Implement PR1822
authorChris Lattner <sabre@nondot.org>
Sun, 25 Nov 2007 21:27:53 +0000 (21:27 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 25 Nov 2007 21:27:53 +0000 (21:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44318 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/select.ll

index 85fd2c3bdb745b9fd848677639d4f9943c43ea1a..e90d1909ae40b38c1afaf2a1a0b7b36628229391 100644 (file)
@@ -7326,6 +7326,13 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
         return BinaryOperator::createOr(NotCond, TrueVal);
       }
     }
+    
+    // select a, b, a  -> a&b
+    // select a, a, b  -> a|b
+    if (CondVal == TrueVal)
+      return BinaryOperator::createOr(CondVal, FalseVal);
+    else if (CondVal == FalseVal)
+      return BinaryOperator::createAnd(CondVal, TrueVal);
   }
 
   // Selecting between two integer constants?
index ccc63c2553d2b9f222fb7080622b2be58bb120e3..aac7603e082b44ce3767a4409735e02587649c67 100644 (file)
@@ -1,8 +1,7 @@
 ; This test makes sure that these instructions are properly eliminated.
+; PR1822
 
-; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
-; RUN:    not grep select
-; END.
+; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep select
 
 implementation
 
@@ -180,3 +179,12 @@ short %test22(int %x) {
         ret short %retval
 }
 
+bool %test23(bool %a, bool %b) {
+       %c = select bool %a, bool %b, bool %a
+       ret bool %c
+}
+
+bool %test24(bool %a, bool %b) {
+       %c = select bool %a, bool %a, bool %b
+       ret bool %c
+}