This is an archive of the discontinued LLVM Phabricator instance.

LSV: Fix incorrectly increasing alignment
ClosedPublic

Authored by arsenm on Aug 25 2016, 10:19 PM.

Details

Summary

If the unaligned access has a dynamic offset, it may be odd which
would make the adjusted alignment incorrect to use.

Diff Detail

Event Timeline

arsenm updated this revision to Diff 69318.Aug 25 2016, 10:19 PM
arsenm retitled this revision from to LSV: Fix incorrectly increasing alignment.
arsenm updated this object.
arsenm added reviewers: jlebar, escha, asbirlea.
arsenm added a subscriber: llvm-commits.

Is there some reason you're not using getOrEnforceKnownAlignment here?

Is there some reason you're not using getOrEnforceKnownAlignment here?

I didn't know about that one. Switching to that mostly works, except it misses the case (e.g. store_unknown_offset_align1_i32) where it should be OK because the indexing should avoid an unaligned offset because it uses stripPointerCasts instead of GetUnderlyingObject

arsenm updated this revision to Diff 69439.Aug 26 2016, 3:23 PM
arsenm edited edge metadata.

Switch to using getOrEnforceKnownAlignment, even though this regresses the case. Maybe it should be extended to handle this case

efriedma added inline comments.Aug 29 2016, 10:20 AM
lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
797

I'm sort of confused about what you're doing here... what is StackAdjustedAlignment supposed to be?

arsenm added inline comments.Aug 30 2016, 5:58 PM
lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
797

It's supposed to be a normal "good" stack alignment value that will generally allow vectorization. It's a hardcoded 4 because the GPUs we care about this always works. This should be something smarter, but that's a separate change

efriedma added inline comments.Aug 31 2016, 9:54 AM
lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
797

Okay... but if StackAdjustedAlignment is the alignment which allows vectorization, shouldn't you be checking "NewAlign <= StackAdjustedAlignment", as opposed to "NewAlign <= Alignment"?

jlebar added inline comments.Aug 31 2016, 11:36 AM
lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
798

getOrEnforceKnownAlignment returns 0 on failure, maybe we should check for that instead? (If you want, you could also assert that NewAlign is either 0 or >= StackAdjustedAlignment.)

1028–1029

Why this change? It's equivalent to the old code assuming the alignment is a power of two (which, if we depend on this, we should assert?), but I don't see why we need to make the change at all.

arsenm updated this revision to Diff 70762.Sep 8 2016, 4:29 PM

Address comments

jlebar edited edge metadata.Sep 8 2016, 8:39 PM

Address comments

It looks like you only addressed one of the two comments I left. efriedma's comment is also still outstanding afaict. Was that intentional?

arsenm updated this revision to Diff 70779.Sep 8 2016, 9:08 PM
arsenm edited edge metadata.

Apparently I never saved the file

lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
798

It doesn't actually return 0 on failure, it returns the known alignment. In the motivating testcase, load_unknown_offset_align1_i8, it returns 1 when it can't find the constant offset

jlebar accepted this revision.Sep 9 2016, 2:53 PM
jlebar edited edge metadata.
jlebar added inline comments.
lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
798

I looked through the code and agree that it is as you describe.

It may be worth fixing the comment in Local.h.

This revision is now accepted and ready to land.Sep 9 2016, 2:53 PM
arsenm closed this revision.Sep 9 2016, 3:29 PM

r281110