This is an archive of the discontinued LLVM Phabricator instance.

Add expensive/extensive pass to set Load/Store alignment
Needs ReviewPublic

Authored by ThomasRaoux on Jun 23 2022, 5:31 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Currently Load/Store alignment is only set in InstComnine pass based on computeKnownBits function.
computeKnownBits is stateless and recursive, therefore it is limited in how much analysis it can do and it will give up after 6 level or after 1 phi and 1 level.
This cause the alignment information to often be pessimistic. On some target having the right alignment important for performance.

This new pass does a more expensive analysis of KnownBits for all the integer of a function and deduce a more accurate alignment information out of it.
Also starting a discourse discussion about it.

Diff Detail

Event Timeline

ThomasRaoux created this revision.Jun 23 2022, 5:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2022, 5:31 PM
ThomasRaoux requested review of this revision.Jun 23 2022, 5:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2022, 5:31 PM
arichardson added inline comments.
llvm/lib/Transforms/Scalar/SetLoadStoreAlignment.cpp
128

It probably also makes sense to include memtransferinst here. While looking at poor codegen for CHERI-enabled RISC-V, I've noticed that missing alignment propagation on llvm.memcpy/memmove resulted in memcpy calls instead of inline expansion.

nikic added a subscriber: nikic.Jun 24 2022, 1:26 AM
nikic added inline comments.
llvm/lib/Transforms/Scalar/SetLoadStoreAlignment.cpp
59

nit: PreviousValue

69

Assert monotonic lattice here? If I got the logic right:

assert((Known.One & PreviousValue->One) == PreviousValue->One);
assert((Known.Zero & PreviousValue->Zero) == PreviousValue->Zero);
nikic added inline comments.Jun 24 2022, 1:31 AM
llvm/include/llvm/Analysis/ValueTracking.h
63

I'd suggest to pre-commit a clang-format of this header.

llvm/lib/Analysis/ValueTracking.cpp
1928

nit: It