1 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1200 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN %s
3 ; GCN-LABEL: {{^}}test_fmaximum3_olt_0_f32:
4 ; GCN: buffer_load_b32 [[REGC:v[0-9]+]]
5 ; GCN: buffer_load_b32 [[REGB:v[0-9]+]]
6 ; GCN: buffer_load_b32 [[REGA:v[0-9]+]]
7 ; GCN: v_maximum3_f32 [[RESULT:v[0-9]+]], [[REGC]], [[REGB]], [[REGA]]
8 ; GCN: buffer_store_b32 [[RESULT]],
9 define amdgpu_kernel void @test_fmaximum3_olt_0_f32(ptr addrspace(1) %out, ptr addrspace(1) %aptr, ptr addrspace(1) %bptr, ptr addrspace(1) %cptr) {
10 %a = load volatile float, ptr addrspace(1) %aptr, align 4
11 %b = load volatile float, ptr addrspace(1) %bptr, align 4
12 %c = load volatile float, ptr addrspace(1) %cptr, align 4
13 %f0 = call float @llvm.maximum.f32(float %a, float %b)
14 %f1 = call float @llvm.maximum.f32(float %f0, float %c)
15 store float %f1, ptr addrspace(1) %out, align 4
19 ; Commute operand of second fmaximum
20 ; GCN-LABEL: {{^}}test_fmaximum3_olt_1_f32:
21 ; GCN: buffer_load_b32 [[REGB:v[0-9]+]]
22 ; GCN: buffer_load_b32 [[REGA:v[0-9]+]]
23 ; GCN: buffer_load_b32 [[REGC:v[0-9]+]]
24 ; GCN: v_maximum3_f32 [[RESULT:v[0-9]+]], [[REGC]], [[REGB]], [[REGA]]
25 ; GCN: buffer_store_b32 [[RESULT]],
26 define amdgpu_kernel void @test_fmaximum3_olt_1_f32(ptr addrspace(1) %out, ptr addrspace(1) %aptr, ptr addrspace(1) %bptr, ptr addrspace(1) %cptr) {
27 %a = load volatile float, ptr addrspace(1) %aptr, align 4
28 %b = load volatile float, ptr addrspace(1) %bptr, align 4
29 %c = load volatile float, ptr addrspace(1) %cptr, align 4
30 %f0 = call float @llvm.maximum.f32(float %a, float %b)
31 %f1 = call float @llvm.maximum.f32(float %c, float %f0)
32 store float %f1, ptr addrspace(1) %out, align 4
36 ; GCN-LABEL: {{^}}test_fmaximum3_olt_0_f16:
37 ; GCN: buffer_load_u16 [[REGC:v[0-9]+]]
38 ; GCN: buffer_load_u16 [[REGB:v[0-9]+]]
39 ; GCN: buffer_load_u16 [[REGA:v[0-9]+]]
40 ; GCN: v_maximum3_f16 [[RESULT:v[0-9]+]], [[REGC]], [[REGB]], [[REGA]]
41 ; GCN: buffer_store_b16 [[RESULT]],
42 define amdgpu_kernel void @test_fmaximum3_olt_0_f16(ptr addrspace(1) %out, ptr addrspace(1) %aptr, ptr addrspace(1) %bptr, ptr addrspace(1) %cptr) {
43 %a = load volatile half, ptr addrspace(1) %aptr, align 2
44 %b = load volatile half, ptr addrspace(1) %bptr, align 2
45 %c = load volatile half, ptr addrspace(1) %cptr, align 2
46 %f0 = call half @llvm.maximum.f16(half %a, half %b)
47 %f1 = call half @llvm.maximum.f16(half %f0, half %c)
48 store half %f1, ptr addrspace(1) %out, align 2
52 ; GCN-LABEL: {{^}}test_fmaximum3_olt_1_f16:
53 ; GCN: buffer_load_u16 [[REGA:v[0-9]+]]
54 ; GCN: buffer_load_u16 [[REGB:v[0-9]+]]
55 ; GCN: buffer_load_u16 [[REGC:v[0-9]+]]
56 ; GCN: v_maximum3_f16 [[RESULT:v[0-9]+]], [[REGC]], [[REGA]], [[REGB]]
57 ; GCN: buffer_store_b16 [[RESULT]],
58 define amdgpu_kernel void @test_fmaximum3_olt_1_f16(ptr addrspace(1) %out, ptr addrspace(1) %aptr, ptr addrspace(1) %bptr, ptr addrspace(1) %cptr) {
59 %a = load volatile half, ptr addrspace(1) %aptr, align 2
60 %b = load volatile half, ptr addrspace(1) %bptr, align 2
61 %c = load volatile half, ptr addrspace(1) %cptr, align 2
62 %f0 = call half @llvm.maximum.f16(half %a, half %b)
63 %f1 = call half @llvm.maximum.f16(half %c, half %f0)
64 store half %f1, ptr addrspace(1) %out, align 2
68 ; Checks whether the test passes; performMinMaxCombine() should not optimize vector patterns of maximum3
69 ; since there are no pack instructions for fmaximum3.
70 ; GCN-LABEL: {{^}}no_fmaximum3_v2f16:
71 ; GCN: v_pk_maximum_f16 v0, v0, v1
72 ; GCN: v_pk_maximum_f16 v0, v2, v0
73 ; GCN: v_pk_maximum_f16 v0, v0, v3
74 ; GCN-NEXT: s_setpc_b64
75 define <2 x half> @no_fmaximum3_v2f16(<2 x half> %a, <2 x half> %b, <2 x half> %c, <2 x half> %d) {
77 %max = call <2 x half> @llvm.maximum.v2f16(<2 x half> %a, <2 x half> %b)
78 %max1 = call <2 x half> @llvm.maximum.v2f16(<2 x half> %c, <2 x half> %max)
79 %res = call <2 x half> @llvm.maximum.v2f16(<2 x half> %max1, <2 x half> %d)
83 ; GCN-LABEL: {{^}}no_fmaximum3_olt_0_f64:
84 ; GCN-COUNT-2: v_maximum_f64
85 define amdgpu_kernel void @no_fmaximum3_olt_0_f64(ptr addrspace(1) %out, ptr addrspace(1) %aptr, ptr addrspace(1) %bptr, ptr addrspace(1) %cptr) {
86 %a = load volatile double, ptr addrspace(1) %aptr, align 4
87 %b = load volatile double, ptr addrspace(1) %bptr, align 4
88 %c = load volatile double, ptr addrspace(1) %cptr, align 4
89 %f0 = call double @llvm.maximum.f64(double %a, double %b)
90 %f1 = call double @llvm.maximum.f64(double %f0, double %c)
91 store double %f1, ptr addrspace(1) %out, align 4
95 declare double @llvm.maximum.f64(double, double)
96 declare float @llvm.maximum.f32(float, float)
97 declare half @llvm.maximum.f16(half, half)
98 declare <2 x half> @llvm.maximum.v2f16(<2 x half>, <2 x half>)