|
| 1 | +; RUN: llc -O0 -mtriple=spirv1.5-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-EXP |
| 2 | +; RUN: llc -O0 -mtriple=spirv1.6-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-DOT |
| 3 | +; RUN: llc -O0 -mtriple=spirv-unknown-unknown -spirv-ext=+SPV_KHR_integer_dot_product %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-DOT,CHECK-EXT |
| 4 | +; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv1.5-unknown-unknown %s -o - -filetype=obj | spirv-val %} |
| 5 | +; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv1.6-unknown-unknown %s -o - -filetype=obj | spirv-val %} |
| 6 | +; RUN: %if spirv-tools %{ llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown -spirv-ext=+SPV_KHR_integer_dot_product %s -o - -filetype=obj | spirv-val %} |
| 7 | + |
| 8 | +; CHECK-DOT: OpCapability DotProduct |
| 9 | +; CHECK-DOT: OpCapability DotProductInput4x8BitPacked |
| 10 | +; CHECK-EXT: OpExtension "SPV_KHR_integer_dot_product" |
| 11 | + |
| 12 | +; CHECK: %[[#int_32:]] = OpTypeInt 32 0 |
| 13 | +; CHECK-EXP-DAG: %[[#int_8:]] = OpTypeInt 8 0 |
| 14 | +; CHECK-EXP-DAG: %[[#zero:]] = OpConstantNull %[[#int_8]] |
| 15 | +; CHECK-EXP-DAG: %[[#eight:]] = OpConstant %[[#int_8]] 8 |
| 16 | +; CHECK-EXP-DAG: %[[#sixteen:]] = OpConstant %[[#int_8]] 16 |
| 17 | +; CHECK-EXP-DAG: %[[#twentyfour:]] = OpConstant %[[#int_8]] 24 |
| 18 | + |
| 19 | +; CHECK-LABEL: Begin function test_dot |
| 20 | +define noundef i32 @test_dot(i32 noundef %a, i32 noundef %b, i32 noundef %c) { |
| 21 | +entry: |
| 22 | +; CHECK: %[[#A:]] = OpFunctionParameter %[[#int_32]] |
| 23 | +; CHECK: %[[#B:]] = OpFunctionParameter %[[#int_32]] |
| 24 | +; CHECK: %[[#C:]] = OpFunctionParameter %[[#int_32]] |
| 25 | + |
| 26 | +; Test that we use the dot product op when capabilities allow |
| 27 | + |
| 28 | +; CHECK-DOT: %[[#DOT:]] = OpUDot %[[#int_32]] %[[#A]] %[[#B]] |
| 29 | +; CHECK-DOT: %[[#RES:]] = OpIAdd %[[#int_32]] %[[#DOT]] %[[#C]] |
| 30 | + |
| 31 | +; Test expansion is used when spirv dot product capabilities aren't available: |
| 32 | + |
| 33 | +; First element of the packed vector |
| 34 | +; CHECK-EXP: %[[#A0:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#zero]] %[[#eight]] |
| 35 | +; CHECK-EXP: %[[#B0:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#zero]] %[[#eight]] |
| 36 | +; CHECK-EXP: %[[#MUL0:]] = OpIMul %[[#int_32]] %[[#A0]] %[[#B0]] |
| 37 | +; CHECK-EXP: %[[#MASK0:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL0]] %[[#zero]] %[[#eight]] |
| 38 | +; CHECK-EXP: %[[#ACC0:]] = OpIAdd %[[#int_32]] %[[#C]] %[[#MASK0]] |
| 39 | + |
| 40 | +; Second element of the packed vector |
| 41 | +; CHECK-EXP: %[[#A1:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#eight]] %[[#eight]] |
| 42 | +; CHECK-EXP: %[[#B1:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#eight]] %[[#eight]] |
| 43 | +; CHECK-EXP: %[[#MUL1:]] = OpIMul %[[#int_32]] %[[#A1]] %[[#B1]] |
| 44 | +; CHECK-EXP: %[[#MASK1:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL1]] %[[#zero]] %[[#eight]] |
| 45 | +; CHECK-EXP: %[[#ACC1:]] = OpIAdd %[[#int_32]] %[[#ACC0]] %[[#MASK1]] |
| 46 | + |
| 47 | +; Third element of the packed vector |
| 48 | +; CHECK-EXP: %[[#A2:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#sixteen]] %[[#eight]] |
| 49 | +; CHECK-EXP: %[[#B2:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#sixteen]] %[[#eight]] |
| 50 | +; CHECK-EXP: %[[#MUL2:]] = OpIMul %[[#int_32]] %[[#A2]] %[[#B2]] |
| 51 | +; CHECK-EXP: %[[#MASK2:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL2]] %[[#zero]] %[[#eight]] |
| 52 | +; CHECK-EXP: %[[#ACC2:]] = OpIAdd %[[#int_32]] %[[#ACC1]] %[[#MASK2]] |
| 53 | + |
| 54 | +; Fourth element of the packed vector |
| 55 | +; CHECK-EXP: %[[#A3:]] = OpBitFieldUExtract %[[#int_32]] %[[#A]] %[[#twentyfour]] %[[#eight]] |
| 56 | +; CHECK-EXP: %[[#B3:]] = OpBitFieldUExtract %[[#int_32]] %[[#B]] %[[#twentyfour]] %[[#eight]] |
| 57 | +; CHECK-EXP: %[[#MUL3:]] = OpIMul %[[#int_32]] %[[#A3]] %[[#B3]] |
| 58 | +; CHECK-EXP: %[[#MASK3:]] = OpBitFieldUExtract %[[#int_32]] %[[#MUL3]] %[[#zero]] %[[#eight]] |
| 59 | + |
| 60 | +; CHECK-EXP: %[[#RES:]] = OpIAdd %[[#int_32]] %[[#ACC2]] %[[#MASK3]] |
| 61 | +; CHECK: OpReturnValue %[[#RES]] |
| 62 | + %spv.dot = call i32 @llvm.spv.dot4add.u8packed(i32 %a, i32 %b, i32 %c) |
| 63 | + |
| 64 | + ret i32 %spv.dot |
| 65 | +} |
0 commit comments