[llvm] [LoadStoreVectorizer] Propagate alignment through contiguous chain (PR #145733)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 22 09:18:40 PDT 2025
================
@@ -21,6 +21,43 @@
using namespace llvm;
+static bool tryToPropagateAlign(Function &F, const DataLayout &DL) {
+ bool Changed = false;
+
+ for (BasicBlock &BB : F) {
+ // We need to reset the map for each block because alignment information
+ // can't be propagated across blocks. This is because control flow could
+ // be dependent on the address at runtime, making an alignment assumption
+ // within one block not true in another. Some sort of dominator tree
+ // approach could be better, but restricting within a basic block is correct
+ // too.
+ DenseMap<Value *, Align> BestBasePointerAligns;
+ for (Instruction &I : BB) {
+ if (auto *PtrOp = getLoadStorePointerOperand(&I)) {
+ Align LoadStoreAlign = getLoadStoreAlignment(&I);
+ APInt OffsetFromBase = APInt(
+ DL.getIndexSizeInBits(PtrOp->getType()->getPointerAddressSpace()),
+ 0);
+ PtrOp = PtrOp->stripAndAccumulateInBoundsConstantOffsets(
+ DL, OffsetFromBase);
+ Align BasePointerAlign =
+ commonAlignment(LoadStoreAlign, OffsetFromBase.getLimitedValue());
+
+ if (BestBasePointerAligns.count(PtrOp) &&
----------------
nikic wrote:
Avoid duplicate hash lookup (e.g. using try_emplace).
https://github.com/llvm/llvm-project/pull/145733
More information about the llvm-commits
mailing list