This is an archive of the discontinued LLVM Phabricator instance.

[WIP] Treat branch on poison as immediate UB
AbandonedPublic

Authored by reames on Oct 6 2021, 10:20 AM.

Details

Summary

The LangRef clearly states that branching on a poison value is immediate undefined behavior, but historically, we have not been consistent about implementing that interpretation in the optimizer. Historically, we used (in some cases) a more relaxed model which essentially downgraded the poison to undef, and then looked for provable UB along the paths. However, we've never been 100% consistent here.

At the moment, the last big blocker for this change is D106041. Loop unswitching (in it's classic form) is incorrect with this change as it creates many "branch on poisons" when unswitching conditions originally unreachable within the loop.

This is posted mostly to show the benefit of this change optimization quality wise. If reviewers are comfortable with this, I'd like to introduce the actual code change under an off by default flag (e.g. minimal test diffs) so that we can run performance tests in combination with the unswitch changes.

Diff Detail

Event Timeline

reames created this revision.Oct 6 2021, 10:20 AM
reames requested review of this revision.Oct 6 2021, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2021, 10:20 AM
nikic added a comment.Oct 6 2021, 10:50 AM

(This is a reimplementation of D92739, which is a reimplementation of D80875 -- we tend to rediscover this obvious hole in our poison reasoning every half a year.)

(This is a reimplementation of D92739, which is a reimplementation of D80875 -- we tend to rediscover this obvious hole in our poison reasoning every half a year.)

Sounds like my "put this under an off by default flag with comment" would be very beneficial. :)

reames abandoned this revision.Oct 18 2021, 12:12 PM

Patch to add flag out for review: https://reviews.llvm.org/D112026

Abandoning this revision as the test diffs aren't going to land in the immediate future.