[llvm] r330850 - [X86] Form MUL_IMM for multiplies with 3/5/9 to encourage LEA formation over load folding.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 25 10:35:03 PDT 2018
Author: ctopper
Date: Wed Apr 25 10:35:03 2018
New Revision: 330850
URL: http://llvm.org/viewvc/llvm-project?rev=330850&view=rev
Log:
[X86] Form MUL_IMM for multiplies with 3/5/9 to encourage LEA formation over load folding.
Previously we only formed MUL_IMM when we split a constant. This blocked load folding on those cases. We should also form MUL_IMM for 3/5/9 to favor LEA over load folding.
Differential Revision: https://reviews.llvm.org/D46040
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/test/CodeGen/X86/imul.ll
llvm/trunk/test/CodeGen/X86/mul-constant-i16.ll
llvm/trunk/test/CodeGen/X86/mul-constant-i32.ll
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=330850&r1=330849&r2=330850&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Apr 25 10:35:03 2018
@@ -33225,9 +33225,14 @@ static SDValue combineMul(SDNode *N, Sel
if (!C)
return SDValue();
uint64_t MulAmt = C->getZExtValue();
- if (isPowerOf2_64(MulAmt) || MulAmt == 3 || MulAmt == 5 || MulAmt == 9)
+ if (isPowerOf2_64(MulAmt))
return SDValue();
+ SDLoc DL(N);
+ if (MulAmt == 3 || MulAmt == 5 || MulAmt == 9)
+ return DAG.getNode(X86ISD::MUL_IMM, DL, VT, N->getOperand(0),
+ N->getOperand(1));
+
uint64_t MulAmt1 = 0;
uint64_t MulAmt2 = 0;
if ((MulAmt % 9) == 0) {
@@ -33241,7 +33246,6 @@ static SDValue combineMul(SDNode *N, Sel
MulAmt2 = MulAmt / 3;
}
- SDLoc DL(N);
SDValue NewMul;
if (MulAmt2 &&
(isPowerOf2_64(MulAmt2) || MulAmt2 == 3 || MulAmt2 == 5 || MulAmt2 == 9)){
Modified: llvm/trunk/test/CodeGen/X86/imul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/imul.ll?rev=330850&r1=330849&r2=330850&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/imul.ll (original)
+++ llvm/trunk/test/CodeGen/X86/imul.ll Wed Apr 25 10:35:03 2018
@@ -119,7 +119,8 @@ define i32 @mul3_32(i32 %A) {
;
; X86-LABEL: mul3_32:
; X86: # %bb.0:
-; X86-NEXT: imull $3, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,2), %eax
; X86-NEXT: retl
; But why?!
%mul = mul i32 %A, 3
@@ -134,9 +135,10 @@ define i64 @mul3_64(i64 %A) {
;
; X86-LABEL: mul3_64:
; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,2), %ecx
; X86-NEXT: movl $3, %eax
; X86-NEXT: mull {{[0-9]+}}(%esp)
-; X86-NEXT: imull $3, {{[0-9]+}}(%esp), %ecx
; X86-NEXT: addl %ecx, %edx
; X86-NEXT: retl
%mul = mul i64 %A, 3
Modified: llvm/trunk/test/CodeGen/X86/mul-constant-i16.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/mul-constant-i16.ll?rev=330850&r1=330849&r2=330850&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/mul-constant-i16.ll (original)
+++ llvm/trunk/test/CodeGen/X86/mul-constant-i16.ll Wed Apr 25 10:35:03 2018
@@ -37,7 +37,8 @@ define i16 @test_mul_by_2(i16 %x) {
define i16 @test_mul_by_3(i16 %x) {
; X86-LABEL: test_mul_by_3:
; X86: # %bb.0:
-; X86-NEXT: imull $3, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,2), %eax
; X86-NEXT: # kill: def $ax killed $ax killed $eax
; X86-NEXT: retl
;
@@ -72,7 +73,8 @@ define i16 @test_mul_by_4(i16 %x) {
define i16 @test_mul_by_5(i16 %x) {
; X86-LABEL: test_mul_by_5:
; X86: # %bb.0:
-; X86-NEXT: imull $5, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,4), %eax
; X86-NEXT: # kill: def $ax killed $ax killed $eax
; X86-NEXT: retl
;
@@ -147,7 +149,8 @@ define i16 @test_mul_by_8(i16 %x) {
define i16 @test_mul_by_9(i16 %x) {
; X86-LABEL: test_mul_by_9:
; X86: # %bb.0:
-; X86-NEXT: imull $9, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,8), %eax
; X86-NEXT: # kill: def $ax killed $ax killed $eax
; X86-NEXT: retl
;
Modified: llvm/trunk/test/CodeGen/X86/mul-constant-i32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/mul-constant-i32.ll?rev=330850&r1=330849&r2=330850&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/mul-constant-i32.ll (original)
+++ llvm/trunk/test/CodeGen/X86/mul-constant-i32.ll Wed Apr 25 10:35:03 2018
@@ -107,7 +107,8 @@ define i32 @test_mul_by_2(i32 %x) {
define i32 @test_mul_by_3(i32 %x) {
; X86-LABEL: test_mul_by_3:
; X86: # %bb.0:
-; X86-NEXT: imull $3, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,2), %eax
; X86-NEXT: retl
;
; X64-HSW-LABEL: test_mul_by_3:
@@ -209,7 +210,8 @@ define i32 @test_mul_by_4(i32 %x) {
define i32 @test_mul_by_5(i32 %x) {
; X86-LABEL: test_mul_by_5:
; X86: # %bb.0:
-; X86-NEXT: imull $5, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,4), %eax
; X86-NEXT: retl
;
; X64-HSW-LABEL: test_mul_by_5:
@@ -415,7 +417,8 @@ define i32 @test_mul_by_8(i32 %x) {
define i32 @test_mul_by_9(i32 %x) {
; X86-LABEL: test_mul_by_9:
; X86: # %bb.0:
-; X86-NEXT: imull $9, {{[0-9]+}}(%esp), %eax
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,8), %eax
; X86-NEXT: retl
;
; X64-HSW-LABEL: test_mul_by_9:
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=330850&r1=330849&r2=330850&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll (original)
+++ llvm/trunk/test/CodeGen/X86/mul-constant-i64.ll Wed Apr 25 10:35:03 2018
@@ -107,9 +107,10 @@ define i64 @test_mul_by_2(i64 %x) {
define i64 @test_mul_by_3(i64 %x) {
; X86-LABEL: test_mul_by_3:
; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,2), %ecx
; X86-NEXT: movl $3, %eax
; X86-NEXT: mull {{[0-9]+}}(%esp)
-; X86-NEXT: imull $3, {{[0-9]+}}(%esp), %ecx
; X86-NEXT: addl %ecx, %edx
; X86-NEXT: retl
;
@@ -207,9 +208,10 @@ define i64 @test_mul_by_4(i64 %x) {
define i64 @test_mul_by_5(i64 %x) {
; X86-LABEL: test_mul_by_5:
; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,4), %ecx
; X86-NEXT: movl $5, %eax
; X86-NEXT: mull {{[0-9]+}}(%esp)
-; X86-NEXT: imull $5, {{[0-9]+}}(%esp), %ecx
; X86-NEXT: addl %ecx, %edx
; X86-NEXT: retl
;
@@ -416,9 +418,10 @@ define i64 @test_mul_by_8(i64 %x) {
define i64 @test_mul_by_9(i64 %x) {
; X86-LABEL: test_mul_by_9:
; X86: # %bb.0:
+; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
+; X86-NEXT: leal (%eax,%eax,8), %ecx
; X86-NEXT: movl $9, %eax
; X86-NEXT: mull {{[0-9]+}}(%esp)
-; X86-NEXT: imull $9, {{[0-9]+}}(%esp), %ecx
; X86-NEXT: addl %ecx, %edx
; X86-NEXT: retl
;
More information about the llvm-commits
mailing list