This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Simplify G_ICMP against true/false when boolean contents are 0/1
ClosedPublic

Authored by paquette on Apr 5 2021, 5:02 PM.

Details

Reviewers
aemerson
arsenm
Summary

Assuming 0 == false and 1 == true, if we have one of

%c = G_ICMP eq %x, 1
%c = G_ICMP ne %x, 0

If we know %x is either 0 or 1, we can replace %c with %x.

For AArch64, this saves 0.1% text size on CTMark/7zip and CTMark/mafft/pairlocalalign at -Os, and gives minor code size improvements across the rest of CTMark as well.

Diff Detail

Event Timeline

paquette created this revision.Apr 5 2021, 5:02 PM
paquette requested review of this revision.Apr 5 2021, 5:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2021, 5:02 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.Apr 5 2021, 5:06 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3908

Is this actually optional?

3917

Might as well just handle vectors and pass through isVector?

3934

This will be the wrong extension type for zero or neg1 boolean

paquette added inline comments.Apr 6 2021, 9:51 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3908

AArch64PostLegalizerLowering doesn't have it, but maybe it should?

Or maybe I should make this an assert.

3917

Sure.

3934

This doesn't handle neg1 boolean anyway, because

KnownLHS.getMinValue() == 0 && KnownLHS.getMaxValue() == 1;

wouldn't tell us if the constant is exactly one of false/true

paquette updated this revision to Diff 335584.Apr 6 2021, 10:39 AM
  • Change KB check to an assert
  • Handle vectors
  • Add a vector test in AMDGPU (which has ZeroOrOneBooleanContent for vectors)
aemerson added inline comments.Apr 6 2021, 12:20 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3908

I don't see why it should be mandatory. Combines should just skip if it isn't available.

arsenm added inline comments.Apr 6 2021, 2:24 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3908

I think this should be handled by marking a specific combine in tablegen as needing known bits. Every combine shouldn't have to insert its own check for this

aemerson added inline comments.Apr 7 2021, 9:51 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3908

That's fair enough, but until that support is implemented, we shouldn't just assert if an analysis is missing.

arsenm accepted this revision.Feb 28 2022, 5:17 PM
This revision is now accepted and ready to land.Feb 28 2022, 5:17 PM
paquette closed this revision.Sep 28 2022, 5:13 PM

This was done in D109130

Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 5:13 PM
Herald added a subscriber: kosarev. · View Herald Transcript