This PR continues https://github.com/llvm/llvm-project/pull/101732 changes in virtual register processing aimed to improve correctness of emitted MIR between passes from the perspective of MachineVerifier. Namely, the following changes are introduced: * register classes (lib/Target/SPIRV/SPIRVRegisterInfo.td) and instruction patterns (lib/Target/SPIRV/SPIRVInstrInfo.td) are corrected and simplified (by removing unnecessary sophisticated options) -- e.g., this PR gets rid of duplicating 32/64 bits patterns, removes ANYID register class and simplifies definition of the rest of register classes, * hardcoded LLT scalar types in passes before instruction selection are corrected -- the goal is to have correct bit width before instruction selection, and use 64 bits registers for pattern matching in the instruction selection pass; 32-bit registers remain where they are described in such terms by SPIR-V specification (like, for example, creation of virtual registers for scope/mem semantics operands), * rework virtual register type/class assignment for calls/builtins lowering, * a series of minor changes to fix validity of emitted code between passes: - ensure that that bitcast changes the type, - fix the pattern for instruction selection for OpExtInst, - simplify inline asm operands usage, - account for arbitrary integer sizes / update legalizer rules; * add '-verify-machineinstrs' to existed test cases. See also https://github.com/llvm/llvm-project/issues/88129 that this PR may resolve. This PR fixes a great number of issues reported by MachineVerifier and, as a result, reduces a number of failed test cases for the mode with expensive checks set on from ~200 to ~57.
128 lines
4.7 KiB
LLVM
128 lines
4.7 KiB
LLVM
; RUN: llc -verify-machineinstrs -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
|
|
}
|