This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Swap comparison operands if that enables some folding.
ClosedPublic

Authored by aadg on Oct 10 2018, 2:41 AM.

Details

Summary

AArch64 can fold some shift+extend operations on the RHS operand of
comparisons, so swap the operands if that makes sense.

This provides a fix for https://bugs.llvm.org/show_bug.cgi?id=38751

Diff Detail

Event Timeline

aadg created this revision.Oct 10 2018, 2:41 AM
SjoerdMeijer added inline comments.
lib/Target/AArch64/AArch64ISelLowering.cpp
1802

Had a quick first look, so sorry for some question about testing.... If the shift amount is in the range [0,31] and [0,64], are the edge cases tested (also values just outside this range)? Also, can Shift be negative here?

1879

Nit, feel free to ignore: perhaps the example can be given in terms of ISD nodes because that's what we're transforming here. And then TheLHS can perhaps be given a more meaningful name.

aadg added inline comments.Oct 11 2018, 5:02 AM
lib/Target/AArch64/AArch64ISelLowering.cpp
1802

The ARMARM definitely states Shift has to be in [0:31] (32bits variant) or [0:63] (64 bits variant), so it can not be negative.
You however point rightfully that testcases for the out-of-range cases for the upper bound are missing --- I'll add them right away.

1879

I think it's best to have the example in terms of what we are trying to achieve at the ISA level as this gives the reader the "why" we want to do it. The how we actually do it is what the code does.
Regarding TheLHS, it's a pattern often found in the code base and denotes what is the LHS (theLHS) under consideration at this point in the code, as it might differ from a high level LHS. I'm open to a better naming though if you have suggestions

aadg added inline comments.Oct 11 2018, 5:15 AM
lib/Target/AArch64/AArch64ISelLowering.cpp
1802

After thinking about it a bit more, testing the out of bound case for upper range is ... UB. But there are definitely some testcases missing, and those will be added.

SjoerdMeijer added inline comments.Oct 11 2018, 5:39 AM
lib/Target/AArch64/AArch64ISelLowering.cpp
1802

After thinking about it a bit more, testing the out of bound case for upper range is ... UB.

Ah yes, of course. I was thinking it could inhibit this rewrite.

1879

I think it's best to have the example in terms of what we are trying to achieve at the ISA

Fair enough.

Regarding TheLHS, it's a pattern often found in the code base and denotes what is the LHS (theLHS)

Sure, but we have 2 variables TheLHS and LHS here, which could be a bit confusing. Anyway, as I said, I was nitpicking, so please ignore.

aadg updated this revision to Diff 169361.Oct 12 2018, 3:07 AM

Address previous review comments by adding missing testcases.

SjoerdMeijer accepted this revision.Oct 12 2018, 6:03 AM

Looks fine to me

This revision is now accepted and ready to land.Oct 12 2018, 6:03 AM
This revision was automatically updated to reflect the committed changes.