diff options
author | Pedro Lobo <pedro.lobo@tecnico.ulisboa.pt> | 2025-08-05 17:09:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-05 17:09:06 +0100 |
commit | 2bbc6147138187946616c1b30743e09825fb61b8 (patch) | |
tree | 5309569b54be83e1bc0ee9be105637220fe2afcd /llvm/lib | |
parent | d72e58e422be747dfd1e42f8ad370420634190cb (diff) | |
download | llvm-2bbc6147138187946616c1b30743e09825fb61b8.zip llvm-2bbc6147138187946616c1b30743e09825fb61b8.tar.gz llvm-2bbc6147138187946616c1b30743e09825fb61b8.tar.bz2 |
[InstCombine] Support offsets in `memset` to load forwarding (#151924)
Adds support for load offsets when performing `memset` load forwarding.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/Loads.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp index da76f5b..78d0887 100644 --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -631,9 +631,13 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr, if (!Val || !Len) return nullptr; - // TODO: Handle offsets. - Value *Dst = MSI->getDest(); - if (!AreEquivalentAddressValues(Dst, Ptr)) + // Handle offsets. + int64_t StoreOffset = 0, LoadOffset = 0; + const Value *StoreBase = + GetPointerBaseWithConstantOffset(MSI->getDest(), StoreOffset, DL); + const Value *LoadBase = + GetPointerBaseWithConstantOffset(Ptr, LoadOffset, DL); + if (StoreBase != LoadBase || LoadOffset < StoreOffset) return nullptr; if (IsLoadCSE) @@ -645,7 +649,7 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr, // Make sure the read bytes are contained in the memset. uint64_t LoadSize = LoadTypeSize.getFixedValue(); - if ((Len->getValue() * 8).ult(LoadSize)) + if ((Len->getValue() * 8).ult(LoadSize + (LoadOffset - StoreOffset) * 8)) return nullptr; APInt Splat = LoadSize >= 8 ? APInt::getSplat(LoadSize, Val->getValue()) |