| 1 |
;=========================== begin_copyright_notice ============================ |
| 2 |
; |
| 3 |
; Copyright (C) 2025 Intel Corporation |
| 4 |
; |
| 5 |
; SPDX-License-Identifier: MIT |
| 6 |
; |
| 7 |
;============================ end_copyright_notice ============================= |
| 8 |
|
| 9 |
; REQUIRES: llvm-spirv, cri-supported |
| 10 |
; RUN: llvm-as %s -o %t.bc |
| 11 |
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_int4,+SPV_KHR_bfloat16 |
| 12 |
; RUN: ocloc compile -spirv_input -file %t.spv -device cri -options "-igc_opts 'ForceOCLSIMDWidth=32,DumpVISAASMToConsole=1,AddVISADumpDeclarationsToEnd=1'" | FileCheck %s |
| 13 |
|
| 14 |
; Test if conversion opcodes are present in spirv disassembly |
| 15 |
; RUN: llvm-spirv --to-text %t.spv -o %t.spt |
| 16 |
; RUN: cat %t.spt | FileCheck %s -check-prefix=CHECK-SPV |
| 17 |
; CHECK-SPV: ConvertSToF |
| 18 |
|
| 19 |
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024" |
| 20 |
target triple = "spir64-unknown-unknown" |
| 21 |
|
| 22 |
declare spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32) |
| 23 |
|
| 24 |
define spir_kernel void @Int4_to_BF16_scalar(<2 x i4> addrspace(1)* %input, bfloat addrspace(1)* %output) { |
| 25 |
; CHECK-LABEL: .kernel "Int4_to_BF16_scalar" |
| 26 |
; CHECK: mov ({{.*}}, 1) [[LUT:[A-z0-9.]*]](0,0)<1> 0x3f803f8000000000:q |
| 27 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,1)<1> 0x4040404040004000:q |
| 28 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,2)<1> 0x40a040a040804080:q |
| 29 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,3)<1> 0x40e040e040c040c0:q |
| 30 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,4)<1> 0xc0e0c0e0c100c100:q |
| 31 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,5)<1> 0xc0a0c0a0c0c0c0c0:q |
| 32 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,6)<1> 0xc040c040c080c080:q |
| 33 |
; CHECK: mov ({{.*}}, 1) [[LUT]](0,7)<1> 0xbf80bf80c000c000:q |
| 34 |
|
| 35 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST:[A-z0-9]*]].0 [[LUT_SRC:[A-z0-9]*]](0,0)<0;16,1> [[INPUT:[A-z0-9]*]](0,0)<4;1,0> |
| 36 |
; CHECK-NOT: shfl_idx4 |
| 37 |
; CHECK-DAG: // .decl [[DST]] v_type=G type=ud num_elts=32 |
| 38 |
; CHECK-DAG: // .decl [[LUT_SRC]] v_type=G type=ud num_elts=16 |
| 39 |
; CHECK-DAG: // .decl [[INPUT]] v_type=G type=ub num_elts=128 |
| 40 |
%gid = call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0) |
| 41 |
%inputAddr = getelementptr <2 x i4>, <2 x i4> addrspace(1)* %input, i64 %gid |
| 42 |
%outputAddr = getelementptr bfloat, bfloat addrspace(1)* %output, i64 %gid |
| 43 |
%1 = load <2 x i4>, <2 x i4> addrspace(1)* %inputAddr, align 1 |
| 44 |
%2 = extractelement <2 x i4> %1, i32 0 |
| 45 |
%3 = call bfloat @_Z38__builtin_spirv_ConvertInt4ToBF16INTELi(i4 %2) |
| 46 |
store bfloat %3, bfloat addrspace(1)* %outputAddr, align 2 |
| 47 |
ret void |
| 48 |
} |
| 49 |
declare dso_local spir_func bfloat @_Z38__builtin_spirv_ConvertInt4ToBF16INTELi(i4) |
| 50 |
|
| 51 |
define spir_kernel void @Int4_to_BF16_vector2(<2 x i4> addrspace(1)* %input, <2 x bfloat> addrspace(1)* %output) { |
| 52 |
; CHECK-LABEL: .kernel "Int4_to_BF16_vector2" |
| 53 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST:[A-z0-9]*]].0 [[LUT_SRC:[A-z0-9]*]](0,0)<0;16,1> [[INPUT:[A-z0-9]*]](0,0)<4;1,0> |
| 54 |
; CHECK-NOT: shfl_idx4 |
| 55 |
; CHECK-DAG: // .decl [[DST]] v_type=G type=ud num_elts=32 |
| 56 |
; CHECK-DAG: // .decl [[LUT_SRC]] v_type=G type=ud num_elts=16 |
| 57 |
; CHECK-DAG: // .decl [[INPUT]] v_type=G type=ub num_elts=128 |
| 58 |
%gid = call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0) |
| 59 |
%inputAddr = getelementptr <2 x i4>, <2 x i4> addrspace(1)* %input, i64 %gid |
| 60 |
%outputAddr = getelementptr <2 x bfloat>, <2 x bfloat> addrspace(1)* %output, i64 %gid |
| 61 |
%1 = load <2 x i4>, <2 x i4> addrspace(1)* %inputAddr, align 1 |
| 62 |
%2 = call <2 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv2_i(<2 x i4> %1) |
| 63 |
store <2 x bfloat> %2, <2 x bfloat> addrspace(1)* %outputAddr, align 4 |
| 64 |
ret void |
| 65 |
} |
| 66 |
declare dso_local spir_func <2 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv2_i(<2 x i4>) |
| 67 |
|
| 68 |
define spir_kernel void @Int4_to_BF16_vector3(<4 x i4> addrspace(1)* %input, <3 x bfloat> addrspace(1)* %output) { |
| 69 |
; CHECK-LABEL: .kernel "Int4_to_BF16_vector3" |
| 70 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST0:[A-z0-9]*]].0 [[LUT_SRC:[A-z0-9]*]](0,0)<0;16,1> [[INPUT:[A-z0-9]*]](0,0)<4;1,0> |
| 71 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST1:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 72 |
; CHECK-NOT: shfl_idx4 |
| 73 |
; CHECK-DAG: // .decl [[DST0]] v_type=G type=ud num_elts=32 |
| 74 |
; CHECK-DAG: // .decl [[DST1]] v_type=G type=ud num_elts=32 |
| 75 |
; CHECK-DAG: // .decl [[LUT_SRC]] v_type=G type=ud num_elts=16 |
| 76 |
; CHECK-DAG: // .decl [[INPUT]] v_type=G type=ub num_elts=128 |
| 77 |
%gid = call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0) |
| 78 |
%inputAddr = getelementptr <4 x i4>, <4 x i4> addrspace(1)* %input, i64 %gid |
| 79 |
%outputAddr = getelementptr <3 x bfloat>, <3 x bfloat> addrspace(1)* %output, i64 %gid |
| 80 |
%1 = load <4 x i4>, <4 x i4> addrspace(1)* %inputAddr, align 2 |
| 81 |
%2 = shufflevector <4 x i4> %1, <4 x i4> undef, <3 x i32> <i32 0, i32 1, i32 2> |
| 82 |
%3 = call <3 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv3_i(<3 x i4> %2) |
| 83 |
store <3 x bfloat> %3, <3 x bfloat> addrspace(1)* %outputAddr, align 8 |
| 84 |
ret void |
| 85 |
} |
| 86 |
declare dso_local spir_func <3 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv3_i(<3 x i4>) |
| 87 |
|
| 88 |
define spir_kernel void @Int4_to_BF16_vector4(<4 x i4> addrspace(1)* %input, <4 x bfloat> addrspace(1)* %output) { |
| 89 |
; CHECK-LABEL: .kernel "Int4_to_BF16_vector4" |
| 90 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST0:[A-z0-9]*]].0 [[LUT_SRC:[A-z0-9]*]](0,0)<0;16,1> [[INPUT:[A-z0-9]*]](0,0)<4;1,0> |
| 91 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST1:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 92 |
; CHECK-NOT: shfl_idx4 |
| 93 |
; CHECK-DAG: // .decl [[DST0]] v_type=G type=ud num_elts=32 |
| 94 |
; CHECK-DAG: // .decl [[DST1]] v_type=G type=ud num_elts=32 |
| 95 |
; CHECK-DAG: // .decl [[LUT_SRC]] v_type=G type=ud num_elts=16 |
| 96 |
; CHECK-DAG: // .decl [[INPUT]] v_type=G type=ub num_elts=128 |
| 97 |
%gid = call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0) |
| 98 |
%inputAddr = getelementptr <4 x i4>, <4 x i4> addrspace(1)* %input, i64 %gid |
| 99 |
%outputAddr = getelementptr <4 x bfloat>, <4 x bfloat> addrspace(1)* %output, i64 %gid |
| 100 |
%1 = load <4 x i4>, <4 x i4> addrspace(1)* %inputAddr, align 2 |
| 101 |
%2 = call <4 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv4_i(<4 x i4> %1) |
| 102 |
store <4 x bfloat> %2, <4 x bfloat> addrspace(1)* %outputAddr, align 8 |
| 103 |
ret void |
| 104 |
} |
| 105 |
declare dso_local spir_func <4 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv4_i(<4 x i4>) |
| 106 |
|
| 107 |
define spir_kernel void @Int4_to_BF16_vector8(<8 x i4> addrspace(1)* %input, <8 x bfloat> addrspace(1)* %output) { |
| 108 |
; CHECK-LABEL: .kernel "Int4_to_BF16_vector8" |
| 109 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST0:[A-z0-9]*]].0 [[LUT_SRC:[A-z0-9]*]](0,0)<0;16,1> [[INPUT:[A-z0-9]*]](0,0)<4;1,0> |
| 110 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST1:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 111 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST2:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 112 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST3:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 113 |
; CHECK-NOT: shfl_idx4 |
| 114 |
; CHECK-DAG: // .decl [[DST0]] v_type=G type=ud num_elts=32 |
| 115 |
; CHECK-DAG: // .decl [[DST1]] v_type=G type=ud num_elts=32 |
| 116 |
; CHECK-DAG: // .decl [[DST2]] v_type=G type=ud num_elts=32 |
| 117 |
; CHECK-DAG: // .decl [[DST3]] v_type=G type=ud num_elts=32 |
| 118 |
; CHECK-DAG: // .decl [[LUT_SRC]] v_type=G type=ud num_elts=16 |
| 119 |
; CHECK-DAG: // .decl [[INPUT]] v_type=G type=ub num_elts=128 |
| 120 |
%gid = call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0) |
| 121 |
%inputAddr = getelementptr <8 x i4>, <8 x i4> addrspace(1)* %input, i64 %gid |
| 122 |
%outputAddr = getelementptr <8 x bfloat>, <8 x bfloat> addrspace(1)* %output, i64 %gid |
| 123 |
%1 = load <8 x i4>, <8 x i4> addrspace(1)* %inputAddr, align 4 |
| 124 |
%2 = call <8 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv8_i(<8 x i4> %1) |
| 125 |
store <8 x bfloat> %2, <8 x bfloat> addrspace(1)* %outputAddr, align 16 |
| 126 |
ret void |
| 127 |
} |
| 128 |
declare dso_local spir_func <8 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv8_i(<8 x i4>) |
| 129 |
|
| 130 |
define spir_kernel void @Int4_to_BF16_vector16(<16 x i4> addrspace(1)* %input, <16 x bfloat> addrspace(1)* %output) { |
| 131 |
; CHECK-LABEL: .kernel "Int4_to_BF16_vector16" |
| 132 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST0:[A-z0-9]*]].0 [[LUT_SRC:[A-z0-9]*]](0,0)<0;16,1> [[INPUT:[A-z0-9]*]](0,0)<4;1,0> |
| 133 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST1:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 134 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST2:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 135 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST3:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 136 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST4:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 137 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST5:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 138 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST6:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 139 |
; CHECK: shfl_idx4 ({{.*}}, 32) [[DST7:[A-z0-9]*]].0 [[LUT_SRC]](0,0)<0;16,1> [[INPUT]](0,0)<4;1,0> |
| 140 |
; CHECK-NOT: shfl_idx4 |
| 141 |
; CHECK-DAG: // .decl [[DST0]] v_type=G type=ud num_elts=32 |
| 142 |
; CHECK-DAG: // .decl [[DST1]] v_type=G type=ud num_elts=32 |
| 143 |
; CHECK-DAG: // .decl [[DST2]] v_type=G type=ud num_elts=32 |
| 144 |
; CHECK-DAG: // .decl [[DST3]] v_type=G type=ud num_elts=32 |
| 145 |
; CHECK-DAG: // .decl [[DST4]] v_type=G type=ud num_elts=32 |
| 146 |
; CHECK-DAG: // .decl [[DST5]] v_type=G type=ud num_elts=32 |
| 147 |
; CHECK-DAG: // .decl [[DST6]] v_type=G type=ud num_elts=32 |
| 148 |
; CHECK-DAG: // .decl [[DST7]] v_type=G type=ud num_elts=32 |
| 149 |
; CHECK-DAG: // .decl [[LUT_SRC]] v_type=G type=ud num_elts=16 |
| 150 |
; CHECK-DAG: // .decl [[INPUT]] v_type=G type=ub num_elts=128 |
| 151 |
%gid = call spir_func i64 @_Z33__spirv_BuiltInGlobalInvocationIdi(i32 0) |
| 152 |
%inputAddr = getelementptr <16 x i4>, <16 x i4> addrspace(1)* %input, i64 %gid |
| 153 |
%outputAddr = getelementptr <16 x bfloat>, <16 x bfloat> addrspace(1)* %output, i64 %gid |
| 154 |
%1 = load <16 x i4>, <16 x i4> addrspace(1)* %inputAddr, align 8 |
| 155 |
%2 = call <16 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv16_i(<16 x i4> %1) |
| 156 |
store <16 x bfloat> %2, <16 x bfloat> addrspace(1)* %outputAddr, align 32 |
| 157 |
ret void |
| 158 |
} |
| 159 |
declare dso_local spir_func <16 x bfloat> @_Z38__builtin_spirv_ConvertInt4ToBF16INTELDv16_i(<16 x i4>) |