This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Combine icmp eq/ne x, 0/1 -> x when x == 0 or 1
ClosedPublic

Authored by paquette on Sep 1 2021, 10:02 PM.

Details

Summary

This adds the following combines:

x = ... 0 or 1
c = icmp eq x, 1

->

c = x

and

x = ... 0 or 1
c = icmp ne x, 0

->

c = x

When the target's true value for the relevant types is 1.

This showed up in the following situation:

https://godbolt.org/z/M5jKexWTW

SDAG currently supports the ne case, but not the eq case. This can probably be further generalized, but I don't feel like thinking that hard right now.

This gives some minor code size improvements across the board on CTMark at -Os for AArch64. (0.1% for 7zip and pairlocalalign in particular.)

Diff Detail

Event Timeline

paquette created this revision.Sep 1 2021, 10:02 PM
paquette requested review of this revision.Sep 1 2021, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 1 2021, 10:02 PM
Herald added a subscriber: wdng. · View Herald Transcript
aemerson added inline comments.Sep 2 2021, 2:00 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
4152

s/const auto/unsigned

4156

Test for the G_ZEXT case?

paquette updated this revision to Diff 370405.Sep 2 2021, 2:12 PM
paquette marked an inline comment as done.

add missing testcase + use unsigned instead of const auto

aemerson accepted this revision.Sep 2 2021, 2:51 PM
This revision is now accepted and ready to land.Sep 2 2021, 2:51 PM
This revision was landed with ongoing or failed builds.Sep 2 2021, 3:05 PM
This revision was automatically updated to reflect the committed changes.