This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Move imm adjustment for G_ICMP to post-legalizer lowering
ClosedPublic

Authored by paquette on Oct 20 2020, 1:49 PM.

Details

Summary

Move the code which adjusts the immediate/predicate on a G_ICMP to AArch64PostLegalizerLowering.

This

  • Reduces the number of places we need to test for optimized compares in the selector. We know that the compare should have been simplified by the time it hits the selector, so we can avoid testing this in selects, brconds, etc.
  • Allows us to potentially fold more compares (previously, this optimization was only done after calling tryFoldCompare, this may allow us to hit some more TST cases)
  • Simplifies the selection code in emitIntegerCompare significantly; we can just use an emitSUBS function.
  • Allows us to avoid checking that the predicate has been updated after emitIntegerCompare.

Also add a utility header file for things that may be useful in the selector and various combiners. No need for an implementation file at this point, since it's just one constexpr function for now. I've run into a couple cases where having one of these would be handy, so might as well add it here. There are a couple functions in the selector that can probably be factored out into here.

Diff Detail

Event Timeline

paquette created this revision.Oct 20 2020, 1:49 PM
aemerson added inline comments.Oct 21 2020, 9:04 PM
llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp
527–528

debug left

llvm/test/CodeGen/AArch64/GlobalISel/select-arith-immed-compare.mir
31

Can we have some end-to-end tests that show that the MIR that we previously had being selected to CSINCWr still selects to the same output if we now go through lowering->select? Don't have to cover all the cases but to show the mechanism still works.

Maybe we'll need to use .ll tests for this, not sure.

paquette added inline comments.Oct 21 2020, 9:21 PM
llvm/test/CodeGen/AArch64/GlobalISel/select-arith-immed-compare.mir
31

To avoid a .ll test we could do something like this:

llc -mtriple=aarch64 -start-before=aarch64-postlegalizer-lowering -stop-after=instruction-select -verify-machineinstrs

A slightly hackier, but more pointed version would be:

llc -mtriple=aarch64 -run-pass=aarch64-postlegalizer-lowering -run-pass=instruction-select -verify-machineinstrs

(IIRC this works)

From the perspective that we'd only run aarch64-postlegalizer-lowering and instruction-select, I guess this is better. We'd have to use regbankselected MIR though, which is a little wonky. Not sure if that's something that we'd want to support in the future.

Preferences? (I could also just take the .ll test route, or add a GISel checkline to an existing .ll test somewhere probably)

aemerson added inline comments.Oct 21 2020, 11:21 PM
llvm/test/CodeGen/AArch64/GlobalISel/select-arith-immed-compare.mir
31

I didn't realize that -start-before and -stop-after actually worked without crashing. That's the ideal route, otherwise adding check lines to an existing .ll is fine too.

paquette updated this revision to Diff 300057.Oct 22 2020, 11:34 AM
  • Remove leftover debug code
  • Make the test also show that we select the right thing
  • Improve a couple comments
  • Add G_SELECT testcase showing that still works
  • Add ands/tst testcase showing we can now fold constants into the tst/ands case
This revision is now accepted and ready to land.Oct 22 2020, 12:23 PM