[llvm] 34d0d64 - [ValueTracking] move/add helper to get inverse min/max; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 14:38:34 PST 2021
Author: Sanjay Patel
Date: 2021-03-08T17:38:22-05:00
New Revision: 34d0d644ffa4a3282a03f6e47b5f420a09ff9848
URL: https://github.com/llvm/llvm-project/commit/34d0d644ffa4a3282a03f6e47b5f420a09ff9848
DIFF: https://github.com/llvm/llvm-project/commit/34d0d644ffa4a3282a03f6e47b5f420a09ff9848.diff
LOG: [ValueTracking] move/add helper to get inverse min/max; NFC
We will need to this functionality to improve min/max folds
in instcombine when we canonicalize to intrinsics.
Added:
Modified:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index 6020bbd97bae..64e953282f2c 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -737,6 +737,8 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
/// For example, signed minimum is the inverse of signed maximum.
SelectPatternFlavor getInverseMinMaxFlavor(SelectPatternFlavor SPF);
+ Intrinsic::ID getInverseMinMaxIntrinsic(Intrinsic::ID MinMaxID);
+
/// Return the canonical inverse comparison predicate for the specified
/// minimum/maximum flavor.
CmpInst::Predicate getInverseMinMaxPred(SelectPatternFlavor SPF);
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 632741e2c737..0f7575fc104e 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5416,16 +5416,6 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
return nullptr;
}
-static Intrinsic::ID getMaxMinOpposite(Intrinsic::ID IID) {
- switch (IID) {
- case Intrinsic::smax: return Intrinsic::smin;
- case Intrinsic::smin: return Intrinsic::smax;
- case Intrinsic::umax: return Intrinsic::umin;
- case Intrinsic::umin: return Intrinsic::umax;
- default: llvm_unreachable("Unexpected intrinsic");
- }
-}
-
static APInt getMaxMinLimit(Intrinsic::ID IID, unsigned BitWidth) {
switch (IID) {
case Intrinsic::smax: return APInt::getSignedMaxValue(BitWidth);
@@ -5465,7 +5455,7 @@ static Value *foldMinMaxSharedOp(Intrinsic::ID IID, Value *Op0, Value *Op1) {
if (IID0 == IID)
return MM0;
// max (min X, Y), X --> X
- if (IID0 == getMaxMinOpposite(IID))
+ if (IID0 == getInverseMinMaxIntrinsic(IID))
return Op1;
}
return nullptr;
@@ -5517,7 +5507,7 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
// If the constant op is the opposite of the limit value, the other must
// be larger/smaller or equal. For example:
// umin(i8 %x, i8 255) --> %x
- if (*C == getMaxMinLimit(getMaxMinOpposite(IID), BitWidth))
+ if (*C == getMaxMinLimit(getInverseMinMaxIntrinsic(IID), BitWidth))
return Op0;
// Remove nested call if constant operands allow it. Example:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 80f03d3379de..0a5071881414 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5992,6 +5992,16 @@ SelectPatternFlavor llvm::getInverseMinMaxFlavor(SelectPatternFlavor SPF) {
llvm_unreachable("unhandled!");
}
+Intrinsic::ID llvm::getInverseMinMaxIntrinsic(Intrinsic::ID MinMaxID) {
+ switch (MinMaxID) {
+ case Intrinsic::smax: return Intrinsic::smin;
+ case Intrinsic::smin: return Intrinsic::smax;
+ case Intrinsic::umax: return Intrinsic::umin;
+ case Intrinsic::umin: return Intrinsic::umax;
+ default: llvm_unreachable("Unexpected intrinsic");
+ }
+}
+
CmpInst::Predicate llvm::getInverseMinMaxPred(SelectPatternFlavor SPF) {
return getMinMaxPred(getInverseMinMaxFlavor(SPF));
}
More information about the llvm-commits
mailing list