This is an archive of the discontinued LLVM Phabricator instance.

[GuardWidening] Add tests showing the incorrect behavior of GW wrt poison
ClosedPublic

Authored by skatkov on Jun 28 2022, 9:19 PM.

Details

Summary

The first test shows that combineRangeChecks may choose to keep only two poison conditions.
And we cannot do simple arithmetic or logical and in guard.
The second test shows that even in simple test we can hoist a poison and even logical and does not help here.

Diff Detail

Event Timeline

skatkov created this revision.Jun 28 2022, 9:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 9:19 PM
skatkov requested review of this revision.Jun 28 2022, 9:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 9:19 PM
mkazantsev added inline comments.Jun 28 2022, 10:35 PM
llvm/test/Transforms/GuardWidening/posion.ll
15

nit: considers

17

nit: consider then -> considers them

23

please add FIXME into the comment

74

I don't quite get it. COND_0 here is not poison, why would logical and not help?

I didn't quite get what's the problem with 2nd example and logical and, but the first example is more than enough to admit it's a bug.

skatkov added inline comments.Jun 28 2022, 10:41 PM
llvm/test/Transforms/GuardWidening/posion.ll
74

Consider a = 5, b = -1
b.shift and cond2 are poison
a u< 10
So with logical and the result of select is posion.
guard on poison is UB.

In original program check in the loop b u< 10 protects us from the execution the guard in ok block on poison value - so no UB.

mkazantsev accepted this revision.Jun 28 2022, 11:29 PM

Pls add test with side effect that we've discussed offline.

This revision is now accepted and ready to land.Jun 28 2022, 11:29 PM
skatkov updated this revision to Diff 440868.Jun 28 2022, 11:39 PM

Add test with side effect for combine range checks.

skatkov updated this revision to Diff 440871.Jun 28 2022, 11:41 PM

handle nits.

skatkov closed this revision.Jun 29 2022, 12:09 AM

Landed.