diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2023-09-13 13:46:08 -0500 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2024-06-06 12:42:07 -0500 |
commit | 3716a3c1bce4af81db6a95eee30e35b5b923e319 (patch) | |
tree | 96123f12ce7f18839a60fcc1411b3411bf4967c2 | |
parent | 7cfad77a5e3e9145213b024b9151ff812b54de51 (diff) | |
download | llvm-3716a3c1bce4af81db6a95eee30e35b5b923e319.zip llvm-3716a3c1bce4af81db6a95eee30e35b5b923e319.tar.gz llvm-3716a3c1bce4af81db6a95eee30e35b5b923e319.tar.bz2 |
[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
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp-of-or-x.ll | 7 |
2 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 803475b..38c1c26 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -4795,7 +4795,7 @@ static Instruction *foldICmpOrXX(ICmpInst &I, const SimplifyQuery &Q, if (ICmpInst::isEquality(Pred) && Op0->hasOneUse()) { // icmp (X | Y) eq/ne Y --> (X & ~Y) eq/ne 0 if Y is freely invertible if (Value *NotOp1 = - IC.getFreelyInverted(Op1, Op1->hasOneUse(), &IC.Builder)) + IC.getFreelyInverted(Op1, !Op1->hasNUsesOrMore(3), &IC.Builder)) return new ICmpInst(Pred, IC.Builder.CreateAnd(A, NotOp1), Constant::getNullValue(Op1->getType())); // icmp (X | Y) eq/ne Y --> (~X | Y) eq/ne -1 if X is freely invertible. diff --git a/llvm/test/Transforms/InstCombine/icmp-of-or-x.ll b/llvm/test/Transforms/InstCombine/icmp-of-or-x.ll index 9abcc1a..3048746 100644 --- a/llvm/test/Transforms/InstCombine/icmp-of-or-x.ll +++ b/llvm/test/Transforms/InstCombine/icmp-of-or-x.ll @@ -376,10 +376,9 @@ define i1 @pr64610(ptr %b) { define i1 @icmp_eq_x_invertable_y2_todo(i8 %x, i1 %y, i8 %z) { ; CHECK-LABEL: @icmp_eq_x_invertable_y2_todo( -; CHECK-NEXT: [[ZZ:%.*]] = xor i8 [[Z:%.*]], -1 -; CHECK-NEXT: [[YY:%.*]] = select i1 [[Y:%.*]], i8 7, i8 [[ZZ]] -; CHECK-NEXT: [[OR:%.*]] = or i8 [[YY]], [[X:%.*]] -; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[YY]], [[OR]] +; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[Y:%.*]], i8 -8, i8 [[Z:%.*]] +; CHECK-NEXT: [[TMP2:%.*]] = and i8 [[TMP1]], [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP2]], 0 ; CHECK-NEXT: ret i1 [[R]] ; %zz = xor i8 %z, -1 |