This PR improves type inference of operand presented by opaque pointers and aggregate types: * tries to restore original function return type for aggregate types so that it's possible to deduce a correct type during emit-intrinsics step (see llvm/test/CodeGen/SPIRV/SpecConstants/restore-spec-type.ll for the reproducer of the previously existed issue when spirv-val found a mismatch between object and ptr types in OpStore due to the incorrect aggregate types tracing), * explores untyped pointer operands of store to deduce correct pointee types, * creates an extension type to track pointee types from emit-intrinsics step and further instead of direct and naive usage of TypePointerType that led previously to crashes due to ban of creation of Value of TypePointerType type, * tracks instructions with uncomplete type information and tries to improve their type info after pass calculated types for all machine functions (it doesn't traverse a code but rather checks only those instructions which were tracked as uncompleted), * address more cases of removing unnecessary bitcasts (see, for example, changes in test/CodeGen/SPIRV/transcoding/OpGenericCastToPtr.ll where `CHECK-SPIRV-NEXT` in LIT checks show absence of unneeded bitcasts and unmangled/mangled versions have proper typing now with equivalent type info), * address more cases of well known types or relations between types within instructions (see, for example, atomic*.ll test cases and Event-related test cases for improved SPIR-V code generated by the Backend), * fix the issue of removing unneeded ptrcast instructions in pre-legalizer pass that led to creation of new assign-type instructions with the same argument as source in ptrcast and caused errors in type inference (the reproducer `complex.ll` test case is added to the PR).
128 lines
4.6 KiB
LLVM
128 lines
4.6 KiB
LLVM
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
|
|
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
|
|
|
|
; CHECK-DAG: OpName [[ADD:%.*]] "test_add"
|
|
; CHECK-DAG: OpName [[SUB:%.*]] "test_sub"
|
|
; CHECK-DAG: OpName [[MIN:%.*]] "test_min"
|
|
; CHECK-DAG: OpName [[MAX:%.*]] "test_max"
|
|
; CHECK-DAG: OpName [[UMIN:%.*]] "test_umin"
|
|
; CHECK-DAG: OpName [[UMAX:%.*]] "test_umax"
|
|
; CHECK-DAG: OpName [[AND:%.*]] "test_and"
|
|
; CHECK-DAG: OpName [[OR:%.*]] "test_or"
|
|
; CHECK-DAG: OpName [[XOR:%.*]] "test_xor"
|
|
|
|
; CHECK-DAG: [[I32Ty:%.*]] = OpTypeInt 32 0
|
|
; CHECK-DAG: [[PtrI32Ty:%.*]] = OpTypePointer Function [[I32Ty]]
|
|
;; Device scope is encoded with constant 1
|
|
; CHECK-DAG: [[SCOPE:%.*]] = OpConstant [[I32Ty]] 1
|
|
;; "sequentially consistent" maps to constant 16
|
|
; CHECK-DAG: [[SEQ:%.*]] = OpConstant [[I32Ty]] 16
|
|
|
|
; CHECK: [[ADD]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicIAdd [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_add(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw add i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[SUB]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicISub [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_sub(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw sub i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[MIN]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicSMin [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_min(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw min i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[MAX]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicSMax [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_max(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw max i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[UMIN]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicUMin [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_umin(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw umin i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[UMAX]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicUMax [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_umax(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw umax i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[AND]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicAnd [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_and(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw and i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[OR]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicOr [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_or(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw or i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|
|
|
|
; CHECK: [[XOR]] = OpFunction [[I32Ty]]
|
|
; CHECK-NEXT: [[A:%.*]] = OpFunctionParameter [[PtrI32Ty]]
|
|
; CHECK-NEXT: [[B:%.*]] = OpFunctionParameter [[I32Ty]]
|
|
; CHECK-NEXT: OpLabel
|
|
; CHECK-NEXT: [[R:%.*]] = OpAtomicXor [[I32Ty]] [[A]] [[SCOPE]] [[SEQ]] [[B]]
|
|
; CHECK-NEXT: OpReturnValue [[R]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
define i32 @test_xor(i32* %ptr, i32 %val) {
|
|
%r = atomicrmw xor i32* %ptr, i32 %val seq_cst
|
|
ret i32 %r
|
|
}
|