Skip to content

Commit 3a704b6

Browse files
committed
[InstCombine] Bail out on inner disjoint or in foldSelectICmpEq
1 parent ee736a8 commit 3a704b6

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,12 +1853,13 @@ static Instruction *foldSelectICmpEq(SelectInst &SI, ICmpInst *ICI,
18531853
XorOps = Instruction::Xor, NoOps = 0;
18541854
enum NotMask { None = 0, NotInner, NotRHS };
18551855

1856+
// We cannot refine TrueVal to FalseVal when the inner instruction contains
1857+
// disjoint or.
18561858
auto matchFalseVal = [&](unsigned OuterOpc, unsigned InnerOpc,
18571859
unsigned NotMask) {
1858-
auto matchInner = m_c_BinOp(InnerOpc, m_Specific(X), m_Specific(Y));
1859-
if (OuterOpc == NoOps)
1860-
return match(CmpRHS, m_Zero()) && match(FalseVal, matchInner);
1861-
1860+
auto matchInner =
1861+
m_CombineAnd(m_c_BinOp(InnerOpc, m_Specific(X), m_Specific(Y)),
1862+
m_Unless(m_DisjointOr(m_Value(), m_Value())));
18621863
if (NotMask == NotInner) {
18631864
return match(FalseVal, m_c_BinOp(OuterOpc, m_NotForbidPoison(matchInner),
18641865
m_Specific(CmpRHS)));

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,10 +4567,14 @@ define i32 @src_no_trans_select_xor_eq0_or_xor(i32 %x, i32 %y) {
45674567
define i32 @src_no_trans_select_xor_eqc_and_disjoint_or_and_notc(i32 noundef %x, i32 noundef %y, i32 %c) {
45684568
; CHECK-LABEL: @src_no_trans_select_xor_eqc_and_disjoint_or_and_notc(
45694569
; CHECK-NEXT: entry:
4570-
; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[Y:%.*]], [[X:%.*]]
4571-
; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[C:%.*]], -1
4570+
; CHECK-NEXT: [[XOR:%.*]] = xor i32 [[Y:%.*]], [[X:%.*]]
4571+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[XOR]], [[C:%.*]]
4572+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], [[Y]]
4573+
; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[Y]], [[X]]
4574+
; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[C]], -1
45724575
; CHECK-NEXT: [[AND1:%.*]] = and i32 [[OR]], [[NOT]]
4573-
; CHECK-NEXT: ret i32 [[AND1]]
4576+
; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[AND]], i32 [[AND1]]
4577+
; CHECK-NEXT: ret i32 [[COND]]
45744578
;
45754579
entry:
45764580
%xor = xor i32 %y, %x

0 commit comments

Comments
 (0)