aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2021-08-10 10:57:25 -0400
committerSanjay Patel <spatel@rotateright.com>2021-08-10 10:57:25 -0400
commite260e10c4a21784c146c94a2a14b7e78b09a9cf7 (patch)
treec43e7a9f66c934aa5b5ac52dcec73eee1cf43956 /llvm/lib/Analysis/ValueTracking.cpp
parent188832f4191c5ef165eb213107ebff371cb57ecd (diff)
downloadllvm-e260e10c4a21784c146c94a2a14b7e78b09a9cf7.zip
llvm-e260e10c4a21784c146c94a2a14b7e78b09a9cf7.tar.gz
llvm-e260e10c4a21784c146c94a2a14b7e78b09a9cf7.tar.bz2
[InstSimplify] fold min/max with limit constant
This is already done within InstCombine: https://alive2.llvm.org/ce/z/MiGE22 ...but leaving it out of analysis makes it harder to avoid infinite loops there.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index b146f07..1e63fc0 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -6253,6 +6253,16 @@ CmpInst::Predicate llvm::getInverseMinMaxPred(SelectPatternFlavor SPF) {
return getMinMaxPred(getInverseMinMaxFlavor(SPF));
}
+APInt llvm::getMinMaxLimit(SelectPatternFlavor SPF, unsigned BitWidth) {
+ switch (SPF) {
+ case SPF_SMAX: return APInt::getSignedMaxValue(BitWidth);
+ case SPF_SMIN: return APInt::getSignedMinValue(BitWidth);
+ case SPF_UMAX: return APInt::getMaxValue(BitWidth);
+ case SPF_UMIN: return APInt::getMinValue(BitWidth);
+ default: llvm_unreachable("Unexpected flavor");
+ }
+}
+
std::pair<Intrinsic::ID, bool>
llvm::canConvertToMinOrMaxIntrinsic(ArrayRef<Value *> VL) {
// Check if VL contains select instructions that can be folded into a min/max