[PATCH] D159062: [InstCombine] Folding multiuse `(icmp eq/ne (or X, Y), Y)` for 2 uses of `Y`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 12:56:28 PDT 2023
goldstein.w.n updated this revision to Diff 556708.
goldstein.w.n added a comment.
Update with nikic's suggestion
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D159062/new/
https://reviews.llvm.org/D159062
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-of-or-x.ll
Index: llvm/test/Transforms/InstCombine/icmp-of-or-x.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp-of-or-x.ll
+++ llvm/test/Transforms/InstCombine/icmp-of-or-x.ll
@@ -380,10 +380,9 @@
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
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4663,7 +4663,7 @@
if (ICmpInst::isEquality(Pred) && Op0->hasOneUse()) {
// icmp (X | Y) eq/ne Y --> (X & ~Y) eq/ne 0 if Y is freely invertible
- if (IC.isFreeToInvert(Op1, Op1->hasOneUse()))
+ if (IC.isFreeToInvert(Op1, !Op1->hasNUsesOrMore(3)))
return new ICmpInst(Pred,
IC.Builder.CreateAnd(A, IC.Builder.CreateNot(Op1)),
Constant::getNullValue(Op1->getType()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159062.556708.patch
Type: text/x-patch
Size: 1536 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230913/d0e6f444/attachment.bin>
More information about the llvm-commits
mailing list