Page MenuHomePhabricator

[ARM] Combine sub 0, csinc X, Y, CC -> csinv -X, Y, CC
ClosedPublic

Authored by dmgreen on Apr 6 2021, 3:42 AM.

Details

Summary

Combine sub 0, csinc X, Y, CC to csinv -X, Y, CC providing that the negation of X is cheap, currently just handling constants. This comes up during the splat of an i1 to a predicate, where we now generate csetm, as opposed to cset; rsb.

Diff Detail

Event Timeline

dmgreen created this revision.Apr 6 2021, 3:42 AM
dmgreen requested review of this revision.Apr 6 2021, 3:42 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 6 2021, 3:42 AM
malharJ added a comment.EditedApr 6 2021, 8:34 AM

I don't have much context, but I'm just wondering if a similar optimization for csneg might be useful ?
sub(0, csneg( X, Y, <cc>) ) = csinv -X, -Y-1, <cc>

llvm/lib/Target/ARM/ARMISelLowering.cpp
12736

Do you think this would be better worded as:
Fold (sub 0, ( ARMcsinc X, Y, CC) ) -> (ARMcsinv -X, Y, CC)

llvm/test/CodeGen/Thumb2/mve-vmovimm.ll
523

Is the new assembly equivalent to the old one: ie, does this set the condition codes ?

I don't have much context, but I'm just wondering if a similar optimization for csneg might be useful ?
sub(0, csneg( X, Y, <cc>) ) = csinv -X, -Y-1, <cc>

I'm not sure if that will ever come up. LLVM will usually canonicalize to something that is already simpler. The pattern for this patch comes up in splatting i1's to predicates, which is where it is useful.

llvm/test/CodeGen/Thumb2/mve-vmovimm.ll
523

The condition code isn't used though.

dmgreen updated this revision to Diff 336767.Apr 12 2021, 12:53 AM

Add some brackets to a comment, to help readability.

Thanks. LGTM

malharJ accepted this revision.Wed, Apr 14, 2:30 PM
This revision is now accepted and ready to land.Wed, Apr 14, 2:30 PM
This revision was landed with ongoing or failed builds.Fri, Apr 16, 3:52 AM
This revision was automatically updated to reflect the committed changes.