[llvm] 97930f8 - [NFC][SCEV] Prepare `createNodeForSelectOrPHI()` for gaining additional strategy
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 10 06:47:04 PST 2022
Author: Roman Lebedev
Date: 2022-02-10T17:42:55+03:00
New Revision: 97930f85afe63191a1edf8a3141aabdafcbc6847
URL: https://github.com/llvm/llvm-project/commit/97930f85afe63191a1edf8a3141aabdafcbc6847
DIFF: https://github.com/llvm/llvm-project/commit/97930f85afe63191a1edf8a3141aabdafcbc6847.diff
LOG: [NFC][SCEV] Prepare `createNodeForSelectOrPHI()` for gaining additional strategy
Currently `createNodeForSelectOrPHI()` takes an Instruction,
and only works on the Cond that is an ICmpInst,
but that can be relaxed somewhat.
For now, simply rename the existing function,
and add a thin wrapper ontop that still does
the same thing as it used to.
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index a81c19f7c7171..6ff1a5081761b 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1622,8 +1622,17 @@ class ScalarEvolution {
/// is either a select instruction or a phi node). \p I is the instruction
/// being processed, and it is assumed equivalent to "Cond ? TrueVal :
/// FalseVal".
- const SCEV *createNodeForSelectOrPHI(Instruction *I, Value *Cond,
- Value *TrueVal, Value *FalseVal);
+ const SCEV *createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
+ ICmpInst *Cond,
+ Value *TrueVal,
+ Value *FalseVal);
+
+ /// Given a value \p V, which is a select-like instruction (currently this is
+ /// either a select instruction or a phi node), which is assumed equivalent to
+ /// Cond ? TrueVal : FalseVal
+ /// see if we can model it as a SCEV expression.
+ const SCEV *createNodeForSelectOrPHI(Value *V, Value *Cond, Value *TrueVal,
+ Value *FalseVal);
/// Provide the special handling we need to analyze GEP SCEVs.
const SCEV *createNodeForGEP(GEPOperator *GEP);
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 220cf3d8da3fa..53c1bc6ebf0f0 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -5887,19 +5887,10 @@ const SCEV *ScalarEvolution::createNodeForPHI(PHINode *PN) {
return getUnknown(PN);
}
-const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Instruction *I,
- Value *Cond,
- Value *TrueVal,
- Value *FalseVal) {
- // Handle "constant" branch or select. This can occur for instance when a
- // loop pass transforms an inner loop and moves on to process the outer loop.
- if (auto *CI = dyn_cast<ConstantInt>(Cond))
- return getSCEV(CI->isOne() ? TrueVal : FalseVal);
-
+const SCEV *ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(
+ Instruction *I, ICmpInst *Cond, Value *TrueVal, Value *FalseVal) {
// Try to match some simple smax or umax patterns.
- auto *ICI = dyn_cast<ICmpInst>(Cond);
- if (!ICI)
- return getUnknown(I);
+ auto *ICI = Cond;
Value *LHS = ICI->getOperand(0);
Value *RHS = ICI->getOperand(1);
@@ -5995,6 +5986,26 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Instruction *I,
return getUnknown(I);
}
+const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Value *V, Value *Cond,
+ Value *TrueVal,
+ Value *FalseVal) {
+ auto *I = dyn_cast<Instruction>(V);
+ if (!I)
+ return getUnknown(V);
+
+ // Handle "constant" branch or select. This can occur for instance when a
+ // loop pass transforms an inner loop and moves on to process the outer loop.
+ if (auto *CI = dyn_cast<ConstantInt>(Cond))
+ return getSCEV(CI->isOne() ? TrueVal : FalseVal);
+
+ // Try to match some simple smax or umax patterns.
+ if (auto *ICI = dyn_cast<ICmpInst>(Cond))
+ return createNodeForSelectOrPHIInstWithICmpInstCond(I, ICI, TrueVal,
+ FalseVal);
+
+ return getUnknown(V);
+}
+
/// Expand GEP instructions into add and multiply operations. This allows them
/// to be analyzed by regular SCEV code.
const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) {
@@ -7403,14 +7414,8 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
return createNodeForPHI(cast<PHINode>(U));
case Instruction::Select:
- // U can also be a select constant expr, which let fall through. Since
- // createNodeForSelect only works for a condition that is an `ICmpInst`, and
- // constant expressions cannot have instructions as operands, we'd have
- // returned getUnknown for a select constant expressions anyway.
- if (isa<Instruction>(U))
- return createNodeForSelectOrPHI(cast<Instruction>(U), U->getOperand(0),
- U->getOperand(1), U->getOperand(2));
- break;
+ return createNodeForSelectOrPHI(U, U->getOperand(0), U->getOperand(1),
+ U->getOperand(2));
case Instruction::Call:
case Instruction::Invoke:
More information about the llvm-commits
mailing list