Summary: This patch is derived from D87384. In this patch we expand the existing decomposition of mul-by-constant to be more general by implementing 2 patterns: ``` mul x, (2^N + 2^M) --> (add (shl x, N), (shl x, M)) mul x, (2^N - 2^M) --> (sub (shl x, N), (shl x, M)) ``` The conversion will be trigged if the multiplier is a big constant that the target can't use a single multiplication instruction to handle. This is controlled by the hook `decomposeMulByConstant`. More over, the conversion benefits from an ILP improvement since the instructions are independent. A case with the sequence like following also gets benefit since a shift instruction is saved. ``` *res1 = a * 0x8800; *res2 = a * 0x8080; ``` Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D88201
123 lines
2.7 KiB
LLVM
123 lines
2.7 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
|
; RUN: llc -verify-machineinstrs -mcpu=pwr9 -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s
|
|
|
|
define i64 @test1(i64 %x) {
|
|
; CHECK-LABEL: test1:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: li 4, 625
|
|
; CHECK-NEXT: sldi 4, 4, 36
|
|
; CHECK-NEXT: mulld 3, 3, 4
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, 42949672960000
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test2(i64 %x) {
|
|
; CHECK-LABEL: test2:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: li 4, -625
|
|
; CHECK-NEXT: sldi 4, 4, 36
|
|
; CHECK-NEXT: mulld 3, 3, 4
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, -42949672960000
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test3(i64 %x) {
|
|
; CHECK-LABEL: test3:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: lis 4, 74
|
|
; CHECK-NEXT: ori 4, 4, 16384
|
|
; CHECK-NEXT: mulld 3, 3, 4
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, 4866048
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test4(i64 %x) {
|
|
; CHECK-LABEL: test4:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: lis 4, -75
|
|
; CHECK-NEXT: ori 4, 4, 49152
|
|
; CHECK-NEXT: mulld 3, 3, 4
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, -4866048
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test5(i64 %x) {
|
|
; CHECK-LABEL: test5:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: sldi 4, 3, 12
|
|
; CHECK-NEXT: sldi 3, 3, 32
|
|
; CHECK-NEXT: add 3, 3, 4
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, 4294971392
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test6(i64 %x) {
|
|
; CHECK-LABEL: test6:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: sldi 4, 3, 12
|
|
; CHECK-NEXT: sldi 3, 3, 32
|
|
; CHECK-NEXT: add 3, 3, 4
|
|
; CHECK-NEXT: neg 3, 3
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, -4294971392
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test7(i64 %x) {
|
|
; CHECK-LABEL: test7:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: sldi 4, 3, 34
|
|
; CHECK-NEXT: sldi 3, 3, 13
|
|
; CHECK-NEXT: sub 3, 4, 3
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, 17179860992
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test8(i64 %x) {
|
|
; CHECK-LABEL: test8:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: sldi 4, 3, 13
|
|
; CHECK-NEXT: sldi 3, 3, 34
|
|
; CHECK-NEXT: sub 3, 4, 3
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, -17179860992
|
|
ret i64 %y
|
|
}
|
|
|
|
define i64 @test9(i64 %x) {
|
|
; CHECK-LABEL: test9:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: sldi 4, 3, 12
|
|
; CHECK-NEXT: sldi 5, 3, 32
|
|
; CHECK-NEXT: add 4, 5, 4
|
|
; CHECK-NEXT: li 5, 8193
|
|
; CHECK-NEXT: sldi 5, 5, 19
|
|
; CHECK-NEXT: mulld 3, 3, 5
|
|
; CHECK-NEXT: sub 3, 4, 3
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, 4294971392
|
|
%z = mul i64 %x, 4295491584
|
|
%res = sub i64 %y, %z
|
|
ret i64 %res
|
|
}
|
|
|
|
define i64 @test10(i64 %x) {
|
|
; CHECK-LABEL: test10:
|
|
; CHECK: # %bb.0:
|
|
; CHECK-NEXT: sldi 4, 3, 34
|
|
; CHECK-NEXT: sldi 3, 3, 30
|
|
; CHECK-NEXT: sub 3, 4, 3
|
|
; CHECK-NEXT: blr
|
|
%y = mul i64 %x, 17179860992
|
|
%z = mul i64 %x, 1073733632
|
|
%res = sub i64 %y, %z
|
|
ret i64 %res
|
|
}
|
|
|