implement and.ll:test33
authorChris Lattner <sabre@nondot.org>
Mon, 9 May 2005 04:58:36 +0000 (04:58 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 9 May 2005 04:58:36 +0000 (04:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21809 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 40d107a810af30054dfebc595e82608ffe90af98..27b87425adc1f313c6e81bcea3b914a50bad62f6 100644 (file)
@@ -1832,8 +1832,8 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
     ConstantInt *C1; Value *X;
     // (X & C1) | C2 --> (X | C2) & (C1|C2)
     if (match(Op0, m_And(m_Value(X), m_ConstantInt(C1))) && isOnlyUse(Op0)) {
-      std::string Op0Name = Op0->getName(); Op0->setName("");
-      Instruction *Or = BinaryOperator::createOr(X, RHS, Op0Name);
+      Instruction *Or = BinaryOperator::createOr(X, RHS, Op0->getName());
+      Op0->setName("");
       InsertNewInstBefore(Or, I);
       return BinaryOperator::createAnd(Or, ConstantExpr::getOr(RHS, C1));
     }
@@ -1865,6 +1865,22 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
     if (A == Op0 || B == Op0)    // A | (A & ?)  --> A
       return ReplaceInstUsesWith(I, Op0);
 
+  // (X^C)|Y -> (X|Y)^C iff Y&C == 0
+  if (Op0->hasOneUse() && match(Op0, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
+      MaskedValueIsZero(Op1, C1)) {
+    Instruction *NOr = BinaryOperator::createOr(A, Op1, Op0->getName());
+    Op0->setName("");
+    return BinaryOperator::createXor(InsertNewInstBefore(NOr, I), C1);
+  }
+
+  // Y|(X^C) -> (X|Y)^C iff Y&C == 0
+  if (Op1->hasOneUse() && match(Op1, m_Xor(m_Value(A), m_ConstantInt(C1))) &&
+      MaskedValueIsZero(Op0, C1)) {
+    Instruction *NOr = BinaryOperator::createOr(A, Op0, Op1->getName());
+    Op0->setName("");
+    return BinaryOperator::createXor(InsertNewInstBefore(NOr, I), C1);
+  }
+
   // (A & C1)|(A & C2) == A & (C1|C2)
   if (match(Op0, m_And(m_Value(A), m_ConstantInt(C1))) &&
       match(Op1, m_And(m_Value(B), m_ConstantInt(C2))) && A == B)