This is an archive of the discontinued LLVM Phabricator instance.

[GlobalISel] Handle more types in narrowScalar for eq/ne G_ICMP
ClosedPublic

Authored by paquette on Jun 29 2021, 5:14 PM.

Details

Summary

Generalize the existing eq/ne case using extractParts. The original code only handled narrowings for types of width 2n->n. This generalization allows for any type that can be broken down by extractParts.

General overview is:

  • Loop over each narrow-sized part and do exactly what the 2-register case did.
  • Loop over the leftover-sized parts and do the same thing
  • Zext the leftover-sized XOR results to the desired narrow size
  • OR that all together and then do the comparison against 0 (just like the old code)

This shows up a lot when building clang for AArch64 using GlobalISel, so it's worth fixing. For the sake of simplicity, this doesn't handle the non-eq/ne case yet.

Also remove the code in this case that notifies the observer; we're just going to delete MI anyway so talking to the observer shouldn't be necessary.

Diff Detail

Event Timeline

paquette created this revision.Jun 29 2021, 5:14 PM
paquette requested review of this revision.Jun 29 2021, 5:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 29 2021, 5:14 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.Jun 29 2021, 5:45 PM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
1116–1118

This line split is really ugly, assign Xor to a variable to put on a different line?

1124

Could you instead use extractGCDParts/buildLCMMergePieces with zext padding?

1131

auto and drop .getReg()?

paquette added inline comments.Jun 30 2021, 10:23 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
1124

I ran into some weird behaviour with s65 when I tried this and ended up with a really large testcase.

Maybe I'm doing something wrong?

SmallVector<Register, 4> WidenedXors;
...
LLT GCDTy = extractGCDType(WidenedXors, NarrowTy, LeftoverTy, Xor);
buildLCMMergePieces(LeftoverTy, NarrowTy, GCDTy, WidenedXors,
                    /* PadStrategy = */ TargetOpcode::G_ZEXT);
Parts.insert(Parts.end(), WidenedXors.begin(), WidenedXors.end());

It seemed to do the right thing with every other type.

paquette added inline comments.Jun 30 2021, 10:26 AM
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
1124

Actually, scratch that, it's horrible with just a plain zext too.

paquette updated this revision to Diff 355622.Jun 30 2021, 10:50 AM

use buildLCMMergePieces + extractGCDType + rejigger loops to be prettier

aemerson accepted this revision.Jul 12 2021, 5:37 PM
This revision is now accepted and ready to land.Jul 12 2021, 5:37 PM
This revision was landed with ongoing or failed builds.Jul 12 2021, 10:19 PM
This revision was automatically updated to reflect the committed changes.