[llvm] [LAA] Improve code in findForkedSCEVs (NFC) (PR #140384)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 07:04:26 PDT 2025
================
@@ -999,24 +999,17 @@ static void findForkedSCEVs(
break;
}
- // Find the pointer type we need to extend to.
- Type *IntPtrTy = SE->getEffectiveSCEVType(
- SE->getSCEV(GEP->getPointerOperand())->getType());
-
- // Find the size of the type being pointed to. We only have a single
- // index term (guarded above) so we don't need to index into arrays or
- // structures, just get the size of the scalar value.
- const SCEV *Size = SE->getSizeOfExpr(IntPtrTy, SourceTy);
-
- // Scale up the offsets by the size of the type, then add to the bases.
- const SCEV *Scaled1 = SE->getMulExpr(
- Size, SE->getTruncateOrSignExtend(get<0>(OffsetScevs[0]), IntPtrTy));
- const SCEV *Scaled2 = SE->getMulExpr(
- Size, SE->getTruncateOrSignExtend(get<0>(OffsetScevs[1]), IntPtrTy));
- ScevList.emplace_back(SE->getAddExpr(get<0>(BaseScevs[0]), Scaled1),
- NeedsFreeze);
- ScevList.emplace_back(SE->getAddExpr(get<0>(BaseScevs[1]), Scaled2),
- NeedsFreeze);
+ Type *PtrTy = GEP->getPointerOperandType();
----------------
david-arm wrote:
Hmm, it does look odd though, and you're also relying upon the internal behaviour of SCEV to do the right thing, which may be fine I guess. It doesn't seem to be documented in ScalarEvolution.h, although I can believe the author(s) wanted to make life simpler internally by doing the conversion. However, if you try to do the equivalent of `getTruncateOrSignExtend` at the IR level (see CastInst::Create), then it looks like it will assert when trying to truncate to something that isn't an integer type.
What is your objection to using integer types here?
https://github.com/llvm/llvm-project/pull/140384
More information about the llvm-commits
mailing list