This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Walk through G_AND in TB(N)Z bit calculation
ClosedPublic

Authored by paquette on Jan 31 2020, 9:17 AM.

Details

Summary

Given

tb(n)z (and x, m), b

Where the b-th bit of m is 1,

tb(n)z (and x, m), b == tb(n)z x, b

So, we can walk past a G_AND in this case.

Also add test/CodeGen/AArch64/GlobalISel/opt-fold-and-tbz-tbnz.mir to test this.

Diff Detail

Event Timeline

paquette created this revision.Jan 31 2020, 9:17 AM
aemerson added inline comments.Jan 31 2020, 9:46 AM
llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
1014

We need to be explicit here about which opcode's we're looking for.

1027

Do we see these cases of constants on LHS often? Maybe we should fix that at the place of origin if we can.

Also: this is only valid for commutative ops, e.g. not shifts.

paquette updated this revision to Diff 241766.Jan 31 2020, 10:21 AM
paquette marked an inline comment as done.
  • Be explicit about opcodes when looking for a constant.
  • Add fixme to see if we can canonicalize where the constant shows up at a point earlier than selection.
  • Some other refactoring to make the function a bit clearer.

(The case where the constant is on the other side does come up a couple times in the MultiSource tests at -O3.)

aemerson accepted this revision.Feb 3 2020, 11:15 AM

LGTM.

This revision is now accepted and ready to land.Feb 3 2020, 11:15 AM
This revision was automatically updated to reflect the committed changes.