This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Early out of isValidAssumeForContext if the assume and the context instruction are the same
AbandonedPublic

Authored by craig.topper on Jan 17 2019, 11:09 AM.

Details

Reviewers
hfinkel
efriedma
Summary

There are two loops in this function that start at the instruction immediately after the context instruction and scans forward until it encounters the assume or another condition. But if the assume and the context are the same instruction these loops can never find the assume.

Eventually we'll end up in the second loop which will return false when isSafeToSpeculativelyExecute encounters the terminator of the basic block and returns false. But that's seems like a lot of extra looping to get that result.

This was found in asm-goto testing because we failed to add the new CallBr terminator to isSafeToSpeculativelyExecute.

Diff Detail

Event Timeline

craig.topper created this revision.Jan 17 2019, 11:09 AM

Is it possible to write a testcase without the callbr patch?

lib/Analysis/ValueTracking.cpp
549

I think we should return "true" here? The condition of an assume should hold at the point the assume executes.

With context

craig.topper marked an inline comment as done.Jan 17 2019, 2:32 PM

If we return false like we currently do via the loop. Then I don't think it can be tested since its really just making explicit what was previously an odd iteration behavior. If we change it to true then maybe that would be a behavior change we could see.

lib/Analysis/ValueTracking.cpp
549

I just did what the existing behavior ended up with when they hit the end of the basic block and called isSafeToSpeculativelyExecute

If we're going to do anything here, I'd prefer to change it to true, since that's the right answer... it seems like it isn't doing any harm in the meantime.

If we're going to do anything here, I'd prefer to change it to true, since that's the right answer... it seems like it isn't doing any harm in the meantime.

As I recall, it needs to be false. Otherwise, an assumption can imply the truth of its own argument and it will cause its own trivialization (and removal).

Otherwise, an assumption can imply the truth of its own argument and it will cause its own trivialization (and removal).

I think the isEphemeralValueOf check is supposed to take care of that? (The function currently allows cases where the context instruction is before the llvm.assume call.)

craig.topper abandoned this revision.Feb 26 2019, 1:51 PM