This is an archive of the discontinued LLVM Phabricator instance.

LICM: Do not sink or hoist assume intrinsic calls.
AbandonedPublic

Authored by pcc on May 25 2016, 5:04 PM.

Details

Summary

This isn't useful, and it may result in assumes being removed.

This deals with more fallout from the AA change from rL268068.

Diff Detail

Event Timeline

pcc updated this revision to Diff 58541.May 25 2016, 5:04 PM
pcc retitled this revision from to LICM: Do not sink or hoist assume intrinsic calls..
pcc updated this object.
pcc added a subscriber: llvm-commits.
sanjoy edited edge metadata.May 25 2016, 5:07 PM

IIUC this is also a correctness fix, right?

Since you could have had:

volatile boolean always_false = ...;
for (...)
  if (always_false)
    assume(false);

and hoisting out assume(false) to the loop preheader will make the loop appear dead.

Never mind, I was mistaken; you can't hoist out a readnone nounwind function out of control flow anyway, and the same logic should hold for assumes.

hfinkel edited edge metadata.May 25 2016, 5:13 PM

IIUC this is also a correctness fix, right?

Since you could have had:

volatile boolean always_false = ...;
for (...)
  if (always_false)
    assume(false);

and hoisting out assume(false) to the loop preheader will make the loop appear dead.

Yes.

I was afraid something like this might happen. I think we need to revert r268068 (and the various follow-up fixes). Thoughts?

dberlin edited edge metadata.May 25 2016, 5:14 PM
dberlin added a subscriber: dberlin.

Can we just make assume use the same machinery we are now using for control
flow dependencies rather than continued a special case it everywhere

Never mind, I was mistaken; you can't hoist out a readnone nounwind function out of control flow anyway, and the same logic should hold for assumes.

Ah. Because of potential UB?

I'm fine with reverting it if we aren't going to fix it properly ATM.

But of course, for the moment that just means special casing assume in
other places

Can we just make assume use the same machinery we are now using for control
flow dependencies rather than continued a special case it everywhere

Do you mean for convergent?

pcc added a comment.May 25 2016, 5:19 PM

Personally I'd be more comfortable with reverting. If we do need special casing at this point, it seems a little safer to special case to allow optimizations than to special case to inhibit them.

Never mind, I was mistaken; you can't hoist out a readnone nounwind function out of control flow anyway, and the same logic should hold for assumes.

Ah. Because of potential UB?

Yes, an implementation of assume could be void assume(bool cond) { if (!cond) 1/0; }.

Never mind, I was mistaken; you can't hoist out a readnone nounwind function out of control flow anyway, and the same logic should hold for assumes.

Ah. Because of potential UB?

Yes, an implementation of assume could be void assume(bool cond) { if (!cond) 1/0; }.

Yes, but don't we normally assume that this UB concern does not apply to intrinsics?

Granted, but in reality, we want neither ;)

Never mind, I was mistaken; you can't hoist out a readnone nounwind function out of control flow anyway, and the same logic should hold for assumes.

Ah. Because of potential UB?

Yes, an implementation of assume could be void assume(bool cond) { if (!cond) 1/0; }.

Yes, but don't we normally assume that this UB concern does not apply to intrinsics?

I wasn't aware of such a restriction -- can you spell it out explicitly? We do have intrinsics like patchpoint and statepoint that can execute arbitrary code, so stating that intrinsics have no UB at all is probably not okay.

Never mind, I was mistaken; you can't hoist out a readnone nounwind function out of control flow anyway, and the same logic should hold for assumes.

Ah. Because of potential UB?

Yes, an implementation of assume could be void assume(bool cond) { if (!cond) 1/0; }.

Yes, but don't we normally assume that this UB concern does not apply to intrinsics?

I wasn't aware of such a restriction -- can you spell it out explicitly? We do have intrinsics like patchpoint and statepoint that can execute arbitrary code, so stating that intrinsics have no UB at all is probably not okay.

Good point, although those aren't marked as readnone. I'm quite possibly mistaken on this point, although it seems like we should have some kind of distinction on this front since most readnone intrinsics don't have value-dependent UB. We might need a safe-to-speculate attribute or something like that, however.

pcc added a comment.May 25 2016, 6:53 PM

D20653 is the revert.

pcc added a comment.May 25 2016, 6:53 PM

Sorry, I meant D20658

pcc abandoned this revision.May 25 2016, 10:07 PM

Obsoleted by D20658