[llvm] [SCEVExpander] Preserve gep nuw during expansion (PR #102133)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 16 10:03:04 PDT 2024
================
@@ -347,16 +347,19 @@ 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, Value *V) {
+Value *SCEVExpander::expandAddToGEP(const SCEV *Offset, Value *V,
+ SCEV::NoWrapFlags Flags) {
assert(!isa<Instruction>(V) ||
SE.DT.dominates(cast<Instruction>(V), &*Builder.GetInsertPoint()));
Value *Idx = expand(Offset);
+ GEPNoWrapFlags NW = (Flags & SCEV::FlagNUW) ? GEPNoWrapFlags::noUnsignedWrap()
+ : GEPNoWrapFlags::none();
// Fold a GEP with constant operands.
if (Constant *CLHS = dyn_cast<Constant>(V))
if (Constant *CRHS = dyn_cast<Constant>(Idx))
- return Builder.CreatePtrAdd(CLHS, CRHS);
+ return Builder.CreatePtrAdd(CLHS, CRHS, "", NW);
----------------
preames wrote:
Don't we need to merge the flags if we find an existing GEP in the loop below? In particular, is it safe to reuse a GEP with flags when expanding one without?
https://github.com/llvm/llvm-project/pull/102133
More information about the llvm-commits
mailing list