This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Optimize some simple TBZ/TBNZ cases.
ClosedPublic

Authored by gberry on Dec 21 2015, 1:57 PM.

Details

Summary

Add some AArch64 dag combines to optimize some simple TBZ/TBNZ cases:

(tbz (and x, m), b) -> (tbz x, b)
(tbz (shl x, c), b) -> (tbz x, b-c)
(tbz (shr x, c), b) -> (tbz x, b+c)
(tbz (xor x, -1), b) -> (tbnz x, b)

Diff Detail

Event Timeline

gberry updated this revision to Diff 43399.Dec 21 2015, 1:57 PM
gberry retitled this revision from to [AArch64] Optimize some simple TBZ/TBNZ cases..
gberry updated this object.
gberry added reviewers: jmolloy, mcrosier, t.p.northover.
gberry added a subscriber: llvm-commits.
mcrosier added inline comments.Dec 22 2015, 6:29 AM
lib/Target/AArch64/AArch64ISelLowering.cpp
9528

Please remove the extra curly brackets.

9534

Mind adding a test that covers this case?

9543

I don't think SRA is covered by a test. If so, please add one.

mcrosier added a subscriber: aadg.Dec 22 2015, 7:55 AM

Hi Geoff, looks good. :-)

I have some potentially silly questions inline, just curiosities.

lib/Target/AArch64/AArch64ISelLowering.cpp
9528

Are there interesting cases where m[b]==0, so that you an elide the test and generate a direct branch? Or is that handled somewhere else in the compiler (please ignore if this would zap time to figure out, I'm only curious)

9540

Same here, f we shl > Bits, then we know x[Bit] == 0.

gberry updated this revision to Diff 43474.Dec 22 2015, 1:09 PM

Add more tests and handle ashr testing sign bit case.

Chad, Charlie,

Thanks for the review. I believe I have addressed all of your concerns.

Charlie, as to your question about folding opportunities, I don't think those should occur (they should have already been optimized). I did a test run to detect if any of these cases show up and was unable to find a single occurrence. I did however hit a few instances of a missing case of a tbz of an ashr that was essentially testing the carried-in sign bit (see the test case test18 for an example). I added some new code to handle that case in the latest version of the change.

mcrosier accepted this revision.Dec 23 2015, 9:56 AM
mcrosier edited edge metadata.

LGTM

This revision is now accepted and ready to land.Dec 23 2015, 9:56 AM
This revision was automatically updated to reflect the committed changes.