This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Disable unsafe select transform behind a flag
ClosedPublic

Authored by nikic on Dec 27 2020, 9:58 AM.

Details

Summary

This disables the poison-unsafe select -> and/or transform behind a flag (we continue to perform the fold by default). This is intended to simplify testing while we add support for the select pattern. Otherwise, there's no way to test InstCombine-related changes, as InstCombine would just canonicalize it away.

This only disables the main select -> and/or transform. A number of related ones are instead changed to canonicalize to the a ? b : false and a ? true : b forms which represent and/or respectively. This requires a bit of care to avoid infinite loops, as we do not want !a ? b : false to be converted into a ? false : b.

The basic idea here is the same as D93065, this just keeps it behind a flag, and retains the canonicalizations.

Diff Detail

Event Timeline

nikic created this revision.Dec 27 2020, 9:58 AM
nikic requested review of this revision.Dec 27 2020, 9:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 27 2020, 9:58 AM
aqjune accepted this revision.Dec 27 2020, 10:30 AM

I'm fine with this flag.
@congzhe What do you think? If this lands, you can simply check your benchmark's performance with this flag disabled.

This revision is now accepted and ready to land.Dec 27 2020, 10:30 AM

What do you think about using D78152 to allow select -> and/or when it's safe (maybe in a separate patch)?

select x, y, false -> and x, y is safe if impliesPoison(y, x) holds because it guarantees that there is no such case that x is non-poison and y is poison.
The transformation is safe if x and y are non-poison: see https://alive2.llvm.org/ce/z/3X6bkc

I think this will allow many useful optimizations in InstCombine/InstSimplify working on and/or.

This revision was automatically updated to reflect the committed changes.