| 1 |
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s |
| 2 |
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %} |
| 3 |
|
| 4 |
%struct.ST = type { i32, i32, i32 } |
| 5 |
|
| 6 |
; CHECK-DAG: OpName %[[#struct:]] "struct.ST" |
| 7 |
; CHECK-DAG: %[[#int:]] = OpTypeInt 32 0 |
| 8 |
; CHECK-DAG: %[[#struct]] = OpTypeStruct %[[#int]] %[[#int]] %[[#int]] |
| 9 |
; CHECK-DAG: %[[#structP:]] = OpTypePointer Function %[[#struct]] |
| 10 |
; CHECK-DAG: %[[#intP:]] = OpTypePointer Function %[[#int]] |
| 11 |
; CHECK-DAG: %[[#zero:]] = OpConstantNull %[[#int]] |
| 12 |
; CHECK-DAG: %[[#one:]] = OpConstant %[[#int]] 1{{$}} |
| 13 |
; CHECK-DAG: %[[#two:]] = OpConstant %[[#int]] 2{{$}} |
| 14 |
; CHECK-DAG: %[[#three:]] = OpConstant %[[#int]] 3{{$}} |
| 15 |
|
| 16 |
define dso_local spir_func i32 @func() { |
| 17 |
entry: |
| 18 |
; CHECK-SPIRV: %[[#st:]] = OpVariable %[[#structP]] |
| 19 |
%st = alloca %struct.ST, align 4 |
| 20 |
; CHECK-SPIRV: %[[#a:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#zero]] |
| 21 |
; CHECK-SPIRV: OpStore %[[#a]] %[[#one]] |
| 22 |
%a = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 0 |
| 23 |
store i32 1, i32* %a, align 4 |
| 24 |
; CHECK-SPIRV: %[[#b:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#one]] |
| 25 |
; CHECK-SPIRV: OpStore %[[#b]] %[[#two]] |
| 26 |
%b = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 1 |
| 27 |
store i32 2, i32* %b, align 4 |
| 28 |
; CHECK-SPIRV: %[[#c:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#two]] |
| 29 |
; CHECK-SPIRV: OpStore %[[#c]] %[[#three]] |
| 30 |
%c = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 2 |
| 31 |
store i32 3, i32* %c, align 4 |
| 32 |
; CHECK-SPIRV: %[[#a1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#zero]] |
| 33 |
; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#a1]] |
| 34 |
%a1 = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 0 |
| 35 |
%0 = load i32, i32* %a1, align 4 |
| 36 |
; CHECK-SPIRV: %[[#b1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#one]] |
| 37 |
; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#b1]] |
| 38 |
%b2 = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 1 |
| 39 |
%1 = load i32, i32* %b2, align 4 |
| 40 |
%add = add nsw i32 %0, %1 |
| 41 |
; CHECK-SPIRV: %[[#c1:]] = OpInBoundsPtrAccessChain %[[#intP]] %[[#st]] %[[#zero]] %[[#two]] |
| 42 |
; CHECK-SPIRV: %[[#]] = OpLoad %[[#int]] %[[#c1]] |
| 43 |
%c3 = getelementptr inbounds %struct.ST, %struct.ST* %st, i32 0, i32 2 |
| 44 |
%2 = load i32, i32* %c3, align 4 |
| 45 |
%add4 = add nsw i32 %add, %2 |
| 46 |
ret i32 %add4 |
| 47 |
} |