Skip to content

Commit 9cde0b2

Browse files
committed
[InstCombine] Check if Min is actually a Min.
1 parent 4eefa5e commit 9cde0b2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

llvm/include/llvm/IR/IntrinsicInst.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,26 @@ class MinMaxIntrinsic : public IntrinsicInst {
810810
/// Whether the intrinsic is signed or unsigned.
811811
bool isSigned() const { return isSigned(getIntrinsicID()); };
812812

813+
/// Whether the intrinsic is a smin or umin.
814+
static bool isMin(Intrinsic::ID ID) {
815+
switch (ID) {
816+
case Intrinsic::umin:
817+
case Intrinsic::smin:
818+
return true;
819+
case Intrinsic::umax:
820+
case Intrinsic::smax:
821+
return false;
822+
default:
823+
llvm_unreachable("Invalid intrinsic");
824+
}
825+
}
826+
827+
/// Whether the intrinsic is a smin or a umin.
828+
bool isMin() const { return isMin(getIntrinsicID()); }
829+
830+
/// Whether the intrinsic is a smax or a umax.
831+
bool isMax() const { return !isMin(getIntrinsicID()); }
832+
813833
/// Min/max intrinsics are monotonic, they operate on a fixed-bitwidth values,
814834
/// so there is a certain threshold value, upon reaching which,
815835
/// their value can no longer change. Return said threshold.

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5790,7 +5790,7 @@ Instruction *InstCombinerImpl::foldICmpWithMinMax(Instruction &I,
57905790
/// (X - (Hi + 1)) u< (Lo - (Hi + 1))
57915791
Instruction *InstCombinerImpl::foldICmpWithClamp(ICmpInst &I, Value *X,
57925792
MinMaxIntrinsic *Min) {
5793-
if (!I.isEquality() || !Min->hasOneUse())
5793+
if (!I.isEquality() || !Min->hasOneUse() || !Min->isMin())
57945794
return nullptr;
57955795

57965796
const APInt *Lo = nullptr, *Hi = nullptr;

0 commit comments

Comments
 (0)