]> granicus.if.org Git - llvm/commitdiff
[InstCombine] fix matcher to bind to specific operand (PR32830)
authorSanjay Patel <spatel@rotateright.com>
Thu, 27 Apr 2017 21:55:03 +0000 (21:55 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 27 Apr 2017 21:55:03 +0000 (21:55 +0000)
Matching any random value would be very wrong:
https://bugs.llvm.org/show_bug.cgi?id=32830

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301594 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
test/Transforms/InstCombine/and-or-not.ll

index adf36d24a8d58a756ede1f0b620aa5e7d6ab9d4f..e37ceb58f15471e284a716d76ef1b6a42a3c98c6 100644 (file)
@@ -1213,7 +1213,7 @@ static Instruction *foldAndToXor(BinaryOperator &I,
   // (~B | A) & (~A | B) --> ~(A ^ B)
   // (~B | A) & (B | ~A) --> ~(A ^ B)
   if (match(Op0, m_c_Or(m_Value(A), m_Not(m_Value(B)))) &&
-      match(Op1, m_c_Or(m_Not(m_Specific(A)), m_Value(B))))
+      match(Op1, m_c_Or(m_Not(m_Specific(A)), m_Specific(B))))
     return BinaryOperator::CreateNot(Builder.CreateXor(A, B));
 
   return nullptr;
index a2e8a10735fd6d60cb15faf593664700da8dc49a..4015b340cae4ae72480940b054ed950fe40e6bc0 100644 (file)
@@ -524,3 +524,23 @@ define <4 x i32> @demorgan_plus_and_to_xor_vec(<4 x i32> %a, <4 x i32> %b) {
   ret <4 x i32> %not
 }
 
+; https://bugs.llvm.org/show_bug.cgi?id=32830
+; Make sure we're matching operands correctly and not folding things wrongly.
+
+define i64 @PR32830(i64 %a, i64 %b, i64 %c) {
+; CHECK-LABEL: @PR32830(
+; CHECK-NEXT:    [[NOTA:%.*]] = xor i64 %a, -1
+; CHECK-NEXT:    [[NOTB:%.*]] = xor i64 %b, -1
+; CHECK-NEXT:    [[OR1:%.*]] = or i64 [[NOTB]], %a
+; CHECK-NEXT:    [[OR2:%.*]] = or i64 [[NOTA]], %c
+; CHECK-NEXT:    [[AND:%.*]] = and i64 [[OR1]], [[OR2]]
+; CHECK-NEXT:    ret i64 [[AND]]
+;
+  %nota = xor i64 %a, -1
+  %notb = xor i64 %b, -1
+  %or1 = or i64 %notb, %a
+  %or2 = or i64 %nota, %c
+  %and = and i64 %or1, %or2
+  ret i64 %and
+}
+