[llvm] [LoopIdiom] Use SCEV for deciding memmove validity (PR #211274)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 29 06:28:43 PDT 2026
================
@@ -1290,43 +1290,45 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
namespace {
class MemmoveVerifier {
public:
- explicit MemmoveVerifier(const Value &LoadBasePtr, const Value &StoreBasePtr,
- const DataLayout &DL)
- : DL(DL), BP1(llvm::GetPointerBaseWithConstantOffset(
- LoadBasePtr.stripPointerCasts(), LoadOff, DL)),
- BP2(llvm::GetPointerBaseWithConstantOffset(
- StoreBasePtr.stripPointerCasts(), StoreOff, DL)),
- IsSameObject(BP1 == BP2) {}
+ explicit MemmoveVerifier(const SCEV &LoadStart, const SCEV &StoreStart,
+ ScalarEvolution &SE)
+ : DL(SE.getDataLayout()),
+ Off(dyn_cast<SCEVConstant>(SE.getMinusSCEV(&StoreStart, &LoadStart))),
+ BasePtr(dyn_cast<SCEVUnknown>(SE.getPointerBase(&StoreStart))),
+ IsSameObject(Off != nullptr) {}
bool loadAndStoreMayFormMemmove(unsigned StoreSize, bool IsNegStride,
const Instruction &TheLoad,
bool IsMemCpy) const {
+ // The store must be at a constant offset from the load, and there must be
+ // an underlying pointer.
+ if (!Off || !BasePtr)
+ return false;
+ const APInt &OffVal = Off->getAPInt();
+ // If null is defined then the base pointer can't be null
+ if (TheLoad.getParent()->getParent()->nullPointerIsDefined() &&
----------------
artagnon wrote:
Kindly use llvm::NullPointerIsDefined from Function.h here? I also think the condition is inverted: if null pointer is undefined, and if the BasePtr is null, then return false?
https://github.com/llvm/llvm-project/pull/211274
More information about the llvm-commits
mailing list