1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00
llvm-mirror/test/CodeGen/PowerPC/combine-to-mulh-shift-amount.ll
Amy Kwan 97fd4517d5 [DAGCombiner] Combine shifts into multiply-high
This patch implements a target independent DAG combine to produce multiply-high
instructions from shifts. This DAG combine will combine shifts for any type as
long as the MULH on the narrow type is legal.

For now, it is enabled on PowerPC as PowerPC is the only target that has an
implementation of the isMulhCheaperThanMulShift TLI hook introduced in
D78271.

Moreover, this DAG combine focuses on catching the pattern:
(shift (mul (ext <narrow_type>:$a to <wide_type>), (ext <narrow_type>:$b to <wide_type>)), <narrow_width>)
to produce mulhs when we have a sign-extend, and mulhu when we have
a zero-extend.

The patch performs the following checks:
- Operation is a right shift arithmetic (sra) or logical (srl)
- Input to the shift is a multiply
- Both operands to the shift are sext/zext nodes
- The extends into the multiply are both the same
- The narrow type is half the width of the wide type
- The shift amount is the width of the narrow type
- The respective mulh operation is legal

Differential Revision: https://reviews.llvm.org/D78272
2020-06-02 15:22:48 -05:00

117 lines
2.8 KiB
LLVM

; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
; RUN: FileCheck %s
; These tests show that for 32-bit and 64-bit scalars, combining a shift to
; a single multiply-high is only valid when the shift amount is the same as
; the width of the narrow type.
; That is, combining a shift to mulh is only valid for 32-bit when the shift
; amount is 32.
; Likewise, combining a shift to mulh is only valid for 64-bit when the shift
; amount is 64.
define i32 @test_mulhw(i32 %a, i32 %b) {
; CHECK-LABEL: test_mulhw:
; CHECK: mulld
; CHECK-NOT: mulhw
; CHECK: blr
%1 = sext i32 %a to i64
%2 = sext i32 %b to i64
%mul = mul i64 %1, %2
%shr = lshr i64 %mul, 33
%tr = trunc i64 %shr to i32
ret i32 %tr
}
define i32 @test_mulhu(i32 %a, i32 %b) {
; CHECK-LABEL: test_mulhu:
; CHECK: mulld
; CHECK-NOT: mulhwu
; CHECK: blr
%1 = zext i32 %a to i64
%2 = zext i32 %b to i64
%mul = mul i64 %1, %2
%shr = lshr i64 %mul, 33
%tr = trunc i64 %shr to i32
ret i32 %tr
}
define i64 @test_mulhd(i64 %a, i64 %b) {
; CHECK-LABEL: test_mulhd:
; CHECK: mulhd
; CHECK: mulld
; CHECK: blr
%1 = sext i64 %a to i128
%2 = sext i64 %b to i128
%mul = mul i128 %1, %2
%shr = lshr i128 %mul, 63
%tr = trunc i128 %shr to i64
ret i64 %tr
}
define i64 @test_mulhdu(i64 %a, i64 %b) {
; CHECK-LABEL: test_mulhdu:
; CHECK: mulhdu
; CHECK: mulld
; CHECK: blr
%1 = zext i64 %a to i128
%2 = zext i64 %b to i128
%mul = mul i128 %1, %2
%shr = lshr i128 %mul, 63
%tr = trunc i128 %shr to i64
ret i64 %tr
}
define signext i32 @test_mulhw_signext(i32 %a, i32 %b) {
; CHECK-LABEL: test_mulhw_signext:
; CHECK: mulld
; CHECK-NOT: mulhw
; CHECK: blr
%1 = sext i32 %a to i64
%2 = sext i32 %b to i64
%mul = mul i64 %1, %2
%shr = lshr i64 %mul, 33
%tr = trunc i64 %shr to i32
ret i32 %tr
}
define zeroext i32 @test_mulhu_zeroext(i32 %a, i32 %b) {
; CHECK-LABEL: test_mulhu_zeroext:
; CHECK: mulld
; CHECK-NOT: mulhwu
; CHECK: blr
%1 = zext i32 %a to i64
%2 = zext i32 %b to i64
%mul = mul i64 %1, %2
%shr = lshr i64 %mul, 33
%tr = trunc i64 %shr to i32
ret i32 %tr
}
define signext i64 @test_mulhd_signext(i64 %a, i64 %b) {
; CHECK-LABEL: test_mulhd_signext:
; CHECK: mulhd
; CHECK: mulld
; CHECK: blr
%1 = sext i64 %a to i128
%2 = sext i64 %b to i128
%mul = mul i128 %1, %2
%shr = lshr i128 %mul, 63
%tr = trunc i128 %shr to i64
ret i64 %tr
}
define zeroext i64 @test_mulhdu_zeroext(i64 %a, i64 %b) {
; CHECK-LABEL: test_mulhdu_zeroext:
; CHECK: mulhdu
; CHECK: mulld
; CHECK: blr
%1 = zext i64 %a to i128
%2 = zext i64 %b to i128
%mul = mul i128 %1, %2
%shr = lshr i128 %mul, 63
%tr = trunc i128 %shr to i64
ret i64 %tr
}