Skip to content

Commit

Permalink
[SCEVExpander] Drop Ty argument from expandAddToGEP() (NFC)
Browse files Browse the repository at this point in the history
We can directly use the type of Offset here.
  • Loading branch information
nikic committed Sep 21, 2023
1 parent b5ff576 commit eb31208
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Transforms/Utils/ScalarEvolutionExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {

/// Expand a SCEVAddExpr with a pointer type into a GEP instead of using
/// ptrtoint+arithmetic+inttoptr.
Value *expandAddToGEP(const SCEV *Op, Type *Ty, Value *V);
Value *expandAddToGEP(const SCEV *Op, Value *V);

/// Find a previous Value in ExprValueMap for expand.
/// DropPoisonGeneratingInsts is populated with instructions for which
Expand Down Expand Up @@ -484,7 +484,7 @@ class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
const Loop *L, Type *ExpandTy, Type *IntTy,
Type *&TruncTy, bool &InvertStep);
Value *expandIVInc(PHINode *PN, Value *StepV, const Loop *L, Type *ExpandTy,
Type *IntTy, bool useSubtract);
bool useSubtract);

void fixupInsertPoints(Instruction *I);

Expand Down
24 changes: 11 additions & 13 deletions llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,11 @@ Value *SCEVExpander::InsertBinop(Instruction::BinaryOps Opcode,
/// loop-invariant portions of expressions, after considering what
/// can be folded using target addressing modes.
///
Value *SCEVExpander::expandAddToGEP(const SCEV *Offset, Type *Ty, Value *V) {
Value *SCEVExpander::expandAddToGEP(const SCEV *Offset, Value *V) {
assert(!isa<Instruction>(V) ||
SE.DT.dominates(cast<Instruction>(V), &*Builder.GetInsertPoint()));

Value *Idx = expandCodeFor(Offset, Ty);
Value *Idx = expand(Offset);

// Fold a GEP with constant operands.
if (Constant *CLHS = dyn_cast<Constant>(V))
Expand All @@ -338,7 +338,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *Offset, Type *Ty, Value *V) {
if (IP->getOpcode() == Instruction::GetElementPtr &&
IP->getOperand(0) == V && IP->getOperand(1) == Idx &&
cast<GEPOperator>(&*IP)->getSourceElementType() ==
Type::getInt8Ty(Ty->getContext()))
Builder.getInt8Ty())
return &*IP;
if (IP == BlockBegin) break;
}
Expand Down Expand Up @@ -495,8 +495,7 @@ Value *SCEVExpander::visitAddExpr(const SCEVAddExpr *S) {
X = SE.getSCEV(U->getValue());
NewOps.push_back(X);
}
Type *Ty = SE.getEffectiveSCEVType(S->getType());
Sum = expandAddToGEP(SE.getAddExpr(NewOps), Ty, Sum);
Sum = expandAddToGEP(SE.getAddExpr(NewOps), Sum);
} else if (Op->isNonConstantNegative()) {
// Instead of doing a negate and add, just do a subtract.
Value *W = expand(SE.getNegativeSCEV(Op));
Expand Down Expand Up @@ -796,12 +795,11 @@ bool SCEVExpander::isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV,
/// Typically this is the LatchBlock terminator or IVIncInsertPos, but we may
/// need to materialize IV increments elsewhere to handle difficult situations.
Value *SCEVExpander::expandIVInc(PHINode *PN, Value *StepV, const Loop *L,
Type *ExpandTy, Type *IntTy,
bool useSubtract) {
Type *ExpandTy, bool useSubtract) {
Value *IncV;
// If the PHI is a pointer, use a GEP, otherwise use an add or sub.
if (ExpandTy->isPointerTy()) {
IncV = expandAddToGEP(SE.getSCEV(StepV), IntTy, PN);
IncV = expandAddToGEP(SE.getSCEV(StepV), PN);
} else {
IncV = useSubtract ?
Builder.CreateSub(PN, StepV, Twine(IVName) + ".iv.next") :
Expand Down Expand Up @@ -1039,7 +1037,7 @@ SCEVExpander::getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
Instruction *InsertPos = L == IVIncInsertLoop ?
IVIncInsertPos : Pred->getTerminator();
Builder.SetInsertPoint(InsertPos);
Value *IncV = expandIVInc(PN, StepV, L, ExpandTy, IntTy, useSubtract);
Value *IncV = expandIVInc(PN, StepV, L, ExpandTy, useSubtract);

if (isa<OverflowingBinaryOperator>(IncV)) {
if (IncrementIsNUW)
Expand Down Expand Up @@ -1169,7 +1167,7 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
StepV =
expandCodeFor(Step, IntTy, L->getHeader()->getFirstInsertionPt());
}
Result = expandIVInc(PN, StepV, L, ExpandTy, IntTy, useSubtract);
Result = expandIVInc(PN, StepV, L, ExpandTy, useSubtract);
}
}

Expand Down Expand Up @@ -1202,9 +1200,9 @@ Value *SCEVExpander::expandAddRecExprLiterally(const SCEVAddRecExpr *S) {
if (isa<PointerType>(ExpandTy)) {
if (Result->getType()->isIntegerTy()) {
Value *Base = expandCodeFor(PostLoopOffset, ExpandTy);
Result = expandAddToGEP(SE.getUnknown(Result), IntTy, Base);
Result = expandAddToGEP(SE.getUnknown(Result), Base);
} else {
Result = expandAddToGEP(PostLoopOffset, IntTy, Result);
Result = expandAddToGEP(PostLoopOffset, Result);
}
} else {
Result = InsertNoopCastOfTo(Result, IntTy);
Expand Down Expand Up @@ -1259,7 +1257,7 @@ Value *SCEVExpander::visitAddRecExpr(const SCEVAddRecExpr *S) {
if (!S->getStart()->isZero()) {
if (isa<PointerType>(S->getType())) {
Value *StartV = expand(SE.getPointerBase(S));
return expandAddToGEP(SE.removePointerBase(S), Ty, StartV);
return expandAddToGEP(SE.removePointerBase(S), StartV);
}

SmallVector<const SCEV *, 4> NewOps(S->operands());
Expand Down

0 comments on commit eb31208

Please sign in to comment.