[llvm] r339406 - [X86] Qualify one of the heuristics in combineMul to only apply to positive multiply amounts.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 9 16:27:42 PDT 2018


Author: ctopper
Date: Thu Aug  9 16:27:42 2018
New Revision: 339406

URL: http://llvm.org/viewvc/llvm-project?rev=339406&view=rev
Log:
[X86] Qualify one of the heuristics in combineMul to only apply to positive multiply amounts.

This seems to slightly help the performance of one of our internal benchmarks. We probably need better heuristics here.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=339406&r1=339405&r2=339406&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu Aug  9 16:27:42 2018
@@ -33902,10 +33902,12 @@ static SDValue combineMul(SDNode *N, Sel
        (SignMulAmt >= 0 && (MulAmt2 == 3 || MulAmt2 == 5 || MulAmt2 == 9)))) {
 
     if (isPowerOf2_64(MulAmt2) &&
-        !(N->hasOneUse() && N->use_begin()->getOpcode() == ISD::ADD))
+        !(SignMulAmt >= 0 && N->hasOneUse() &&
+          N->use_begin()->getOpcode() == ISD::ADD))
       // If second multiplifer is pow2, issue it first. We want the multiply by
       // 3, 5, or 9 to be folded into the addressing mode unless the lone use
-      // is an add.
+      // is an add. Only do this for positive multiply amounts since the
+      // negate would prevent it from being used as an address mode anyway.
       std::swap(MulAmt1, MulAmt2);
 
     if (isPowerOf2_64(MulAmt1))

Modified: llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll?rev=339406&r1=339405&r2=339406&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll (original)
+++ llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll Thu Aug  9 16:27:42 2018
@@ -2119,8 +2119,8 @@ define i64 @test_mul_by_neg10(i64 %x) {
 ; X86-NEXT:    movl %ecx, %eax
 ; X86-NEXT:    mull %edx
 ; X86-NEXT:    subl %ecx, %edx
+; X86-NEXT:    addl %esi, %esi
 ; X86-NEXT:    leal (%esi,%esi,4), %ecx
-; X86-NEXT:    addl %ecx, %ecx
 ; X86-NEXT:    subl %ecx, %edx
 ; X86-NEXT:    popl %esi
 ; X86-NEXT:    .cfi_def_cfa_offset 4
@@ -2188,8 +2188,8 @@ define i64 @test_mul_by_neg36(i64 %x) {
 ; X86-NEXT:    movl %ecx, %eax
 ; X86-NEXT:    mull %edx
 ; X86-NEXT:    subl %ecx, %edx
+; X86-NEXT:    shll $2, %esi
 ; X86-NEXT:    leal (%esi,%esi,8), %ecx
-; X86-NEXT:    shll $2, %ecx
 ; X86-NEXT:    subl %ecx, %edx
 ; X86-NEXT:    popl %esi
 ; X86-NEXT:    .cfi_def_cfa_offset 4




More information about the llvm-commits mailing list