This is an archive of the discontinued LLVM Phabricator instance.

[LV] fold-tail predication should be respected even with assume_safety
ClosedPublic

Authored by dorit on Aug 12 2019, 1:03 PM.

Details

Summary

assume_safety implies that loads under "if's" can be safely executed speculatively (unguarded, unmasked). However this assumption holds only for the original user "if's", not those introduced by the compiler, such as the fold-tail "if" that guards us from loading beyond the original loop trip-count. Currently the combination of fold-tail and assume-safety pragmas results in ignoring the fold-tail predicate that guards the loads, generating unmasked loads. This patch fixes this behavior.

Diff Detail

Repository
rL LLVM

Event Timeline

dorit created this revision.Aug 12 2019, 1:03 PM
Ayal accepted this revision.Aug 13 2019, 2:01 PM

LGTM, good catch!

The original overriding of SafePtrs by IsAnnotatedParallel deserves cleaning up, but preferably as a follow-up NFC patch to this wrong-code bug fix. I.e., when this "AllPtrsAreSafe" overriding takes place, there's no point in inserting any pointer to SafePtrs. (Put differently, this overriding could alternatively be implemented by inserting all accessed pointers to SafePtrs.) Finally, "continue"ing to next instruction for non-SafePtrs, while falling-thru to check I.mayWriteToMemory for SafePtrs, seems strange.

test/Transforms/LoopVectorize/X86/tail_folding_and_assume_safety.ll
55 ↗(On Diff #214689)

fold_tail() >> assume_safety()

100 ↗(On Diff #214689)

fold_tail() >> fold_tail_and_assume_safety()

This revision is now accepted and ready to land.Aug 13 2019, 2:01 PM
This revision was automatically updated to reflect the committed changes.