Skip to content

Commit

Permalink
[InstSimplify] don't commute constant expression operand in min/max c…
Browse files Browse the repository at this point in the history
…alls

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.
  • Loading branch information
rotateright committed Sep 26, 2022
1 parent b5bccde commit 222e1c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/Transforms/InstSimplify/maxmin_intrinsics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 222e1c7

Please sign in to comment.