- Notifications
You must be signed in to change notification settings - Fork 15k
[SCEV] Expose getGEPExpr without needing to pass GEPOperator* (NFC) #164487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @llvm/pr-subscribers-llvm-analysis Author: Florian Hahn (fhahn) ChangesAdd a new getGEPExpr variant which is independent of GEPOperator*. To be used to construct SCEVs for VPlan recipes in #161276. Full diff: https://github.com/llvm/llvm-project/pull/164487.diff 2 Files Affected:
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index 3d3ec14796bc1..c419aed107464 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -640,6 +640,9 @@ class ScalarEvolution { /// \p IndexExprs The expressions for the indices. LLVM_ABI const SCEV * getGEPExpr(GEPOperator *GEP, const SmallVectorImpl<const SCEV *> &IndexExprs); + LLVM_ABI const SCEV *getGEPExpr( + const SCEV *BaseExpr, const SmallVectorImpl<const SCEV *> &IndexExprs, + Type *SrcElementTy, SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap); LLVM_ABI const SCEV *getAbsExpr(const SCEV *Op, bool IsNSW); LLVM_ABI const SCEV *getMinMaxExpr(SCEVTypes Kind, SmallVectorImpl<const SCEV *> &Operands); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 6f7dd79032cfe..4856c51ee2a4a 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -3774,7 +3774,6 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP, const SCEV *BaseExpr = getSCEV(GEP->getPointerOperand()); // getSCEV(Base)->getType() has the same address space as Base->getType() // because SCEV::getType() preserves the address space. - Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType()); GEPNoWrapFlags NW = GEP->getNoWrapFlags(); if (NW != GEPNoWrapFlags::none()) { // We'd like to propagate flags from the IR to the corresponding SCEV nodes, @@ -3793,7 +3792,16 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP, if (NW.hasNoUnsignedWrap()) OffsetWrap = setFlags(OffsetWrap, SCEV::FlagNUW); - Type *CurTy = GEP->getType(); + return getGEPExpr(BaseExpr, IndexExprs, GEP->getSourceElementType(), + OffsetWrap); +} + +const SCEV * +ScalarEvolution::getGEPExpr(const SCEV *BaseExpr, + const SmallVectorImpl<const SCEV *> &IndexExprs, + Type *SrcElementTy, SCEV::NoWrapFlags OffsetWrap) { + Type *CurTy = BaseExpr->getType(); + Type *IntIdxTy = getEffectiveSCEVType(BaseExpr->getType()); bool FirstIter = true; SmallVector<const SCEV *, 4> Offsets; for (const SCEV *IndexExpr : IndexExprs) { @@ -3812,7 +3820,7 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP, if (FirstIter) { assert(isa<PointerType>(CurTy) && "The first index of a GEP indexes a pointer"); - CurTy = GEP->getSourceElementType(); + CurTy = SrcElementTy; FirstIter = false; } else { CurTy = GetElementPtrInst::getTypeAtIndex(CurTy, (uint64_t)0); @@ -3837,8 +3845,9 @@ ScalarEvolution::getGEPExpr(GEPOperator *GEP, // Add the base address and the offset. We cannot use the nsw flag, as the // base address is unsigned. However, if we know that the offset is // non-negative, we can use nuw. - bool NUW = NW.hasNoUnsignedWrap() || - (NW.hasNoUnsignedSignedWrap() && isKnownNonNegative(Offset)); + bool NUW = + hasFlags(OffsetWrap, SCEV::FlagNUW) || + (hasFlags(OffsetWrap, SCEV::FlagNSW) && isKnownNonNegative(Offset)); SCEV::NoWrapFlags BaseWrap = NUW ? SCEV::FlagNUW : SCEV::FlagAnyWrap; auto *GEPExpr = getAddExpr(BaseExpr, Offset, BaseWrap); assert(BaseExpr->getType() == GEPExpr->getType() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! ArrayRef improvement is optional.
| getGEPExpr(GEPOperator *GEP, const SmallVectorImpl<const SCEV *> &IndexExprs); | ||
| LLVM_ABI const SCEV *getGEPExpr( | ||
| const SCEV *BaseExpr, const SmallVectorImpl<const SCEV *> &IndexExprs, | ||
| Type *SrcElementTy, SCEV::NoWrapFlags OffsetWrap = SCEV::FlagAnyWrap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should accept GEPNoWrapFlags instead of OffsetWrap. We should not infer the base wrapping behavior from the offset wrapping behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, although currently I think the behavior currently stays the same, as OffsetWrap would be set to match the GEPNoWrapFlags (although with NSW instead of hasNoUnsignedSignedWrap)?
Add a new getGEPExpr variant which is independent of GEPOperator*. To be used to construct SCEVs for VPlan recipes in llvm#161276.
333e5a1 to fcc832e Compare fcc832e to 790ea77 Compare There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…or* (NFC) (#164487) Add a new getGEPExpr variant which is independent of GEPOperator*. To be used to construct SCEVs for VPlan recipes in llvm/llvm-project#161276. PR: llvm/llvm-project#164487
Add a new getGEPExpr variant which is independent of GEPOperator*.
To be used to construct SCEVs for VPlan recipes in #161276.