2018-04-25 11:40:45 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
2015-01-28 22:08:22 +08:00
|
|
|
; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu | FileCheck %s --check-prefix=X64
|
|
|
|
; RUN: llc < %s -mtriple=x86_64-pc-linux-gnux32 | FileCheck %s --check-prefix=X64
|
|
|
|
; RUN: llc < %s -mtriple=i686-pc-linux | FileCheck %s --check-prefix=X86
|
|
|
|
|
|
|
|
define i32 @mul4_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul4_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
|
|
|
; X64-NEXT: leal (,%rdi,4), %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul4_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: shll $2, %eax
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i32 %A, 4
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @mul4_64(i64 %A) {
|
|
|
|
; X64-LABEL: mul4_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: leaq (,%rdi,4), %rax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul4_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
|
|
|
|
; X86-NEXT: shldl $2, %eax, %edx
|
|
|
|
; X86-NEXT: shll $2, %eax
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i64 %A, 4
|
|
|
|
ret i64 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul4096_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul4096_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: shll $12, %eax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul4096_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: shll $12, %eax
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i32 %A, 4096
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @mul4096_64(i64 %A) {
|
|
|
|
; X64-LABEL: mul4096_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movq %rdi, %rax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: shlq $12, %rax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul4096_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
|
|
|
|
; X86-NEXT: shldl $12, %eax, %edx
|
|
|
|
; X86-NEXT: shll $12, %eax
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i64 %A, 4096
|
|
|
|
ret i64 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mulmin4096_32(i32 %A) {
|
|
|
|
; X64-LABEL: mulmin4096_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: shll $12, %eax
|
|
|
|
; X64-NEXT: negl %eax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mulmin4096_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: shll $12, %eax
|
|
|
|
; X86-NEXT: negl %eax
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i32 %A, -4096
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @mulmin4096_64(i64 %A) {
|
|
|
|
; X64-LABEL: mulmin4096_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movq %rdi, %rax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: shlq $12, %rax
|
|
|
|
; X64-NEXT: negq %rax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mulmin4096_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: shldl $12, %eax, %ecx
|
|
|
|
; X86-NEXT: shll $12, %eax
|
|
|
|
; X86-NEXT: xorl %edx, %edx
|
|
|
|
; X86-NEXT: negl %eax
|
|
|
|
; X86-NEXT: sbbl %ecx, %edx
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i64 %A, -4096
|
|
|
|
ret i64 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul3_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul3_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
|
|
|
; X64-NEXT: leal (%rdi,%rdi,2), %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul3_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
2018-04-26 01:35:03 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: leal (%eax,%eax,2), %eax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
; But why?!
|
|
|
|
%mul = mul i32 %A, 3
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @mul3_64(i64 %A) {
|
|
|
|
; X64-LABEL: mul3_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: leaq (%rdi,%rdi,2), %rax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul3_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
2018-04-26 01:35:03 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: leal (%eax,%eax,2), %ecx
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86-NEXT: movl $3, %eax
|
|
|
|
; X86-NEXT: mull {{[0-9]+}}(%esp)
|
|
|
|
; X86-NEXT: addl %ecx, %edx
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i64 %A, 3
|
|
|
|
ret i64 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul40_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul40_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
|
|
|
; X64-NEXT: shll $3, %edi
|
|
|
|
; X64-NEXT: leal (%rdi,%rdi,4), %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul40_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: shll $3, %eax
|
|
|
|
; X86-NEXT: leal (%eax,%eax,4), %eax
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i32 %A, 40
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @mul40_64(i64 %A) {
|
|
|
|
; X64-LABEL: mul40_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: shlq $3, %rdi
|
|
|
|
; X64-NEXT: leaq (%rdi,%rdi,4), %rax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-01-28 22:08:22 +08:00
|
|
|
; X86-LABEL: mul40_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: leal (%eax,%eax,4), %ecx
|
|
|
|
; X86-NEXT: movl $40, %eax
|
|
|
|
; X86-NEXT: mull {{[0-9]+}}(%esp)
|
|
|
|
; X86-NEXT: leal (%edx,%ecx,8), %edx
|
|
|
|
; X86-NEXT: retl
|
2015-01-28 22:08:22 +08:00
|
|
|
%mul = mul i64 %A, 40
|
|
|
|
ret i64 %mul
|
|
|
|
}
|
2015-08-12 19:27:26 +08:00
|
|
|
|
|
|
|
define i32 @mul4_32_minsize(i32 %A) minsize {
|
|
|
|
; X64-LABEL: mul4_32_minsize:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
|
|
|
; X64-NEXT: leal (,%rdi,4), %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-08-12 19:27:26 +08:00
|
|
|
; X86-LABEL: mul4_32_minsize:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: shll $2, %eax
|
|
|
|
; X86-NEXT: retl
|
2015-08-12 19:27:26 +08:00
|
|
|
%mul = mul i32 %A, 4
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul40_32_minsize(i32 %A) minsize {
|
|
|
|
; X64-LABEL: mul40_32_minsize:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: imull $40, %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
2015-08-12 19:27:26 +08:00
|
|
|
; X86-LABEL: mul40_32_minsize:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: imull $40, {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: retl
|
2015-08-12 19:27:26 +08:00
|
|
|
%mul = mul i32 %A, 40
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
|
|
|
|
define i32 @mul33_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul33_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: shll $5, %eax
|
|
|
|
; X64-NEXT: leal (%rax,%rdi), %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
; X86-LABEL: mul33_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: shll $5, %eax
|
|
|
|
; X86-NEXT: addl %ecx, %eax
|
|
|
|
; X86-NEXT: retl
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
%mul = mul i32 %A, 33
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul31_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul31_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: shll $5, %eax
|
|
|
|
; X64-NEXT: subl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
; X86-LABEL: mul31_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: shll $5, %eax
|
|
|
|
; X86-NEXT: subl %ecx, %eax
|
|
|
|
; X86-NEXT: retl
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
%mul = mul i32 %A, 31
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul0_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul0_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: xorl %eax, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: mul0_32:
|
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: xorl %eax, %eax
|
|
|
|
; X86-NEXT: retl
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
%mul = mul i32 %A, 0
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @mul4294967295_32(i32 %A) {
|
|
|
|
; X64-LABEL: mul4294967295_32:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movl %edi, %eax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: negl %eax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: mul4294967295_32:
|
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: xorl %eax, %eax
|
|
|
|
; X86-NEXT: subl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: retl
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
%mul = mul i32 %A, 4294967295
|
|
|
|
ret i32 %mul
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @mul18446744073709551615_64(i64 %A) {
|
|
|
|
; X64-LABEL: mul18446744073709551615_64:
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64: # %bb.0:
|
|
|
|
; X64-NEXT: movq %rdi, %rax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: negq %rax
|
2018-04-25 11:40:45 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: mul18446744073709551615_64:
|
|
|
|
; X86: # %bb.0:
|
|
|
|
; X86-NEXT: xorl %edx, %edx
|
|
|
|
; X86-NEXT: xorl %eax, %eax
|
|
|
|
; X86-NEXT: subl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: sbbl {{[0-9]+}}(%esp), %edx
|
|
|
|
; X86-NEXT: retl
|
[X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Summary: This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Reviewers: craig.topper, RKSimon
Subscribers: aemerson, llvm-commits
Differential Revision: http://reviews.llvm.org/D14603
llvm-svn: 255415
2015-12-12 09:04:15 +08:00
|
|
|
%mul = mul i64 %A, 18446744073709551615
|
|
|
|
ret i64 %mul
|
|
|
|
}
|
2017-01-18 17:31:13 +08:00
|
|
|
|
|
|
|
define i32 @test(i32 %a) {
|
|
|
|
; X64-LABEL: test:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: shll $5, %eax
|
|
|
|
; X64-NEXT: subl %edi, %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: shll $5, %eax
|
|
|
|
; X86-NEXT: subl %ecx, %eax
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i32 %a, 31
|
|
|
|
ret i32 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test1(i32 %a) {
|
|
|
|
; X64-LABEL: test1:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: movl %edi, %ecx
|
|
|
|
; X64-NEXT: shll $5, %ecx
|
|
|
|
; X64-NEXT: subl %ecx, %eax
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test1:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2018-07-25 05:31:21 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl %eax, %ecx
|
|
|
|
; X86-NEXT: shll $5, %ecx
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: subl %ecx, %eax
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i32 %a, -31
|
|
|
|
ret i32 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define i32 @test2(i32 %a) {
|
|
|
|
; X64-LABEL: test2:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2018-02-01 06:04:26 +08:00
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: shll $5, %eax
|
|
|
|
; X64-NEXT: leal (%rax,%rdi), %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test2:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: shll $5, %eax
|
|
|
|
; X86-NEXT: addl %ecx, %eax
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i32 %a, 33
|
|
|
|
ret i32 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test3(i32 %a) {
|
|
|
|
; X64-LABEL: test3:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2018-02-01 06:04:26 +08:00
|
|
|
; X64-NEXT: # kill: def $edi killed $edi def $rdi
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movl %edi, %eax
|
|
|
|
; X64-NEXT: shll $5, %eax
|
|
|
|
; X64-NEXT: leal (%rax,%rdi), %eax
|
|
|
|
; X64-NEXT: negl %eax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test3:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: shll $5, %eax
|
|
|
|
; X86-NEXT: addl %ecx, %eax
|
|
|
|
; X86-NEXT: negl %eax
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i32 %a, -33
|
|
|
|
ret i32 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test4(i64 %a) {
|
|
|
|
; X64-LABEL: test4:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rax
|
|
|
|
; X64-NEXT: shlq $5, %rax
|
|
|
|
; X64-NEXT: subq %rdi, %rax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test4:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl %eax, %ecx
|
|
|
|
; X86-NEXT: shll $5, %ecx
|
|
|
|
; X86-NEXT: subl %eax, %ecx
|
|
|
|
; X86-NEXT: movl $31, %eax
|
|
|
|
; X86-NEXT: mull {{[0-9]+}}(%esp)
|
|
|
|
; X86-NEXT: addl %ecx, %edx
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i64 %a, 31
|
|
|
|
ret i64 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test5(i64 %a) {
|
|
|
|
; X64-LABEL: test5:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rcx
|
|
|
|
; X64-NEXT: shlq $5, %rcx
|
|
|
|
; X64-NEXT: subq %rcx, %rax
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test5:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: pushl %esi
|
|
|
|
; X86-NEXT: .cfi_def_cfa_offset 8
|
|
|
|
; X86-NEXT: .cfi_offset %esi, -8
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
2018-07-25 05:31:21 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
|
|
|
|
; X86-NEXT: movl %esi, %eax
|
|
|
|
; X86-NEXT: shll $5, %eax
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: subl %eax, %esi
|
|
|
|
; X86-NEXT: movl $-31, %edx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: mull %edx
|
|
|
|
; X86-NEXT: subl %ecx, %edx
|
2018-07-25 05:31:21 +08:00
|
|
|
; X86-NEXT: addl %esi, %edx
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: popl %esi
|
2018-04-24 18:32:08 +08:00
|
|
|
; X86-NEXT: .cfi_def_cfa_offset 4
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i64 %a, -31
|
|
|
|
ret i64 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define i64 @test6(i64 %a) {
|
|
|
|
; X64-LABEL: test6:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rax
|
|
|
|
; X64-NEXT: shlq $5, %rax
|
|
|
|
; X64-NEXT: leaq (%rax,%rdi), %rax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test6:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl %eax, %ecx
|
|
|
|
; X86-NEXT: shll $5, %ecx
|
|
|
|
; X86-NEXT: addl %eax, %ecx
|
|
|
|
; X86-NEXT: movl $33, %eax
|
|
|
|
; X86-NEXT: mull {{[0-9]+}}(%esp)
|
|
|
|
; X86-NEXT: addl %ecx, %edx
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i64 %a, 33
|
|
|
|
ret i64 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @test7(i64 %a) {
|
|
|
|
; X64-LABEL: test7:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rax
|
|
|
|
; X64-NEXT: shlq $5, %rax
|
|
|
|
; X64-NEXT: leaq (%rax,%rdi), %rax
|
|
|
|
; X64-NEXT: negq %rax
|
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: test7:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: pushl %esi
|
2017-06-28 18:21:17 +08:00
|
|
|
; X86-NEXT: .cfi_def_cfa_offset 8
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: .cfi_offset %esi, -8
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
|
|
|
|
; X86-NEXT: movl %eax, %esi
|
|
|
|
; X86-NEXT: shll $5, %esi
|
|
|
|
; X86-NEXT: addl %eax, %esi
|
|
|
|
; X86-NEXT: movl $-33, %edx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: mull %edx
|
|
|
|
; X86-NEXT: subl %ecx, %edx
|
|
|
|
; X86-NEXT: subl %esi, %edx
|
|
|
|
; X86-NEXT: popl %esi
|
2018-04-24 18:32:08 +08:00
|
|
|
; X86-NEXT: .cfi_def_cfa_offset 4
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i64 %a, -33
|
|
|
|
ret i64 %tmp3
|
|
|
|
}
|
|
|
|
|
|
|
|
define i64 @testOverflow(i64 %a) {
|
|
|
|
; X64-LABEL: testOverflow:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X64: # %bb.0: # %entry
|
2018-07-27 13:56:27 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rax
|
|
|
|
; X64-NEXT: shlq $63, %rax
|
|
|
|
; X64-NEXT: subq %rdi, %rax
|
2017-01-18 17:31:13 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: testOverflow:
|
2017-12-05 01:18:51 +08:00
|
|
|
; X86: # %bb.0: # %entry
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: pushl %esi
|
|
|
|
; X86-NEXT: .cfi_def_cfa_offset 8
|
|
|
|
; X86-NEXT: .cfi_offset %esi, -8
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl $-1, %edx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: mull %edx
|
|
|
|
; X86-NEXT: movl %ecx, %esi
|
|
|
|
; X86-NEXT: shll $31, %esi
|
|
|
|
; X86-NEXT: subl %ecx, %esi
|
|
|
|
; X86-NEXT: addl %esi, %edx
|
|
|
|
; X86-NEXT: subl {{[0-9]+}}(%esp), %edx
|
|
|
|
; X86-NEXT: popl %esi
|
2018-04-24 18:32:08 +08:00
|
|
|
; X86-NEXT: .cfi_def_cfa_offset 4
|
2017-01-18 17:31:13 +08:00
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i64 %a, 9223372036854775807
|
|
|
|
ret i64 %tmp3
|
|
|
|
}
|
2018-07-27 13:56:27 +08:00
|
|
|
|
|
|
|
define i64 @testNegOverflow(i64 %a) {
|
|
|
|
; X64-LABEL: testNegOverflow:
|
|
|
|
; X64: # %bb.0: # %entry
|
|
|
|
; X64-NEXT: movq %rdi, %rax
|
2018-09-20 02:59:08 +08:00
|
|
|
; X64-NEXT: movq %rdi, %rcx
|
|
|
|
; X64-NEXT: shlq $63, %rcx
|
|
|
|
; X64-NEXT: subq %rcx, %rax
|
2018-07-27 13:56:27 +08:00
|
|
|
; X64-NEXT: retq
|
|
|
|
;
|
|
|
|
; X86-LABEL: testNegOverflow:
|
|
|
|
; X86: # %bb.0: # %entry
|
|
|
|
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; X86-NEXT: movl $1, %edx
|
|
|
|
; X86-NEXT: movl %ecx, %eax
|
|
|
|
; X86-NEXT: mull %edx
|
|
|
|
; X86-NEXT: shll $31, %ecx
|
|
|
|
; X86-NEXT: addl %ecx, %edx
|
|
|
|
; X86-NEXT: addl {{[0-9]+}}(%esp), %edx
|
|
|
|
; X86-NEXT: retl
|
|
|
|
entry:
|
|
|
|
%tmp3 = mul i64 %a, -9223372036854775807
|
|
|
|
ret i64 %tmp3
|
|
|
|
}
|