This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Generate CMN when comparing a short int with minus
ClosedPublic

Authored by David.Xu on Aug 18 2014, 6:44 PM.

Details

Summary

This patch generates cmn instruction when comparing a short int with minus

ldrh w8, [x0]
orr w9, wzr, #0xffff
cmp w8, w9

to

ldrsh w8, [x0]
cmn w8, #1

This patch fixes the issue by signed extending the operand.The performance test shows there are some improvements:
spec.cpu2000.ref.253_perlbmk -2.15%,
spec.cpu2006.ref.482_sphinx3 -1.59%.

As to why this patch just deals with short int, please look at the comments in the patch.

Please have a look.

David

Diff Detail

Event Timeline

David.Xu updated this revision to Diff 12637.Aug 18 2014, 6:44 PM
David.Xu retitled this revision from to [AArch64] Generate CMN when comparing a short int with minus.
David.Xu updated this object.
David.Xu edited the test plan for this revision. (Show Details)
David.Xu added a subscriber: Unknown Object (MLST).
t.p.northover edited edge metadata.Aug 19 2014, 3:54 AM

Hi David,

This looks fine mostly; just a couple of minor nits.

Cheers.

Tim.

lib/Target/AArch64/AArch64ISelLowering.cpp
1084–1117

I think you should probably mention the fundamental property you're relying on here: that (zext LHS) == (zext RHS) if and only if (sext LHS) == (sext RHS).

Your checks are all aimed at determining

  • whether LHS and RHS really are zexted
  • whether making the transformation would be profitable.
1096

int16_t would be better here.

David.Xu updated this revision to Diff 12741.Aug 21 2014, 12:21 AM
David.Xu edited edge metadata.

Comments about fundamental property are added in the patch.

Please have a look.

David

David.Xu updated this revision to Diff 12742.Aug 21 2014, 12:27 AM

ping ....

David

mcrosier accepted this revision.Aug 27 2014, 8:49 AM
mcrosier added a reviewer: mcrosier.

LGTM, once the new comments are addressed. Any additional concerns can be addressed in post-commit reviews.

lib/Target/AArch64/AArch64ISelLowering.cpp
1084

Wording improvements:

The imm operand of ADDS is an unsigned immediate, in the range 0 to 4095. For the i8 operand, the largest immediate is 255, so this can be easily encoded in the compare instruction. For i16 operand, however, the largest immediate cannot be encoded in the compare.

Therefore, use a sign extending load and cmn to avoid materializing the -1 constant. For example,

movz w1, #65535
ldrh w0, [x0, #0]
cmp w0, w1

>

ldrsh w0, [x0, #0]
cmn w0, #1

Fundamental, we're relying on the property that (zext LHS) == (zext RHS) if and only if (sext LHS) == (sext RHS). The checks are in place to ensure both the LHS and RHS are truely zero extended and to make sure the transformation is profitable.

1097

clang-format?

This revision is now accepted and ready to land.Aug 27 2014, 8:49 AM
mcrosier closed this revision.Sep 12 2014, 10:00 AM

This was committed in r216651.