[llvm] aa12133 - [NFC][SCEV] `createNodeForSelectOrPHIInstWithICmpInstCond()`: directly take `Type`, not `Instruction`
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 21 18:04:00 PST 2023
Author: Roman Lebedev
Date: 2023-01-22T05:03:42+03:00
New Revision: aa121336377fe17b07e8edd1d48a20e655183581
URL: https://github.com/llvm/llvm-project/commit/aa121336377fe17b07e8edd1d48a20e655183581
DIFF: https://github.com/llvm/llvm-project/commit/aa121336377fe17b07e8edd1d48a20e655183581.diff
LOG: [NFC][SCEV] `createNodeForSelectOrPHIInstWithICmpInstCond()`: directly take `Type`, not `Instruction`
We don't use the `Instruction` itself, only it's type anyways.
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 604ad3612a4a..c4bd0fa3e07c 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1702,11 +1702,11 @@ class ScalarEvolution {
const SCEV *createNodeFromSelectLikePHI(PHINode *PN);
/// Provide special handling for a select-like instruction (currently this
- /// 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".
+ /// is either a select instruction or a phi node). \p Ty is the type of the
+ /// instruction being processed, that is assumed equivalent to
+ /// "Cond ? TrueVal : FalseVal".
std::optional<const SCEV *>
- createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I, ICmpInst *Cond,
+ createNodeForSelectOrPHIInstWithICmpInstCond(Type *Ty, ICmpInst *Cond,
Value *TrueVal, Value *FalseVal);
/// See if we can model this select-like instruction via umin_seq expression.
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 58589161b428..e8f071ddb5f1 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6104,7 +6104,7 @@ bool SCEVMinMaxExprContains(const SCEV *Root, const SCEV *OperandToFind,
}
std::optional<const SCEV *>
-ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
+ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Type *Ty,
ICmpInst *Cond,
Value *TrueVal,
Value *FalseVal) {
@@ -6127,7 +6127,7 @@ ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
case ICmpInst::ICMP_UGE:
// a > b ? a+x : b+x -> max(a, b)+x
// a > b ? b+x : a+x -> min(a, b)+x
- if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType())) {
+ if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(Ty)) {
bool Signed = ICI->isSigned();
const SCEV *LA = getSCEV(TrueVal);
const SCEV *RA = getSCEV(FalseVal);
@@ -6149,9 +6149,9 @@ ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
return Op;
}
if (Signed)
- Op = getNoopOrSignExtend(Op, I->getType());
+ Op = getNoopOrSignExtend(Op, Ty);
else
- Op = getNoopOrZeroExtend(Op, I->getType());
+ Op = getNoopOrZeroExtend(Op, Ty);
return Op;
};
LS = CoerceOperand(LS);
@@ -6176,9 +6176,9 @@ ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
[[fallthrough]];
case ICmpInst::ICMP_EQ:
// x == 0 ? C+y : x+y -> umax(x, C)+y iff C u<= 1
- if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(I->getType()) &&
+ if (getTypeSizeInBits(LHS->getType()) <= getTypeSizeInBits(Ty) &&
isa<ConstantInt>(RHS) && cast<ConstantInt>(RHS)->isZero()) {
- const SCEV *X = getNoopOrZeroExtend(getSCEV(LHS), I->getType());
+ const SCEV *X = getNoopOrZeroExtend(getSCEV(LHS), Ty);
const SCEV *TrueValExpr = getSCEV(TrueVal); // C+y
const SCEV *FalseValExpr = getSCEV(FalseVal); // x+y
const SCEV *Y = getMinusSCEV(FalseValExpr, X); // y = (x+y)-x
@@ -6195,10 +6195,10 @@ ScalarEvolution::createNodeForSelectOrPHIInstWithICmpInstCond(Instruction *I,
const SCEV *X = getSCEV(LHS);
while (auto *ZExt = dyn_cast<SCEVZeroExtendExpr>(X))
X = ZExt->getOperand();
- if (getTypeSizeInBits(X->getType()) <= getTypeSizeInBits(I->getType())) {
+ if (getTypeSizeInBits(X->getType()) <= getTypeSizeInBits(Ty)) {
const SCEV *FalseValExpr = getSCEV(FalseVal);
if (SCEVMinMaxExprContains(FalseValExpr, X, scSequentialUMinExpr))
- return getUMinExpr(getNoopOrZeroExtend(X, I->getType()), FalseValExpr,
+ return getUMinExpr(getNoopOrZeroExtend(X, Ty), FalseValExpr,
/*Sequential=*/true);
}
}
@@ -6284,8 +6284,8 @@ const SCEV *ScalarEvolution::createNodeForSelectOrPHI(Value *V, Value *Cond,
if (auto *I = dyn_cast<Instruction>(V)) {
if (auto *ICI = dyn_cast<ICmpInst>(Cond)) {
if (std::optional<const SCEV *> S =
- createNodeForSelectOrPHIInstWithICmpInstCond(I, ICI, TrueVal,
- FalseVal))
+ createNodeForSelectOrPHIInstWithICmpInstCond(I->getType(), ICI,
+ TrueVal, FalseVal))
return *S;
}
}
More information about the llvm-commits
mailing list