[llvm] 222e1c7 - [InstSimplify] don't commute constant expression operand in min/max calls
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 26 13:09:54 PDT 2022
Author: Sanjay Patel
Date: 2022-09-26T16:01:09-04:00
New Revision: 222e1c73f319560765f1e82ece9be4315e6109c0
URL: https://github.com/llvm/llvm-project/commit/222e1c73f319560765f1e82ece9be4315e6109c0
DIFF: https://github.com/llvm/llvm-project/commit/222e1c73f319560765f1e82ece9be4315e6109c0.diff
LOG: [InstSimplify] don't commute constant expression operand in min/max calls
The test shows that we would fail to consistently fold the
instruction based on the max value operand. This is also
the root cause for issue #57986, but I'll add an instcombine
test + assert for that exact problem in another commit.
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 40943d7c4530..e57d9800b04e 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5843,8 +5843,8 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
if (Op0 == Op1)
return Op0;
- // Canonicalize constant operand as Op1.
- if (isa<Constant>(Op0))
+ // Canonicalize immediate constant operand as Op1.
+ if (match(Op0, m_ImmConstant()))
std::swap(Op0, Op1);
// Assume undef is the limit value.
diff --git a/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll b/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
index d6326baf4b11..e7123b208084 100644
--- a/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
+++ b/llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
@@ -27,8 +27,7 @@ define i8 @constexpr_maxvalue() {
define i8 @constexpr_maxvalue_commute() {
; CHECK-LABEL: @constexpr_maxvalue_commute(
-; CHECK-NEXT: [[UMIN:%.*]] = call i8 @llvm.umin.i8(i8 ptrtoint (ptr @g to i8), i8 -1)
-; CHECK-NEXT: ret i8 [[UMIN]]
+; CHECK-NEXT: ret i8 ptrtoint (ptr @g to i8)
;
%umin = call i8 @llvm.umin.i8(i8 ptrtoint (ptr @g to i8), i8 255)
ret i8 %umin
More information about the llvm-commits
mailing list