Fix a miscompilation of crafty by clobbering the "A" variable.
authorChris Lattner <sabre@nondot.org>
Sat, 7 May 2005 23:49:08 +0000 (23:49 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 7 May 2005 23:49:08 +0000 (23:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21770 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp

index 72b45319c0cffdf347f84d0a9a7bbde104061018..6cafc25777137589671ce7d40ebe08deb0bdc917 100644 (file)
@@ -1856,8 +1856,16 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
         return NV;
   }
 
-  // (A & C1)|(A & C2) == A & (C1|C2)
   Value *A, *B; ConstantInt *C1, *C2;
+
+  if (match(Op0, m_And(m_Value(A), m_Value(B))))
+    if (A == Op1 || B == Op1)    // (A & ?) | A  --> A
+      return ReplaceInstUsesWith(I, Op1);
+  if (match(Op1, m_And(m_Value(A), m_Value(B))))
+    if (A == Op0 || B == Op0)    // A | (A & ?)  --> A
+      return ReplaceInstUsesWith(I, Op0);
+
+  // (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)
     return BinaryOperator::createAnd(A, ConstantExpr::getOr(C1, C2));
@@ -1869,14 +1877,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
   } else {
     A = 0;
   }
-
-  if (match(Op0, m_And(m_Value(A), m_Value(B))))
-    if (A == Op1 || B == Op1)    // (A & ?) | A  --> A
-      return ReplaceInstUsesWith(I, Op1);
-  if (match(Op1, m_And(m_Value(A), m_Value(B))))
-    if (A == Op0 || B == Op0)    // A | (A & ?)  --> A
-      return ReplaceInstUsesWith(I, Op0);
-
+  // Note, A is still live here!
   if (match(Op1, m_Not(m_Value(B)))) {   // Op0 | ~B
     if (Op0 == B)
       return ReplaceInstUsesWith(I,