Page MenuHomePhabricator

[InstCombine] Fold select -> and/or using impliesPoison

Authored by nikic on Jan 12 2021, 1:25 PM.



We can fold a ? b : false to a & b if is_poison(b) implies that is_poison(a), at which point we're able to reuse all the usual fold on ands. In particular, this covers the very common case of icmp X, C && icmp X, C'.

This currently only has an effect if -instcombine-unsafe-select-transform=0.

Diff Detail

Event Timeline

nikic requested review of this revision.Jan 12 2021, 1:25 PM
nikic created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2021, 1:25 PM
nikic added a comment.Jan 12 2021, 1:47 PM

With this patch applied, this is the impact on InstCombine after flipping the flag: We can see that there are still quite a few cases where we regress. However, many can be fixed by stronger impliesPoison handling. E.g. we're currently missing icmp X, Y && icmp X, Y and icmp (X & C), C2 && icmp (X, C'), C2'.

aqjune accepted this revision.Jan 12 2021, 4:49 PM

Yes, I see that such pattern is quite prevalent. I'll make a patch for this.

This revision is now accepted and ready to land.Jan 12 2021, 4:49 PM
This revision was landed with ongoing or failed builds.Jan 13 2021, 8:46 AM
This revision was automatically updated to reflect the committed changes.