InstCombine: (X ^ 4) == 8 --> X == 12
authorChris Lattner <sabre@nondot.org>
Wed, 23 Jul 2003 17:26:36 +0000 (17:26 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 23 Jul 2003 17:26:36 +0000 (17:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7260 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index d9c6ccee8d48fa0d31b7eaa58c48ebb659cd9c18..4e36927200339f25e8fbd38e22ceab418bacb43a 100644 (file)
@@ -711,7 +711,7 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
         return BinaryOperator::createNot(Val, I.getName());
       }
 
-      // If the first operand is (and|or) with a constant, and the second
+      // If the first operand is (and|or|xor) with a constant, and the second
       // operand is a constant, simplify a bit.
       if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0))
         if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1)))
@@ -725,6 +725,11 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) {
             // comparison can never succeed!
             if (!(*CI & *~*BOC)->isNullValue())
               return ReplaceInstUsesWith(I, ConstantBool::get(isSetNE));
+          } else if (BO->getOpcode() == Instruction::Xor) {
+            // For the xor case, we can always just xor the two constants
+            // together, potentially eliminating the explicit xor.
+            return BinaryOperator::create(I.getOpcode(), BO->getOperand(0),
+                                          *CI ^ *BOC);
           }
     }