Implement select.ll:test11
authorChris Lattner <sabre@nondot.org>
Fri, 9 Apr 2004 18:19:44 +0000 (18:19 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 9 Apr 2004 18:19:44 +0000 (18:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12793 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 6774419e79753593cc2906bcd83466dc95d72b3d..2f2d32ceab630d8d18b35f3962c1cbd8357a9162 100644 (file)
@@ -2055,11 +2055,20 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
   // Selecting between two constants?
   if (Constant *TrueValC = dyn_cast<Constant>(TrueVal))
     if (Constant *FalseValC = dyn_cast<Constant>(FalseVal)) {
-      // If the true constant is a 1 and the false is a zero, turn this into a
-      // cast from bool.
-      if (FalseValC->isNullValue() && isa<ConstantInt>(TrueValC) &&
-          cast<ConstantInt>(TrueValC)->getRawValue() == 1)
-        return new CastInst(CondVal, SI.getType());
+      if (SI.getType()->isInteger()) {
+        // select C, 1, 0 -> cast C to int
+        if (FalseValC->isNullValue() && isa<ConstantInt>(TrueValC) &&
+            cast<ConstantInt>(TrueValC)->getRawValue() == 1) {
+          return new CastInst(CondVal, SI.getType());
+        } else if (TrueValC->isNullValue() && isa<ConstantInt>(FalseValC) &&
+                   cast<ConstantInt>(FalseValC)->getRawValue() == 1) {
+          // select C, 0, 1 -> cast !C to int
+          Value *NotCond =
+            InsertNewInstBefore(BinaryOperator::createNot(CondVal,
+                                               "not."+CondVal->getName()), SI);
+          return new CastInst(NotCond, SI.getType());
+        }
+      }
     }
   
   return 0;