1 ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI -check-prefix=FUNC %s
2 ; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI -check-prefix=FUNC %s
3 ; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -check-prefix=EG -check-prefix=FUNC %s
4 ; RUN: llc -march=r600 -mcpu=cayman < %s | FileCheck -check-prefix=CM -check-prefix=FUNC %s
6 ; FUNC-LABEL: {{^}}test_smul24_i32:
10 ; Signed 24-bit multiply is not supported on pre-Cayman GPUs.
13 ; Make sure we are not masking the inputs
16 define amdgpu_kernel void @test_smul24_i32(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
18 %a.shl = shl i32 %a, 8
19 %a.24 = ashr i32 %a.shl, 8
20 %b.shl = shl i32 %b, 8
21 %b.24 = ashr i32 %b.shl, 8
22 %mul24 = mul i32 %a.24, %b.24
23 store i32 %mul24, i32 addrspace(1)* %out
27 ; FUNC-LABEL: {{^}}test_smulhi24_i64:
30 ; GCN: v_mul_hi_i32_i24_e32 [[RESULT:v[0-9]+]],
31 ; GCN-NEXT: buffer_store_dword [[RESULT]]
42 define amdgpu_kernel void @test_smulhi24_i64(i32 addrspace(1)* %out, i32 %a, i32 %b) #0 {
44 %a.shl = shl i32 %a, 8
45 %a.24 = ashr i32 %a.shl, 8
46 %b.shl = shl i32 %b, 8
47 %b.24 = ashr i32 %b.shl, 8
48 %a.24.i64 = sext i32 %a.24 to i64
49 %b.24.i64 = sext i32 %b.24 to i64
50 %mul48 = mul i64 %a.24.i64, %b.24.i64
51 %mul48.hi = lshr i64 %mul48, 32
52 %mul24hi = trunc i64 %mul48.hi to i32
53 store i32 %mul24hi, i32 addrspace(1)* %out
57 ; This requires handling of the original 64-bit mul node to eliminate
58 ; unnecessary extension instructions because after legalization they
59 ; will not be removed by SimplifyDemandedBits because there are
60 ; multiple uses by the separate mul and mulhi.
62 ; FUNC-LABEL: {{^}}test_smul24_i64:
69 ; GCN-DAG: v_mul_hi_i32_i24_e32
70 ; GCN-DAG: v_mul_i32_i24_e32
72 ; GCN: buffer_store_dwordx2
73 define amdgpu_kernel void @test_smul24_i64(i64 addrspace(1)* %out, [8 x i32], i32 %a, [8 x i32], i32 %b) #0 {
74 %shl.i = shl i32 %a, 8
75 %shr.i = ashr i32 %shl.i, 8
76 %conv.i = sext i32 %shr.i to i64
77 %shl1.i = shl i32 %b, 8
78 %shr2.i = ashr i32 %shl1.i, 8
79 %conv3.i = sext i32 %shr2.i to i64
80 %mul.i = mul i64 %conv3.i, %conv.i
81 store i64 %mul.i, i64 addrspace(1)* %out
85 ; FUNC-LABEL: {{^}}test_smul24_i64_square:
86 ; GCN: s_load_dword [[A:s[0-9]+]]
87 ; GCN-DAG: v_mul_hi_i32_i24_e64 v{{[0-9]+}}, [[A]], [[A]]
88 ; GCN-DAG: v_mul_i32_i24_e64 v{{[0-9]+}}, [[A]], [[A]]
89 ; GCN: buffer_store_dwordx2
90 define amdgpu_kernel void @test_smul24_i64_square(i64 addrspace(1)* %out, i32 %a, i32 %b) #0 {
91 %shl.i = shl i32 %a, 8
92 %shr.i = ashr i32 %shl.i, 8
93 %conv.i = sext i32 %shr.i to i64
94 %mul.i = mul i64 %conv.i, %conv.i
95 store i64 %mul.i, i64 addrspace(1)* %out
99 ; FUNC-LABEL: {{^}}test_smul24_i33:
100 ; GCN: s_load_dword s
101 ; GCN: s_load_dword s
106 ; GCN-DAG: v_mul_i32_i24_e32
107 ; GCN-DAG: v_mul_hi_i32_i24_e32
108 ; SI: v_lshl_b64 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, 31
109 ; SI: v_ashr_i64 v{{\[[0-9]+:[0-9]+\]}}, v{{\[[0-9]+:[0-9]+\]}}, 31
111 ; VI: v_lshlrev_b64 v{{\[[0-9]+:[0-9]+\]}}, 31, v{{\[[0-9]+:[0-9]+\]}}
112 ; VI: v_ashrrev_i64 v{{\[[0-9]+:[0-9]+\]}}, 31, v{{\[[0-9]+:[0-9]+\]}}
114 ; GCN: buffer_store_dwordx2
115 define amdgpu_kernel void @test_smul24_i33(i64 addrspace(1)* %out, i33 %a, i33 %b) #0 {
117 %a.shl = shl i33 %a, 9
118 %a.24 = ashr i33 %a.shl, 9
119 %b.shl = shl i33 %b, 9
120 %b.24 = ashr i33 %b.shl, 9
121 %mul24 = mul i33 %a.24, %b.24
122 %ext = sext i33 %mul24 to i64
123 store i64 %ext, i64 addrspace(1)* %out
127 ; FUNC-LABEL: {{^}}test_smulhi24_i33:
133 ; SI: v_mul_hi_i32_i24_e32 v[[MUL_HI:[0-9]+]],
134 ; SI-NEXT: v_and_b32_e32 v[[HI:[0-9]+]], 1, v[[MUL_HI]]
135 ; SI-NEXT: buffer_store_dword v[[HI]]
136 define amdgpu_kernel void @test_smulhi24_i33(i32 addrspace(1)* %out, i33 %a, i33 %b) {
138 %tmp0 = shl i33 %a, 9
139 %a_24 = ashr i33 %tmp0, 9
140 %tmp1 = shl i33 %b, 9
141 %b_24 = ashr i33 %tmp1, 9
142 %tmp2 = mul i33 %a_24, %b_24
143 %hi = lshr i33 %tmp2, 32
144 %trunc = trunc i33 %hi to i32
146 store i32 %trunc, i32 addrspace(1)* %out
150 ; GCN-LABEL: {{^}}simplify_i24_crash:
151 ; GCN: v_mul_i32_i24_e32 v[[VAL_LO:[0-9]+]]
152 ; GCN: v_mov_b32_e32 v[[VAL_HI:[0-9]+]], v[[VAL_LO]]
153 ; GCN: buffer_store_dwordx2 v{{\[}}[[VAL_LO]]:[[VAL_HI]]{{\]}}
154 define amdgpu_kernel void @simplify_i24_crash(<2 x i32> addrspace(1)* %out, i32 %arg0, <2 x i32> %arg1, <2 x i32> %arg2) {
156 %cmp = icmp eq i32 %arg0, 0
157 br i1 %cmp, label %bb11, label %bb7
160 %tmp14 = shufflevector <2 x i32> %arg1, <2 x i32> undef, <2 x i32> zeroinitializer
161 %tmp16 = shufflevector <2 x i32> %arg2, <2 x i32> undef, <2 x i32> zeroinitializer
162 %tmp17 = shl <2 x i32> %tmp14, <i32 8, i32 8>
163 %tmp18 = ashr <2 x i32> %tmp17, <i32 8, i32 8>
164 %tmp19 = shl <2 x i32> %tmp16, <i32 8, i32 8>
165 %tmp20 = ashr <2 x i32> %tmp19, <i32 8, i32 8>
166 %tmp21 = mul <2 x i32> %tmp18, %tmp20
167 store <2 x i32> %tmp21, <2 x i32> addrspace(1)* %out
174 attributes #0 = { nounwind }