Implement instcombine/cast.ll:test16:
authorChris Lattner <sabre@nondot.org>
Tue, 25 May 2004 04:29:21 +0000 (04:29 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 25 May 2004 04:29:21 +0000 (04:29 +0000)
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

index 67b99c56e7e54d6aaf32b4488dd1e65771917ff0..d31e7e83332966f8e34d529177ae913d7c015df9 100644 (file)
@@ -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!
   //