[AArch64][GlobalISel] Fold G_AND into G_BRCOND
authorJessica Paquette <jpaquette@apple.com>
Tue, 28 Jan 2020 19:35:44 +0000 (11:35 -0800)
committerJessica Paquette <jpaquette@apple.com>
Tue, 28 Jan 2020 22:00:31 +0000 (14:00 -0800)
commitdba29f7c3b36443c7287ba5a31d166f8edb73544
tree52db456e8dff62f9d3db980d1c0f997446d72822
parent4e799ada5860d1029ea89226b9b867302e792251
[AArch64][GlobalISel] Fold G_AND into G_BRCOND

When the G_BRCOND is fed by a 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.

Differential Revision: https://reviews.llvm.org/D73573
llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
llvm/test/CodeGen/AArch64/GlobalISel/opt-and-tbnz-tbz.mir [new file with mode: 0644]