Page MenuHomePhabricator

[InstCombine] Simplify select operand based on equality condition

Authored by nikic on Sep 10 2020, 1:24 PM.



For selects of the type X == Y ? A : B, check if we can simplify A by using the X == Y equality and replace the operand if that's possible. We already try to do this in InstSimplify, but will only fold if the result of the simplification is the same as B, in which case the select can be dropped entirely. Here the select will be retained, just one operand simplified.

As we are performing an actual replacement here, we don't have problems with refinement / poison values.

Diff Detail

Event Timeline

nikic created this revision.Sep 10 2020, 1:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2020, 1:24 PM
nikic added a comment.Sep 10 2020, 1:31 PM

This partially subsumes the foldSelectBinOpIdentity() fold at, which handles a special case of this (where the equality comparison is to the neutral element of a binary operator). However, that fold also handles floating point equalities, which are tricky due to signed zero, so it can't simply be dropped.

reames accepted this revision.Sep 14 2020, 8:26 AM
reames added a subscriber: reames.


This revision is now accepted and ready to land.Sep 14 2020, 8:26 AM
spatel added inline comments.Sep 14 2020, 8:41 AM

Remove stale comment and rename test since it's no longer "bad",


Rename test - it's not "bad" now.

This revision was landed with ongoing or failed builds.Sep 14 2020, 11:08 AM
This revision was automatically updated to reflect the committed changes.