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.
92 lines
2.7 KiB
LLVM
92 lines
2.7 KiB
LLVM
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
|
|
|
|
; CHECK-DAG: OpName [[SCALAR_ADD:%.+]] "scalar_add"
|
|
; CHECK-DAG: OpName [[SCALAR_SUB:%.+]] "scalar_sub"
|
|
; CHECK-DAG: OpName [[SCALAR_MUL:%.+]] "scalar_mul"
|
|
; CHECK-DAG: OpName [[SCALAR_UDIV:%.+]] "scalar_udiv"
|
|
; CHECK-DAG: OpName [[SCALAR_SDIV:%.+]] "scalar_sdiv"
|
|
;; TODO: add tests for urem + srem
|
|
;; TODO: add test for OpSNegate
|
|
|
|
; CHECK-NOT: DAG-FENCE
|
|
|
|
; CHECK-DAG: [[SCALAR:%.+]] = OpTypeInt 32
|
|
; CHECK-DAG: [[SCALAR_FN:%.+]] = OpTypeFunction [[SCALAR]] [[SCALAR]] [[SCALAR]]
|
|
|
|
; CHECK-NOT: DAG-FENCE
|
|
|
|
|
|
;; Test add on scalar:
|
|
define i32 @scalar_add(i32 %a, i32 %b) {
|
|
%c = add i32 %a, %b
|
|
ret i32 %c
|
|
}
|
|
|
|
; CHECK: [[SCALAR_ADD]] = OpFunction [[SCALAR]] None [[SCALAR_FN]]
|
|
; CHECK-NEXT: [[A:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK-NEXT: [[B:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK: OpLabel
|
|
; CHECK: [[C:%.+]] = OpIAdd [[SCALAR]] [[A]] [[B]]
|
|
; CHECK: OpReturnValue [[C]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
|
|
|
|
;; Test sub on scalar:
|
|
define i32 @scalar_sub(i32 %a, i32 %b) {
|
|
%c = sub i32 %a, %b
|
|
ret i32 %c
|
|
}
|
|
|
|
; CHECK: [[SCALAR_SUB]] = OpFunction [[SCALAR]] None [[SCALAR_FN]]
|
|
; CHECK-NEXT: [[A:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK-NEXT: [[B:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK: OpLabel
|
|
; CHECK: [[C:%.+]] = OpISub [[SCALAR]] [[A]] [[B]]
|
|
; CHECK: OpReturnValue [[C]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
|
|
|
|
;; Test mul on scalar:
|
|
define i32 @scalar_mul(i32 %a, i32 %b) {
|
|
%c = mul i32 %a, %b
|
|
ret i32 %c
|
|
}
|
|
|
|
; CHECK: [[SCALAR_MUL]] = OpFunction [[SCALAR]] None [[SCALAR_FN]]
|
|
; CHECK-NEXT: [[A:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK-NEXT: [[B:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK: OpLabel
|
|
; CHECK: [[C:%.+]] = OpIMul [[SCALAR]] [[A]] [[B]]
|
|
; CHECK: OpReturnValue [[C]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
|
|
|
|
;; Test udiv on scalar:
|
|
define i32 @scalar_udiv(i32 %a, i32 %b) {
|
|
%c = udiv i32 %a, %b
|
|
ret i32 %c
|
|
}
|
|
|
|
; CHECK: [[SCALAR_UDIV]] = OpFunction [[SCALAR]] None [[SCALAR_FN]]
|
|
; CHECK-NEXT: [[A:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK-NEXT: [[B:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK: OpLabel
|
|
; CHECK: [[C:%.+]] = OpUDiv [[SCALAR]] [[A]] [[B]]
|
|
; CHECK: OpReturnValue [[C]]
|
|
; CHECK-NEXT: OpFunctionEnd
|
|
|
|
|
|
;; Test sdiv on scalar:
|
|
define i32 @scalar_sdiv(i32 %a, i32 %b) {
|
|
%c = sdiv i32 %a, %b
|
|
ret i32 %c
|
|
}
|
|
|
|
; CHECK: [[SCALAR_SDIV]] = OpFunction [[SCALAR]] None [[SCALAR_FN]]
|
|
; CHECK-NEXT: [[A:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK-NEXT: [[B:%.+]] = OpFunctionParameter [[SCALAR]]
|
|
; CHECK: OpLabel
|
|
; CHECK: [[C:%.+]] = OpSDiv [[SCALAR]] [[A]] [[B]]
|
|
; CHECK: OpReturnValue [[C]]
|
|
; CHECK-NEXT: OpFunctionEnd
|