This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Fold G_AND into G_BRCOND
ClosedPublic

Authored by paquette on Jan 28 2020, 12:11 PM.

Details

Summary

When a G_BRCOND is fed by an eq or ne G_ICMP, it may be possible to fold a G_AND into the branch by producing a tbnz/tbz instead.

This happens when

  1. We have a ne/eq G_ICMP feeding into the G_BRCOND
  2. The G_ICMP is a comparison against 0
  3. One of the operands of the G_AND is a power of 2 constant

This is very similar to the code in AArch64TargetLowering::LowerBR_CC.

Add opt-and-tbnz-tbz to test this.

(I think that we can probably factor out all the CB(N)Z into a function like this, but I want to finish implementing the other parts of AArch64TargetLowering::LowerBR_CC first.)

Diff Detail

Event Timeline

paquette created this revision.Jan 28 2020, 12:11 PM
aemerson accepted this revision.Jan 28 2020, 1:54 PM

LGTM with minor nit.

llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
1040

Nit: when you take the log2 of the mask value, it's no longer a mask but more of a bit position. So this should be named something like Bit or TestedBit etc. It'll help make things clearer when we come to folding in more things like shifts (which I assume is going to be done between here and the branch construction below).

This revision is now accepted and ready to land.Jan 28 2020, 1:54 PM
This revision was automatically updated to reflect the committed changes.