This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Multiply-Negate operation not lowered to mneg in AArch64
ClosedPublic

Authored by karthikthecool on Dec 22 2014, 2:10 AM.

Details

Summary

Hi All,
The below code-

int a,b,c;
void fn() {

c = -(a*b);

}

when compiled on AArch64 bit with -O3 generates the assembly as follows-

fn: @fn
BB#0:
adrp x8, a
adrp x9, b
ldr w8, [x8, :lo12:a]
ldr w9, [x9, :lo12:b]
neg w8, w8
mul w8, w9, w8
adrp x9, c
str w8, [x9, :lo12:c]
ret

the neg and mul operation can be combined to mneg in AArch64. Gcc combines the above to mneg instruction.
Added a patch in llvm to do the same.

Post patch the following assembly is generated-
fn: @fn
BB#0:
adrp x8, a
adrp x9, b
ldr w8, [x8, :lo12:a]
ldr w9, [x9, :lo12:b]
mneg w8, w8, w9
adrp x9, c
str w8, [x9, :lo12:c]
ret

Please let me know if this is good to commit.

Thanks and Regards
Karthik Bhat

Diff Detail

Repository
rL LLVM

Event Timeline

karthikthecool retitled this revision from to [AArch64] Multiply-Negate operation not lowered to mneg in AArch64.
karthikthecool updated this object.
karthikthecool edited the test plan for this revision. (Show Details)
karthikthecool added a reviewer: t.p.northover.
karthikthecool set the repository for this revision to rL LLVM.
karthikthecool added a subscriber: Unknown Object (MLST).
karthikthecool accepted this revision.Dec 22 2014, 5:41 AM
karthikthecool added a reviewer: karthikthecool.

Thanks James. Committed as r224706.

This revision is now accepted and ready to land.Dec 22 2014, 5:41 AM