From a710ddc9c4146764d7bf802ae784d86def71175d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 25 May 2004 04:29:21 +0000 Subject: [PATCH] Implement instcombine/cast.ll:test16: Canonicalize cast X to bool into a setne instruction git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13736 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 67b99c56e7e..d31e7e83332 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1996,6 +1996,11 @@ Instruction *InstCombiner::visitCastInst(CastInst &CI) { } } + // If this is a cast to bool, turn it into the appropriate setne instruction. + if (CI.getType() == Type::BoolTy) + return BinaryOperator::create(Instruction::SetNE, CI.getOperand(0), + Constant::getNullValue(CI.getOperand(0)->getType())); + // If casting the result of a getelementptr instruction with no offset, turn // this into a cast of the original pointer! //