[PATCH] D149426: [InstCombine] Fold `(cmp eq/ne (umax X, Y),0)` -> `(cmp eq/ne (or X, Y),0)`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 27 23:24:08 PDT 2023
goldstein.w.n created this revision.
goldstein.w.n added reviewers: nikic, spatel.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
goldstein.w.n requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`or` is almost always preferable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149426
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
Index: llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
===================================================================
--- llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
+++ llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
@@ -812,8 +812,8 @@
define i1 @umax_eq_zero(i8 %x, i8 %y) {
; CHECK-LABEL: @umax_eq_zero(
-; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
-; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[M]], 0
+; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[TMP1]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%m = call i8 @llvm.umax.i8(i8 %x, i8 %y)
@@ -845,8 +845,8 @@
define i1 @umax_ne_zero(i8 %x, i8 %y) {
; CHECK-LABEL: @umax_ne_zero(
-; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.umax.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
-; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[M]], 0
+; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[TMP1]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%m = call i8 @llvm.umax.i8(i8 %x, i8 %y)
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3384,8 +3384,10 @@
}
break;
+ case Intrinsic::umax:
case Intrinsic::uadd_sat: {
// uadd.sat(a, b) == 0 -> (a | b) == 0
+ // umax(a, b) == 0 -> (a | b) == 0
if (C.isZero() && II->hasOneUse()) {
Value *Or = Builder.CreateOr(II->getArgOperand(0), II->getArgOperand(1));
return new ICmpInst(Pred, Or, Constant::getNullValue(Ty));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149426.517810.patch
Type: text/x-patch
Size: 1691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230428/b365553c/attachment.bin>
More information about the llvm-commits
mailing list