Matt Arsenault | d5c6515 | 2017-02-22 23:27:53 +0000 | [diff] [blame^] | 1 | ; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s |
| 2 | ; RUN: llc -march=amdgcn -mcpu=fiji -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=VI %s |
| 3 | |
| 4 | ; GCN-LABEL: {{^}}v_clamp_add_src_f32: |
| 5 | ; GCN: {{buffer|flat}}_load_dword [[A:v[0-9]+]] |
| 6 | ; GCN-NOT: [[A]] |
| 7 | ; GCN: v_add_f32_e64 v{{[0-9]+}}, [[A]], 1.0 clamp{{$}} |
| 8 | define amdgpu_kernel void @v_clamp_add_src_f32(float addrspace(1)* %out, float addrspace(1)* %aptr) #0 { |
| 9 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 10 | %gep0 = getelementptr float, float addrspace(1)* %aptr, i32 %tid |
| 11 | %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid |
| 12 | %a = load float, float addrspace(1)* %gep0 |
| 13 | %add = fadd float %a, 1.0 |
| 14 | %max = call float @llvm.maxnum.f32(float %add, float 0.0) |
| 15 | %clamp = call float @llvm.minnum.f32(float %max, float 1.0) |
| 16 | store float %clamp, float addrspace(1)* %out.gep |
| 17 | ret void |
| 18 | } |
| 19 | |
| 20 | ; GCN-LABEL: {{^}}v_clamp_multi_use_src_f32: |
| 21 | ; GCN: {{buffer|flat}}_load_dword [[A:v[0-9]+]] |
| 22 | ; GCN: v_add_f32_e32 [[ADD:v[0-9]+]], 1.0, [[A]]{{$}} |
| 23 | ; GCN: v_max_f32_e64 v{{[0-9]+}}, [[ADD]], [[ADD]] clamp{{$}} |
| 24 | define amdgpu_kernel void @v_clamp_multi_use_src_f32(float addrspace(1)* %out, float addrspace(1)* %aptr) #0 { |
| 25 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 26 | %gep0 = getelementptr float, float addrspace(1)* %aptr, i32 %tid |
| 27 | %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid |
| 28 | %a = load float, float addrspace(1)* %gep0 |
| 29 | %add = fadd float %a, 1.0 |
| 30 | %max = call float @llvm.maxnum.f32(float %add, float 0.0) |
| 31 | %clamp = call float @llvm.minnum.f32(float %max, float 1.0) |
| 32 | store float %clamp, float addrspace(1)* %out.gep |
| 33 | store volatile float %add, float addrspace(1)* undef |
| 34 | ret void |
| 35 | } |
| 36 | |
| 37 | ; GCN-LABEL: {{^}}v_clamp_dbg_use_src_f32: |
| 38 | ; GCN: {{buffer|flat}}_load_dword [[A:v[0-9]+]] |
| 39 | ; GCN-NOT: [[A]] |
| 40 | ; GCN: v_add_f32_e64 v{{[0-9]+}}, [[A]], 1.0 clamp{{$}} |
| 41 | define amdgpu_kernel void @v_clamp_dbg_use_src_f32(float addrspace(1)* %out, float addrspace(1)* %aptr) #0 { |
| 42 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 43 | %gep0 = getelementptr float, float addrspace(1)* %aptr, i32 %tid |
| 44 | %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid |
| 45 | %a = load float, float addrspace(1)* %gep0 |
| 46 | %add = fadd float %a, 1.0 |
| 47 | call void @llvm.dbg.value(metadata float %add, i64 0, metadata !4, metadata !9), !dbg !10 |
| 48 | %max = call float @llvm.maxnum.f32(float %add, float 0.0) |
| 49 | %clamp = call float @llvm.minnum.f32(float %max, float 1.0) |
| 50 | store float %clamp, float addrspace(1)* %out.gep |
| 51 | ret void |
| 52 | } |
| 53 | |
| 54 | ; GCN-LABEL: {{^}}v_clamp_add_neg_src_f32: |
| 55 | ; GCN: {{buffer|flat}}_load_dword [[A:v[0-9]+]] |
| 56 | ; GCN: v_floor_f32_e32 [[FLOOR:v[0-9]+]], [[A]] |
| 57 | ; GCN: v_max_f32_e64 v{{[0-9]+}}, -[[FLOOR]], -[[FLOOR]] clamp{{$}} |
| 58 | define amdgpu_kernel void @v_clamp_add_neg_src_f32(float addrspace(1)* %out, float addrspace(1)* %aptr) #0 { |
| 59 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 60 | %gep0 = getelementptr float, float addrspace(1)* %aptr, i32 %tid |
| 61 | %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid |
| 62 | %a = load float, float addrspace(1)* %gep0 |
| 63 | %floor = call float @llvm.floor.f32(float %a) |
| 64 | %neg.floor = fsub float -0.0, %floor |
| 65 | %max = call float @llvm.maxnum.f32(float %neg.floor, float 0.0) |
| 66 | %clamp = call float @llvm.minnum.f32(float %max, float 1.0) |
| 67 | store float %clamp, float addrspace(1)* %out.gep |
| 68 | ret void |
| 69 | } |
| 70 | |
| 71 | ; GCN-LABEL: {{^}}v_non_clamp_max_f32: |
| 72 | ; GCN: {{buffer|flat}}_load_dword [[A:v[0-9]+]] |
| 73 | ; GCN: v_add_f32_e32 [[ADD:v[0-9]+]], 1.0, [[A]]{{$}} |
| 74 | ; GCN: v_max_f32_e32 v{{[0-9]+}}, 0, [[ADD]]{{$}} |
| 75 | define amdgpu_kernel void @v_non_clamp_max_f32(float addrspace(1)* %out, float addrspace(1)* %aptr) #0 { |
| 76 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 77 | %gep0 = getelementptr float, float addrspace(1)* %aptr, i32 %tid |
| 78 | %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid |
| 79 | %a = load float, float addrspace(1)* %gep0 |
| 80 | %add = fadd float %a, 1.0 |
| 81 | %max = call float @llvm.maxnum.f32(float %add, float 0.0) |
| 82 | store float %max, float addrspace(1)* %out.gep |
| 83 | ret void |
| 84 | } |
| 85 | |
| 86 | ; GCN-LABEL: {{^}}v_clamp_add_src_f32_denormals: |
| 87 | ; GCN: {{buffer|flat}}_load_dword [[A:v[0-9]+]] |
| 88 | ; GCN: v_add_f32_e64 [[ADD:v[0-9]+]], [[A]], 1.0 clamp{{$}} |
| 89 | define amdgpu_kernel void @v_clamp_add_src_f32_denormals(float addrspace(1)* %out, float addrspace(1)* %aptr) #2 { |
| 90 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 91 | %gep0 = getelementptr float, float addrspace(1)* %aptr, i32 %tid |
| 92 | %out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid |
| 93 | %a = load float, float addrspace(1)* %gep0 |
| 94 | %add = fadd float %a, 1.0 |
| 95 | %max = call float @llvm.maxnum.f32(float %add, float 0.0) |
| 96 | %clamp = call float @llvm.minnum.f32(float %max, float 1.0) |
| 97 | store float %clamp, float addrspace(1)* %out.gep |
| 98 | ret void |
| 99 | } |
| 100 | |
| 101 | ; GCN-LABEL: {{^}}v_clamp_add_src_f16_denorm: |
| 102 | ; GCN: {{buffer|flat}}_load_ushort [[A:v[0-9]+]] |
| 103 | ; VI: v_add_f16_e64 [[ADD:v[0-9]+]], [[A]], 1.0 clamp{{$}} |
| 104 | |
| 105 | ; SI: v_cvt_f32_f16_e32 [[CVT:v[0-9]+]], [[A]] |
| 106 | ; SI: v_add_f32_e64 [[ADD:v[0-9]+]], [[CVT]], 1.0 clamp{{$}} |
| 107 | ; SI: v_cvt_f16_f32_e32 v{{[0-9]+}}, [[ADD]] |
| 108 | define amdgpu_kernel void @v_clamp_add_src_f16_denorm(half addrspace(1)* %out, half addrspace(1)* %aptr) #0 { |
| 109 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 110 | %gep0 = getelementptr half, half addrspace(1)* %aptr, i32 %tid |
| 111 | %out.gep = getelementptr half, half addrspace(1)* %out, i32 %tid |
| 112 | %a = load half, half addrspace(1)* %gep0 |
| 113 | %add = fadd half %a, 1.0 |
| 114 | %max = call half @llvm.maxnum.f16(half %add, half 0.0) |
| 115 | %clamp = call half @llvm.minnum.f16(half %max, half 1.0) |
| 116 | store half %clamp, half addrspace(1)* %out.gep |
| 117 | ret void |
| 118 | } |
| 119 | |
| 120 | ; GCN-LABEL: {{^}}v_clamp_add_src_f16_no_denormals: |
| 121 | ; GCN: {{buffer|flat}}_load_ushort [[A:v[0-9]+]] |
| 122 | ; VI-NOT: [[A]] |
| 123 | ; VI: v_add_f16_e64 v{{[0-9]+}}, [[A]], 1.0 clamp{{$}} |
| 124 | |
| 125 | ; SI: v_cvt_f32_f16_e32 [[CVT:v[0-9]+]], [[A]] |
| 126 | ; SI: v_add_f32_e64 [[ADD:v[0-9]+]], [[CVT]], 1.0 clamp{{$}} |
| 127 | ; SI: v_cvt_f16_f32_e32 v{{[0-9]+}}, [[ADD]] |
| 128 | define amdgpu_kernel void @v_clamp_add_src_f16_no_denormals(half addrspace(1)* %out, half addrspace(1)* %aptr) #3 { |
| 129 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 130 | %gep0 = getelementptr half, half addrspace(1)* %aptr, i32 %tid |
| 131 | %out.gep = getelementptr half, half addrspace(1)* %out, i32 %tid |
| 132 | %a = load half, half addrspace(1)* %gep0 |
| 133 | %add = fadd half %a, 1.0 |
| 134 | %max = call half @llvm.maxnum.f16(half %add, half 0.0) |
| 135 | %clamp = call half @llvm.minnum.f16(half %max, half 1.0) |
| 136 | store half %clamp, half addrspace(1)* %out.gep |
| 137 | ret void |
| 138 | } |
| 139 | |
| 140 | ; GCN-LABEL: {{^}}v_clamp_add_src_v2f32: |
| 141 | ; GCN: {{buffer|flat}}_load_dwordx2 v{{\[}}[[A:[0-9]+]]:[[B:[0-9]+]]{{\]}} |
| 142 | ; GCN-DAG: v_add_f32_e64 v{{[0-9]+}}, v[[A]], 1.0 clamp{{$}} |
| 143 | ; GCN-DAG: v_add_f32_e64 v{{[0-9]+}}, v[[B]], 1.0 clamp{{$}} |
| 144 | define amdgpu_kernel void @v_clamp_add_src_v2f32(<2 x float> addrspace(1)* %out, <2 x float> addrspace(1)* %aptr) #0 { |
| 145 | %tid = call i32 @llvm.amdgcn.workitem.id.x() |
| 146 | %gep0 = getelementptr <2 x float>, <2 x float> addrspace(1)* %aptr, i32 %tid |
| 147 | %out.gep = getelementptr <2 x float>, <2 x float> addrspace(1)* %out, i32 %tid |
| 148 | %a = load <2 x float>, <2 x float> addrspace(1)* %gep0 |
| 149 | %add = fadd <2 x float> %a, <float 1.0, float 1.0> |
| 150 | %max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %add, <2 x float> zeroinitializer) |
| 151 | %clamp = call <2 x float> @llvm.minnum.v2f32(<2 x float> %max, <2 x float> <float 1.0, float 1.0>) |
| 152 | store <2 x float> %clamp, <2 x float> addrspace(1)* %out.gep |
| 153 | ret void |
| 154 | } |
| 155 | |
| 156 | declare i32 @llvm.amdgcn.workitem.id.x() #1 |
| 157 | declare float @llvm.fabs.f32(float) #1 |
| 158 | declare float @llvm.floor.f32(float) #1 |
| 159 | declare float @llvm.minnum.f32(float, float) #1 |
| 160 | declare float @llvm.maxnum.f32(float, float) #1 |
| 161 | declare float @llvm.amdgcn.fmed3.f32(float, float, float) #1 |
| 162 | declare double @llvm.fabs.f64(double) #1 |
| 163 | declare double @llvm.minnum.f64(double, double) #1 |
| 164 | declare double @llvm.maxnum.f64(double, double) #1 |
| 165 | declare half @llvm.fabs.f16(half) #1 |
| 166 | declare half @llvm.minnum.f16(half, half) #1 |
| 167 | declare half @llvm.maxnum.f16(half, half) #1 |
| 168 | declare <2 x float> @llvm.minnum.v2f32(<2 x float>, <2 x float>) #1 |
| 169 | declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>) #1 |
| 170 | declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 |
| 171 | |
| 172 | attributes #0 = { nounwind } |
| 173 | attributes #1 = { nounwind readnone } |
| 174 | attributes #2 = { nounwind "target-features"="+fp32-denormals" } |
| 175 | attributes #3 = { nounwind "target-features"="-fp64-fp16-denormals" } |
| 176 | |
| 177 | !llvm.dbg.cu = !{!0} |
| 178 | !llvm.module.flags = !{!2, !3} |
| 179 | |
| 180 | !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug) |
| 181 | !1 = !DIFile(filename: "/tmp/foo.cl", directory: "/dev/null") |
| 182 | !2 = !{i32 2, !"Dwarf Version", i32 4} |
| 183 | !3 = !{i32 2, !"Debug Info Version", i32 3} |
| 184 | !4 = !DILocalVariable(name: "add", arg: 1, scope: !5, file: !1, line: 1) |
| 185 | !5 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0) |
| 186 | !6 = !DISubroutineType(types: !7) |
| 187 | !7 = !{null, !8} |
| 188 | !8 = !DIBasicType(name: "float", size: 32, align: 32) |
| 189 | !9 = !DIExpression() |
| 190 | !10 = !DILocation(line: 1, column: 42, scope: !5) |