1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-23 04:52:54 +02:00

[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

llvm-svn: 301594
This commit is contained in:
Sanjay Patel 2017-04-27 21:55:03 +00:00
parent 65e397ded3
commit bc81e1ff42
2 changed files with 21 additions and 1 deletions

View 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;

View 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
}