[llvm] [ExpandMemCmp] Check misaligned access per overlapping/tail load (PR #210707)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 22 04:42:33 PDT 2026
================
@@ -127,31 +130,50 @@ class MemCmpExpansion {
LoadPair getLoadPair(Type *LoadSizeType, Type *BSwapSizeType,
Type *CmpSizeType, unsigned OffsetBytes);
+ // Return true if a load of `LoadSize` bytes at `Offset` from the base
+ // pointers is accessible on the target: either it is naturally aligned given
+ // the known common base alignment, or the target allows a misaligned access
+ // of that width.
+ bool isAccessAllowed(unsigned LoadSize, uint64_t Offset) const;
+
static LoadEntryVector
computeGreedyLoadSequence(uint64_t Size, llvm::ArrayRef<unsigned> LoadSizes,
unsigned MaxNumLoads, unsigned &NumLoadsNonOneByte);
- static LoadEntryVector
+ LoadEntryVector
computeOverlappingLoadSequence(uint64_t Size, unsigned MaxLoadSize,
unsigned MaxNumLoads,
- unsigned &NumLoadsNonOneByte);
+ unsigned &NumLoadsNonOneByte) const;
- static void optimiseLoadSequence(
+ void optimiseLoadSequence(
LoadEntryVector &LoadSequence,
const TargetTransformInfo::MemCmpExpansionOptions &Options,
- bool IsUsedForZeroCmp);
+ bool IsUsedForZeroCmp) const;
public:
MemCmpExpansion(CallInst *CI, uint64_t Size,
const TargetTransformInfo::MemCmpExpansionOptions &Options,
const bool IsUsedForZeroCmp, const DataLayout &TheDataLayout,
- DomTreeUpdater *DTU);
+ DomTreeUpdater *DTU, const TargetTransformInfo &TTI);
unsigned getNumBlocks();
uint64_t getNumLoads() const { return LoadSequence.size(); }
Value *getMemCmpExpansion();
};
+// We query whether the access is *allowed*, not whether it is *fast*, matching
+// the historical behavior of forming unaligned loads whenever the target
+// permits them.
+bool MemCmpExpansion::isAccessAllowed(unsigned LoadSize,
+ uint64_t Offset) const {
+ Align AccessAlign = commonAlignment(BaseAlign, Offset);
+ if (AccessAlign >= LoadSize)
+ return true;
----------------
lukel97 wrote:
I'm not too strongly opinionated what method we use, just wanted to check my understanding
https://github.com/llvm/llvm-project/pull/210707
More information about the llvm-commits
mailing list