aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2021-03-24 17:51:29 -0400
committerSanjay Patel <spatel@rotateright.com>2021-03-24 17:54:38 -0400
commitadf42dff421c0509cc8d2fe103d6e6fe3a30f855 (patch)
tree47f8d3a8635568e0a397e0a668870f66fddd77e6 /llvm/lib/Analysis/ValueTracking.cpp
parent5d6b4aa80d6df62b924a12af030c5ded868ee4f1 (diff)
downloadllvm-adf42dff421c0509cc8d2fe103d6e6fe3a30f855.zip
llvm-adf42dff421c0509cc8d2fe103d6e6fe3a30f855.tar.gz
llvm-adf42dff421c0509cc8d2fe103d6e6fe3a30f855.tar.bz2
[ValueTracking] peek through min/max to find isKnownToBeAPowerOfTwo
This is similar to the select logic just ahead of the new code. Min/max choose exactly one value from the inputs, so if both of those are a power-of-2, then the result must be a power-of-2. This might help with D98152, but we likely still need other pieces of the puzzle to avoid regressions. The change in PatternMatch.h is needed to build with clang. It's possible there is a better way to deal with the 'const' incompatibities. Differential Revision: https://reviews.llvm.org/D99276
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 7984500..cd08c4e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1977,6 +1977,12 @@ bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero, unsigned Depth,
return isKnownToBeAPowerOfTwo(SI->getTrueValue(), OrZero, Depth, Q) &&
isKnownToBeAPowerOfTwo(SI->getFalseValue(), OrZero, Depth, Q);
+ // Peek through min/max.
+ if (match(V, m_MaxOrMin(m_Value(X), m_Value(Y)))) {
+ return isKnownToBeAPowerOfTwo(X, OrZero, Depth, Q) &&
+ isKnownToBeAPowerOfTwo(Y, OrZero, Depth, Q);
+ }
+
if (OrZero && match(V, m_And(m_Value(X), m_Value(Y)))) {
// A power of two and'd with anything is a power of two or zero.
if (isKnownToBeAPowerOfTwo(X, /*OrZero*/ true, Depth, Q) ||