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.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
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() |