Hi Karthik,<br><br>This all looks fine to me.<div><br></div><div>Cheers,</div><div><br></div><div>James</div><br><div class="gmail_quote">On Mon Dec 22 2014 at 11:58:41 AM Karthik Bhat <<a href="mailto:kv.bhat@samsung.com">kv.bhat@samsung.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi t.p.northover,<br>
<br>
Hi All,<br>
The below code-<br>
<br>
int a,b,c;<br>
void fn() {<br>
  c = -(a*b);<br>
}<br>
<br>
when compiled on AArch64 bit with -O3 generates the assembly as follows-<br>
<br>
fn:                                     // @fn<br>
// BB#0:<br>
        adrp    x8, a<br>
        adrp    x9, b<br>
        ldr     w8, [x8, :lo12:a]<br>
        ldr     w9, [x9, :lo12:b]<br>
        neg      w8, w8<br>
        mul      w8, w9, w8<br>
        adrp    x9, c<br>
        str     w8, [x9, :lo12:c]<br>
        ret<br>
<br>
the neg and mul operation can be combined to mneg in AArch64. Gcc combines the above to mneg instruction.<br>
Added a patch in llvm to do the same.<br>
<br>
Post patch the following assembly is generated-<br>
fn:                                     // @fn<br>
// BB#0:<br>
        adrp    x8, a<br>
        adrp    x9, b<br>
        ldr     w8, [x8, :lo12:a]<br>
        ldr     w9, [x9, :lo12:b]<br>
        mneg     w8, w8, w9<br>
        adrp    x9, c<br>
        str     w8, [x9, :lo12:c]<br>
        ret<br>
<br>
Please let me know if this is good to commit.<br>
<br>
Thanks and Regards<br>
Karthik Bhat<br>
<br>
REPOSITORY<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D6754" target="_blank">http://reviews.llvm.org/D6754</a><br>
<br>
Files:<br>
  lib/Target/AArch64/<u></u>AArch64InstrInfo.td<br>
  test/CodeGen/AArch64/dp-<u></u>3source.ll<br>
<br>
Index: lib/Target/AArch64/<u></u>AArch64InstrInfo.td<br>
==============================<u></u>==============================<u></u>=======<br>
--- lib/Target/AArch64/<u></u>AArch64InstrInfo.td<br>
+++ lib/Target/AArch64/<u></u>AArch64InstrInfo.td<br>
@@ -657,6 +657,10 @@<br>
           (MSUBWrrr GPR32:$Rn, GPR32:$Rm, WZR)>;<br>
 def : Pat<(i64 (ineg (mul GPR64:$Rn, GPR64:$Rm))),<br>
           (MSUBXrrr GPR64:$Rn, GPR64:$Rm, XZR)>;<br>
+def : Pat<(i32 (mul (ineg GPR32:$Rn), GPR32:$Rm)),<br>
+          (MSUBWrrr GPR32:$Rn, GPR32:$Rm, WZR)>;<br>
+def : Pat<(i64 (mul (ineg GPR64:$Rn), GPR64:$Rm)),<br>
+          (MSUBXrrr GPR64:$Rn, GPR64:$Rm, XZR)>;<br>
 } // AddedComplexity = 7<br>
<br>
 let AddedComplexity = 5 in {<br>
Index: test/CodeGen/AArch64/dp-<u></u>3source.ll<br>
==============================<u></u>==============================<u></u>=======<br>
--- test/CodeGen/AArch64/dp-<u></u>3source.ll<br>
+++ test/CodeGen/AArch64/dp-<u></u>3source.ll<br>
@@ -161,3 +161,18 @@<br>
 ; CHECK: umnegl {{x[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}<br>
   ret i64 %res<br>
 }<br>
+<br>
+@a = common global i32 0, align 4<br>
+@b = common global i32 0, align 4<br>
+@c = common global i32 0, align 4<br>
+<br>
+define void @test_mneg(){<br>
+; CHECK-LABEL: test_mneg:<br>
+  %1 = load i32* @a, align 4<br>
+  %2 = load i32* @b, align 4<br>
+  %3 = sub i32 0, %1<br>
+  %4 = mul i32 %2, %3<br>
+  store i32 %4, i32* @c, align 4<br>
+; CHECK: mneg {{w[0-9]+}}, {{w[0-9]+}}, {{w[0-9]+}}<br>
+  ret void<br>
+}<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/<u></u>settings/panel/<u></u>emailpreferences/</a><br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</blockquote></div>