1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu \
3 ; RUN: -mcpu=pwr9 -ppc-asm-full-reg-names -ppc-vsr-nums-as-vr < %s | \
6 ; This test case tests multiply high for i32 and i64. When the values are
7 ; sign-extended, mulh[d|w] is emitted. When values are zero-extended,
8 ; mulh[d|w]u is emitted instead.
10 ; The primary goal is transforming the pattern:
11 ; (shift (mul (ext $a, <wide_type>), (ext $b, <wide_type>)), <narrow_type>)
12 ; into (mulhs $a, $b) for sign extend, and (mulhu $a, $b) for zero extend,
13 ; provided that the mulh operation is legal for <narrow_type>.
14 ; The shift operation can be either the srl or sra operations.
16 ; When no attribute is present on i32, the shift operation is srl.
17 define i32 @test_mulhw(i32 %a, i32 %b) {
18 ; CHECK-LABEL: test_mulhw:
20 ; CHECK-NEXT: mulhw r3, r3, r4
21 ; CHECK-NEXT: clrldi r3, r3, 32
23 %1 = sext i32 %a to i64
24 %2 = sext i32 %b to i64
26 %shr = lshr i64 %mul, 32
27 %tr = trunc i64 %shr to i32
31 define i32 @test_mulhu(i32 %a, i32 %b) {
32 ; CHECK-LABEL: test_mulhu:
34 ; CHECK-NEXT: mulhwu r3, r3, r4
35 ; CHECK-NEXT: clrldi r3, r3, 32
37 %1 = zext i32 %a to i64
38 %2 = zext i32 %b to i64
40 %shr = lshr i64 %mul, 32
41 %tr = trunc i64 %shr to i32
45 define i64 @test_mulhd(i64 %a, i64 %b) {
46 ; CHECK-LABEL: test_mulhd:
48 ; CHECK-NEXT: mulhd r3, r3, r4
50 %1 = sext i64 %a to i128
51 %2 = sext i64 %b to i128
52 %mul = mul i128 %1, %2
53 %shr = lshr i128 %mul, 64
54 %tr = trunc i128 %shr to i64
58 define i64 @test_mulhdu(i64 %a, i64 %b) {
59 ; CHECK-LABEL: test_mulhdu:
61 ; CHECK-NEXT: mulhdu r3, r3, r4
63 %1 = zext i64 %a to i128
64 %2 = zext i64 %b to i128
65 %mul = mul i128 %1, %2
66 %shr = lshr i128 %mul, 64
67 %tr = trunc i128 %shr to i64
71 ; When the signext attribute is present on i32, the shift operation is sra.
72 ; We are actually transforming (sra (mul sext_in_reg, sext_in_reg)) into mulh.
73 define signext i32 @test_mulhw_signext(i32 %a, i32 %b) {
74 ; CHECK-LABEL: test_mulhw_signext:
76 ; CHECK-NEXT: mulhw r3, r3, r4
77 ; CHECK-NEXT: extsw r3, r3
79 %1 = sext i32 %a to i64
80 %2 = sext i32 %b to i64
82 %shr = lshr i64 %mul, 32
83 %tr = trunc i64 %shr to i32
87 define zeroext i32 @test_mulhu_zeroext(i32 %a, i32 %b) {
88 ; CHECK-LABEL: test_mulhu_zeroext:
90 ; CHECK-NEXT: mulhwu r3, r3, r4
91 ; CHECK-NEXT: clrldi r3, r3, 32
93 %1 = zext i32 %a to i64
94 %2 = zext i32 %b to i64
96 %shr = lshr i64 %mul, 32
97 %tr = trunc i64 %shr to i32
101 define signext i64 @test_mulhd_signext(i64 %a, i64 %b) {
102 ; CHECK-LABEL: test_mulhd_signext:
104 ; CHECK-NEXT: mulhd r3, r3, r4
106 %1 = sext i64 %a to i128
107 %2 = sext i64 %b to i128
108 %mul = mul i128 %1, %2
109 %shr = lshr i128 %mul, 64
110 %tr = trunc i128 %shr to i64
114 define zeroext i64 @test_mulhdu_zeroext(i64 %a, i64 %b) {
115 ; CHECK-LABEL: test_mulhdu_zeroext:
117 ; CHECK-NEXT: mulhdu r3, r3, r4
119 %1 = zext i64 %a to i128
120 %2 = zext i64 %b to i128
121 %mul = mul i128 %1, %2
122 %shr = lshr i128 %mul, 64
123 %tr = trunc i128 %shr to i64