This is an archive of the discontinued LLVM Phabricator instance.

[LVI][CVP] Handle (x | y) < C style conditions
ClosedPublic

Authored by nikic on Jun 28 2020, 6:18 AM.

Details

Summary

InstCombine converts conditions like (x < C) && (y < C) into (x | y) < C. This teaches LVI to recognize that in this case, it can infer either x < C or y < C along the edge.

This fixes the issue reported at https://github.com/rust-lang/rust/issues/73827.

Diff Detail

Event Timeline

nikic created this revision.Jun 28 2020, 6:18 AM
spatel added inline comments.Jul 1 2020, 8:10 AM
llvm/lib/Analysis/LazyValueInfo.cpp
1106

These transforms only work when C is a low-bit mask or power-of-2 (depending on predicate)?
https://alive2.llvm.org/ce/z/pmF7PF

nikic marked an inline comment as done.Jul 1 2020, 8:41 AM
nikic added inline comments.
llvm/lib/Analysis/LazyValueInfo.cpp
1106

Ah, to be clear, this is not an equivalence, only an implication. If (x | y) < 9 we know that both x < 9 and y < 9, but if we know that x < 9 and y < 9, it does not follow that (x | y) < 9 (which is what the alive proof is showing). Here, we only care about implication in one direction.

spatel added inline comments.Jul 1 2020, 9:19 AM
llvm/lib/Analysis/LazyValueInfo.cpp
1106

Modify/add tests with arbitrary constants to make that more obvious then? I missed the relationship because we're using '7' in all cases.

nikic updated this revision to Diff 274854.Jul 1 2020, 9:46 AM
nikic marked an inline comment as done.

Change tests to use magic number 42, rather than something that looks like a bit mask.

spatel accepted this revision.Jul 1 2020, 10:35 AM

LGTM

This revision is now accepted and ready to land.Jul 1 2020, 10:35 AM
This revision was automatically updated to reflect the committed changes.