[llvm] [LoadStoreVectorizer] Propagate alignment through contiguous chain (PR #145733)
Drew Kersnar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 30 10:13:27 PDT 2025
================
@@ -57,16 +57,54 @@ bool inferAlignment(Function &F, AssumptionCache &AC, DominatorTree &DT) {
}
}
- // Compute alignment from known bits.
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) {
+ // Compute alignment from known bits.
Changed |= tryToImproveAlign(
DL, &I, [&](Value *PtrOp, Align OldAlign, Align PrefAlign) {
KnownBits Known = computeKnownBits(PtrOp, DL, &AC, &I, &DT);
unsigned TrailZ = std::min(Known.countMinTrailingZeros(),
+Value::MaxAlignmentExponent);
return Align(1ull << std::min(Known.getBitWidth() - 1, TrailZ));
});
+
+ // Propagate alignment between loads and stores that originate from the
+ // same base pointer.
+ Changed |= tryToImproveAlign(
+ DL, &I, [&](Value *PtrOp, Align LoadStoreAlign, Align PrefAlign) {
----------------
dakersnar wrote:
I agree with nikic. The most common use cases of this optimization will have the best alignment earlier in a basic block because split up aggregates will be best aligned at the first element.
https://github.com/llvm/llvm-project/pull/145733
More information about the llvm-commits
mailing list