llvm-project/llvm/test/CodeGen/SPIRV/phi-ptrcast-dominate.ll
Vyacheslav Levytskyy 42633cf27b
[SPIR-V] Improve general validity of emitted code between passes (#119202)
This PR improves general validity of emitted code between passes due to
generation of `TargetOpcode::PHI` instead of `SPIRV::OpPhi` after
Instruction Selection, fixing generation of OpTypePointer instructions
and using of proper virtual register classes.

Using `TargetOpcode::PHI` instead of `SPIRV::OpPhi` after Instruction
Selection has a benefit to support existing optimization passes
immediately, as an alternative path to disable those passes that use
`MI.isPHI()`. This PR makes it possible thus to revert
https://github.com/llvm/llvm-project/pull/116060 actions and get back to
use the `MachineSink` pass.

This PR is a solution of the problem discussed in details in
https://github.com/llvm/llvm-project/pull/110507. It accepts an advice
from code reviewers of the PR #110507 to postpone generation of OpPhi
rather than to patch CodeGen. This solution allows to unblock
improvements wrt. expensive checks and makes it unrelated to the general
points of the discussion about OpPhi vs. G_PHI/PHI.

This PR contains numerous small patches of emitted code validity that
allows to substantially pass rate with expensive checks. Namely, the
test suite with expensive checks set ON now has only 12 fails out of 569
total test cases.

FYI @bogner
2024-12-09 21:10:09 +01:00

115 lines
3.4 KiB
LLVM

; The goal of the test is to check that newly inserted `ptrcast` internal
; intrinsic functions for PHI's operands are inserted at the correct
; positions, and don't break rules of instruction domination and PHI nodes
; grouping at top of basic block.
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; CHECK-DAG: OpName %[[#Case1:]] "case1"
; CHECK-DAG: OpName %[[#Case2:]] "case2"
; CHECK-DAG: OpName %[[#Case3:]] "case3"
%struct1 = type { i64 }
%struct2 = type { i64, i64 }
@.str.1 = private unnamed_addr addrspace(1) constant [3 x i8] c"OK\00", align 1
@.str.2 = private unnamed_addr addrspace(1) constant [6 x i8] c"WRONG\00", align 1
; CHECK: %[[#Case1]] = OpFunction
define spir_func void @case1(i1 %b1, i1 %b2, i1 %b3) {
entry:
; CHECK: OpBranchConditional %[[#]] %[[#l1:]] %[[#l2:]]
br i1 %b1, label %l1, label %l2
l1:
%str = phi ptr addrspace(1) [ @.str.1, %entry ], [ @.str.2, %l2 ], [ @.str.2, %l3 ]
br label %exit
; CHECK: %[[#l2]] = OpLabel
; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#l3:]]
l2:
br i1 %b2, label %l1, label %l3
; CHECK: %[[#l3]] = OpLabel
; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#exit:]]
l3:
br i1 %b3, label %l1, label %exit
; CHECK: %[[#l1]] = OpLabel
; CHECK-NEXT: OpPhi
; CHECK: OpBranch %[[#exit]]
; CHECK: %[[#exit]] = OpLabel
; CHECK: OpReturn
exit:
ret void
}
; CHECK: %[[#Case2]] = OpFunction
define spir_func void @case2(i1 %b1, i1 %b2, i1 %b3, ptr addrspace(1) byval(%struct1) %str1, ptr addrspace(1) byval(%struct2) %str2) {
entry:
; CHECK: OpBranchConditional %[[#]] %[[#l1:]] %[[#l2:]]
br i1 %b1, label %l1, label %l2
l1:
%str = phi ptr addrspace(1) [ %str1, %entry ], [ %str2, %l2 ], [ %str2, %l3 ]
br label %exit
; CHECK: %[[#l2]] = OpLabel
; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#l3:]]
l2:
br i1 %b2, label %l1, label %l3
; CHECK: %[[#l3]] = OpLabel
; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#exit:]]
l3:
br i1 %b3, label %l1, label %exit
; CHECK: %[[#l1]] = OpLabel
; CHECK-NEXT: OpPhi
; CHECK: OpBranch %[[#exit]]
; CHECK: %[[#exit]] = OpLabel
; CHECK: OpReturn
exit:
ret void
}
; CHECK: %[[#Case3]] = OpFunction
define spir_func void @case3(i1 %b1, i1 %b2, i1 %b3, ptr addrspace(1) byval(%struct1) %_arg_str1, ptr addrspace(1) byval(%struct2) %_arg_str2) {
; CHECK: OpBranchConditional %[[#]] %[[#l1:]] %[[#l2:]]
entry:
br i1 %b1, label %l1, label %l2
l1:
%str = phi ptr addrspace(1) [ %_arg_str1, %entry ], [ %str2, %l2 ], [ %str3, %l3 ]
br label %exit
; CHECK: %[[#l2]] = OpLabel
; CHECK: OpInBoundsPtrAccessChain
; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#l3:]]
l2:
%str2 = getelementptr inbounds %struct2, ptr addrspace(1) %_arg_str2, i32 1
br i1 %b2, label %l1, label %l3
; CHECK: %[[#l3]] = OpLabel
; CHECK: OpInBoundsPtrAccessChain
; CHECK: OpBranchConditional %[[#]] %[[#l1]] %[[#exit:]]
l3:
%str3 = getelementptr inbounds %struct2, ptr addrspace(1) %_arg_str2, i32 2
br i1 %b3, label %l1, label %exit
; CHECK: %[[#l1]] = OpLabel
; CHECK-NEXT: OpPhi
; CHECK: OpBranch %[[#exit]]
; CHECK: %[[#exit]] = OpLabel
; CHECK: OpReturn
exit:
ret void
}