From: Sanjay Patel Date: Thu, 27 Apr 2017 21:55:03 +0000 (+0000) Subject: [InstCombine] fix matcher to bind to specific operand (PR32830) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=402d01739e421af68ab1a6da9279a419d49bb1aa;p=llvm [InstCombine] fix matcher to bind to specific operand (PR32830) 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 --- diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index adf36d24a8d..e37ceb58f15 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -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; diff --git a/test/Transforms/InstCombine/and-or-not.ll b/test/Transforms/InstCombine/and-or-not.ll index a2e8a10735f..4015b340cae 100644 --- a/test/Transforms/InstCombine/and-or-not.ll +++ b/test/Transforms/InstCombine/and-or-not.ll @@ -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 +} +