mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 19:52:54 +01:00
7b8ddaa293
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
174 lines
3.1 KiB
LLVM
174 lines
3.1 KiB
LLVM
; 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:
|
|
; X64: leal
|
|
; X86-LABEL: mul4_32:
|
|
; X86: shll
|
|
%mul = mul i32 %A, 4
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i64 @mul4_64(i64 %A) {
|
|
; X64-LABEL: mul4_64:
|
|
; X64: leaq
|
|
; X86-LABEL: mul4_64:
|
|
; X86: shldl
|
|
; X86: shll
|
|
%mul = mul i64 %A, 4
|
|
ret i64 %mul
|
|
}
|
|
|
|
define i32 @mul4096_32(i32 %A) {
|
|
; X64-LABEL: mul4096_32:
|
|
; X64: shll
|
|
; X86-LABEL: mul4096_32:
|
|
; X86: shll
|
|
%mul = mul i32 %A, 4096
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i64 @mul4096_64(i64 %A) {
|
|
; X64-LABEL: mul4096_64:
|
|
; X64: shlq
|
|
; X86-LABEL: mul4096_64:
|
|
; X86: shldl
|
|
; X86: shll
|
|
%mul = mul i64 %A, 4096
|
|
ret i64 %mul
|
|
}
|
|
|
|
define i32 @mulmin4096_32(i32 %A) {
|
|
; X64-LABEL: mulmin4096_32:
|
|
; X64: shll
|
|
; X64-NEXT: negl
|
|
; X86-LABEL: mulmin4096_32:
|
|
; X86: shll
|
|
; X86-NEXT: negl
|
|
%mul = mul i32 %A, -4096
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i64 @mulmin4096_64(i64 %A) {
|
|
; X64-LABEL: mulmin4096_64:
|
|
; X64: shlq
|
|
; X64-NEXT: negq
|
|
; X86-LABEL: mulmin4096_64:
|
|
; X86: shldl
|
|
; X86-NEXT: shll
|
|
; X86-NEXT: xorl
|
|
; X86-NEXT: negl
|
|
; X86-NEXT: sbbl
|
|
%mul = mul i64 %A, -4096
|
|
ret i64 %mul
|
|
}
|
|
|
|
define i32 @mul3_32(i32 %A) {
|
|
; X64-LABEL: mul3_32:
|
|
; X64: leal
|
|
; X86-LABEL: mul3_32:
|
|
; But why?!
|
|
; X86: imull
|
|
%mul = mul i32 %A, 3
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i64 @mul3_64(i64 %A) {
|
|
; X64-LABEL: mul3_64:
|
|
; X64: leaq
|
|
; X86-LABEL: mul3_64:
|
|
; X86: mull
|
|
; X86-NEXT: imull
|
|
%mul = mul i64 %A, 3
|
|
ret i64 %mul
|
|
}
|
|
|
|
define i32 @mul40_32(i32 %A) {
|
|
; X64-LABEL: mul40_32:
|
|
; X64: shll
|
|
; X64-NEXT: leal
|
|
; X86-LABEL: mul40_32:
|
|
; X86: shll
|
|
; X86-NEXT: leal
|
|
%mul = mul i32 %A, 40
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i64 @mul40_64(i64 %A) {
|
|
; X64-LABEL: mul40_64:
|
|
; X64: shlq
|
|
; X64-NEXT: leaq
|
|
; X86-LABEL: mul40_64:
|
|
; X86: leal
|
|
; X86-NEXT: movl
|
|
; X86-NEXT: mull
|
|
; X86-NEXT: leal
|
|
%mul = mul i64 %A, 40
|
|
ret i64 %mul
|
|
}
|
|
|
|
define i32 @mul4_32_minsize(i32 %A) minsize {
|
|
; X64-LABEL: mul4_32_minsize:
|
|
; X64: leal
|
|
; X86-LABEL: mul4_32_minsize:
|
|
; X86: shll
|
|
%mul = mul i32 %A, 4
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i32 @mul40_32_minsize(i32 %A) minsize {
|
|
; X64-LABEL: mul40_32_minsize:
|
|
; X64: imull
|
|
; X86-LABEL: mul40_32_minsize:
|
|
; X86: imull
|
|
%mul = mul i32 %A, 40
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i32 @mul33_32(i32 %A) {
|
|
; X64-LABEL: mul33_32:
|
|
; X64: shll
|
|
; X64-NEXT: leal
|
|
; X86-LABEL: mul33_32:
|
|
; X86: shll
|
|
; X86-NEXT: addl
|
|
%mul = mul i32 %A, 33
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i32 @mul31_32(i32 %A) {
|
|
; X64-LABEL: mul31_32:
|
|
; X64: shll
|
|
; X64-NEXT: subl
|
|
; X86-LABEL: mul31_32:
|
|
; X86: shll
|
|
; X86-NEXT: subl
|
|
%mul = mul i32 %A, 31
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i32 @mul0_32(i32 %A) {
|
|
; X64-LABEL: mul0_32:
|
|
; X64: xorl %eax, %eax
|
|
%mul = mul i32 %A, 0
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i32 @mul4294967295_32(i32 %A) {
|
|
; X64-LABEL: mul4294967295_32:
|
|
; X64: negl %edi
|
|
; X64-NEXT: movl %edi, %eax
|
|
%mul = mul i32 %A, 4294967295
|
|
ret i32 %mul
|
|
}
|
|
|
|
define i64 @mul18446744073709551615_64(i64 %A) {
|
|
; X64-LABEL: mul18446744073709551615_64:
|
|
; X64: negq %rdi
|
|
; X64-NEXT: movq %rdi, %rax
|
|
%mul = mul i64 %A, 18446744073709551615
|
|
ret i64 %mul
|
|
}
|