This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Restrict PRE across instructions that don't pass control to successors
ClosedPublic

Authored by mkazantsev on Nov 22 2017, 4:47 AM.

Details

Summary

PRE in JumpThreading should not be able to hoist copy of non-speculable loads across
instructions that don't always transfer execution to their successors, otherwise they may
introduce an unsafe load which otherwise would not be executed.

The same problem for GVN was fixed as rL316975.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Nov 22 2017, 4:47 AM

Guys, can anyone take a look? This is a fix for a miscompile which leads to functional bug.

anna accepted this revision.Dec 18 2017, 6:09 AM
anna added a subscriber: anna.

lgtm.

lib/Transforms/Scalar/JumpThreading.cpp
1337 ↗(On Diff #123912)

Nit: s/We can only validly do it if/This is valid only if/

This revision is now accepted and ready to land.Dec 18 2017, 6:09 AM
anna added a comment.Dec 18 2017, 6:13 AM

This looks simple enough and similar to how we handle other optimizations in presence of guards (there were previous issues with JT around guards that were fixed with isGuaranteedToTransferExecutionToSuccessor as well).

Pls wait and see for a day or two if anyone has other comments.

efriedma accepted this revision.Dec 18 2017, 11:31 AM
efriedma added subscribers: arielb1, efriedma.

LGTM.

(It would be nice to add a testcase using "noalias" so it's obvious this isn't just a problem with llvm.experimental.guard().)

Thanks! I will add more test cases in follow-up NFC.

Comments addressed in merged patch (comment fixed & tests added).

This revision was automatically updated to reflect the committed changes.
efriedma added inline comments.Dec 19 2017, 12:41 PM
llvm/trunk/test/Transforms/JumpThreading/guards.ll
335

Did you mean to make this argument noalias?