This is an archive of the discontinued LLVM Phabricator instance.

SpeculativeExecution: Stop using whitelist for costs
ClosedPublic

Authored by arsenm on Sep 13 2016, 8:32 PM.

Details

Reviewers
reames
Summary

Just let TTI's cost do this instead of arbitrarily restricting this.

Diff Detail

Event Timeline

arsenm updated this revision to Diff 71291.Sep 13 2016, 8:32 PM
arsenm retitled this revision from to SpeculativeExecution: Stop using whitelist for costs.
arsenm updated this object.
arsenm added a subscriber: llvm-commits.
arsenm updated this revision to Diff 71293.Sep 13 2016, 8:40 PM

Attach correct version

reames accepted this revision.Sep 19 2016, 9:31 AM
reames added a reviewer: reames.
reames added a subscriber: reames.

I'd suggest looking over the isSafeToSpeculate code carefully. If we had any bugs there, this whitelist might have been helping to cover over them in practice. In particular, the default: return true; case in that function looks suspicious. You might want to convert that into a fully covered switch and cross reference the two lists to make sure this change isn't accidentally semantic.

Assuming you've done the above, LGTM.

This revision is now accepted and ready to land.Sep 19 2016, 9:31 AM

I'd suggest looking over the isSafeToSpeculate code carefully. If we had any bugs there, this whitelist might have been helping to cover over them in practice. In particular, the default: return true; case in that function looks suspicious. You might want to convert that into a fully covered switch and cross reference the two lists to make sure this change isn't accidentally semantic.

Assuming you've done the above, LGTM.

I only noticed what D24542 fixes, but it's possible I missed something else

Committed a halfway step in r285438 until I get a chance to better check the set of operations and fix the vector indexing

arsenm closed this revision.May 2 2017, 11:15 AM

r301950

I'd suggest looking over the isSafeToSpeculate code carefully. If we had any bugs there, this whitelist might have been helping to cover over them in practice. In particular, the default: return true; case in that function looks suspicious. You might want to convert that into a fully covered switch and cross reference the two lists to make sure this change isn't accidentally semantic.

Perhaps unsurprisingly, this review comment proved prophetic.

This patch causes us to "miscompile" some CUDA kernels.

That said, LLVM may not be at fault as PTXAS has known bugs that miscompile valid PTX programs, so I'm going to try to somehow produce a test case that shows what is going on here.

In the meantime, it sure would be nice to do as Philip suggested and make that switch covering so that we don't just have the default be safe. Or at least make the default be unsafe, which seems ... far better.

I'd suggest looking over the isSafeToSpeculate code carefully. If we had any bugs there, this whitelist might have been helping to cover over them in practice. In particular, the default: return true; case in that function looks suspicious. You might want to convert that into a fully covered switch and cross reference the two lists to make sure this change isn't accidentally semantic.

Perhaps unsurprisingly, this review comment proved prophetic.

This patch causes us to "miscompile" some CUDA kernels.

That said, LLVM may not be at fault as PTXAS has known bugs that miscompile valid PTX programs, so I'm going to try to somehow produce a test case that shows what is going on here.

After some basic investigation, this patch is really broken.

isSafeToSpeculativelyExecute doesn't actually mean it is safe to hoist something. You need a lot more to guarantee that:

  • Does it read from memory?
    • Then you can't hoist it over a clobbering store
    • You can't hoist it over a function call which could map that memory
    • You can't hoist it over a synchronization point with another thread that could map that memory (or be a clobbering store)

I haven't even thought hard about what the full, safe predicate is here. But I suspect this pass needs to look very closely at what existing, well tested LLVM passes use to do hoisting, or it needs to continue to use a whitelist.

For now, I'm reverting this patch because I don't even know how many test cases need to be written here.

Also, if the whitelist is removed, the test against UINT_MAX shoudl be as well.

In the meantime, it sure would be nice to do as Philip suggested and make that switch covering so that we don't just have the default be safe. Or at least make the default be unsafe, which seems ... far better.

And we should still do this as I don't really have a lot of confidence in that routine as-is.

This also caused https://bugs.llvm.org//show_bug.cgi?id=32964

I set that PR to resolved now since the change was reverted, but there is a somewhat small ll file
that reproduces the problem.