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