From 03841659a4d3227b2606480c66a0d790e54dbb5d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 25 May 2004 04:29:21 +0000 Subject: Implement instcombine/cast.ll:test16: Canonicalize cast X to bool into a setne instruction llvm-svn: 13736 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp') diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 67b99c56e7e..d31e7e83332 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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! // -- cgit v1.2.3