Page MenuHomePhabricator

[AArch64][GlobalISel] Fold G_SHL into TB(N)Z bit calculation
ClosedPublic

Authored by paquette on Feb 3 2020, 1:47 PM.

Details

Summary

This implements the following optimization:

(tbz (shl x, c), b) -> (tbz x, b-c)

Which appears in getTestBitOperand in AArch64ISelLowering.cpp.

If we test bit b of shl x, c, we can fold away the shl by looking c bits to the right of b in x when this fits in the type. So, we can just test the b-cth bit.

Diff Detail

Event Timeline

paquette created this revision.Feb 3 2020, 1:47 PM
aemerson accepted this revision.Feb 3 2020, 2:21 PM
aemerson added inline comments.
llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
1063

I guess the case where b-c is negative isn't hit in real code. If it does come from real world code then the entire condbr can be folded away as always/never taken tbz/tbnz.

This revision is now accepted and ready to land.Feb 3 2020, 2:21 PM
This revision was automatically updated to reflect the committed changes.