Skip to content

Commit 3716a3c

Browse files
committed
[InstCombine] Folding multiuse (icmp eq/ne (or X, Y), Y) for 2 uses of Y
The fold will replace 2 uses of `Y` we should also do fold if `Y` has 2 uses (not only oneuse). Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D159062
1 parent 7cfad77 commit 3716a3c

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4795,7 +4795,7 @@ static Instruction *foldICmpOrXX(ICmpInst &I, const SimplifyQuery &Q,
47954795
if (ICmpInst::isEquality(Pred) && Op0->hasOneUse()) {
47964796
// icmp (X | Y) eq/ne Y --> (X & ~Y) eq/ne 0 if Y is freely invertible
47974797
if (Value *NotOp1 =
4798-
IC.getFreelyInverted(Op1, Op1->hasOneUse(), &IC.Builder))
4798+
IC.getFreelyInverted(Op1, !Op1->hasNUsesOrMore(3), &IC.Builder))
47994799
return new ICmpInst(Pred, IC.Builder.CreateAnd(A, NotOp1),
48004800
Constant::getNullValue(Op1->getType()));
48014801
// icmp (X | Y) eq/ne Y --> (~X | Y) eq/ne -1 if X is freely invertible.

llvm/test/Transforms/InstCombine/icmp-of-or-x.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,9 @@ define i1 @pr64610(ptr %b) {
376376

377377
define i1 @icmp_eq_x_invertable_y2_todo(i8 %x, i1 %y, i8 %z) {
378378
; CHECK-LABEL: @icmp_eq_x_invertable_y2_todo(
379-
; CHECK-NEXT: [[ZZ:%.*]] = xor i8 [[Z:%.*]], -1
380-
; CHECK-NEXT: [[YY:%.*]] = select i1 [[Y:%.*]], i8 7, i8 [[ZZ]]
381-
; CHECK-NEXT: [[OR:%.*]] = or i8 [[YY]], [[X:%.*]]
382-
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[YY]], [[OR]]
379+
; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[Y:%.*]], i8 -8, i8 [[Z:%.*]]
380+
; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], [[X:%.*]]
381+
; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP2]], 0
383382
; CHECK-NEXT: ret i1 [[R]]
384383
;
385384
%zz = xor i8 %z, -1

0 commit comments

Comments
 (0)