[llvm] dc13624 - [InstCombine] Fold `(cmp eq/ne (umax X, Y),0)` -> `(cmp eq/ne (or X, Y),0)`
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 29 10:39:01 PDT 2023
Author: Noah Goldstein
Date: 2023-04-29T12:38:43-05:00
New Revision: dc13624e88d872b604fe35c05f290acc37f226ec
URL: https://github.com/llvm/llvm-project/commit/dc13624e88d872b604fe35c05f290acc37f226ec
DIFF: https://github.com/llvm/llvm-project/commit/dc13624e88d872b604fe35c05f290acc37f226ec.diff
LOG: [InstCombine] Fold `(cmp eq/ne (umax X, Y),0)` -> `(cmp eq/ne (or X, Y),0)`
`or` is almost always preferable.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149426
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index aeb1c53c555f..d7c4927e4546 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3384,8 +3384,10 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
}
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));
diff --git a/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll b/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
index 078158729ef1..931031d38a74 100644
--- a/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
+++ b/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
@@ -812,8 +812,8 @@ define <2 x i1> @bitreverse_vec_eq_1_2_todo_no_splat(<2 x i8> %x) {
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_sle_zero_fail(i8 %x, i8 %y) {
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)
More information about the llvm-commits
mailing list