Files
clang-p2996/llvm/test/CodeGen/SPIRV/structurizer/loop-continue-split.ll
Nathan Gauër cba70550cc [SPIR-V] Fix BB ordering & register lifetime (#111026)
The "topological" sorting was behaving incorrectly in some cases: 
the exit of a loop could have a lower rank than a node in the loop.
This causes issues when structurizing some patterns, and also codegen
issues as we could generate BBs in the incorrect order in regard to the
SPIR-V spec.

Fixing this ordering alone broke other parts of the structurizer, which
by luck worked. Had to fix those.

Added more test cases, especially to test basic patterns.

I also needed to tweak/disable some tests for 2 reasons:
 - SPIR-V now required reg2mem/mem2reg to run. Meaning dead stores
   are optimized away. Some tests require tweaks to avoid having the
   whole function removed.
 - Mem2Reg will generate variable & load/stores. This generates
   G_BITCAST in several cases. And there is currently something wrong
   we do with G_BITCAST which causes MIR verifier to complain.
   Until this is resolved, I disabled -verify-machineinstrs flag on
   those tests.

---------

Signed-off-by: Nathan Gauër <brioche@google.com>
2024-10-30 14:57:32 +01:00

105 lines
4.0 KiB
LLVM

; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val %}
; RUN: llc -mtriple=spirv-unknown-vulkan-compute -O0 %s -o - | FileCheck %s
; The goal of this test is to voluntarily create 2 overlapping convergence
; structures: the loop, and the inner condition.
; Here, the condition header also branches to 2 internal nodes, which are not
; directly a merge/exits.
; This will require a proper header-split.
; In addition, splitting the header makes the continue the merge of the inner
; condition, so we need to properly split the continue block to create a
; valid inner merge, in the correct order.
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1"
target triple = "spirv-unknown-vulkan1.3-compute"
; CHECK-DAG: OpName %[[#switch_0:]] "reg1"
; CHECK-DAG: OpName %[[#variable:]] "var"
; CHECK-DAG: %[[#int_0:]] = OpConstant %[[#]] 0
; CHECK-DAG: %[[#int_1:]] = OpConstant %[[#]] 1
; CHECK-DAG: %[[#int_2:]] = OpConstant %[[#]] 2
; CHECK-DAG: %[[#int_3:]] = OpConstant %[[#]] 3
; CHECK-DAG: %[[#int_4:]] = OpConstant %[[#]] 4
define internal spir_func void @main() #1 {
; CHECK: %[[#entry:]] = OpLabel
; CHECK: %[[#switch_0]] = OpVariable %[[#]] Function
; CHECK: %[[#variable]] = OpVariable %[[#]] Function
; CHECK: OpBranch %[[#header:]]
entry:
%0 = call token @llvm.experimental.convergence.entry()
%var = alloca i32, align 4
br label %header
; CHECK: %[[#header]] = OpLabel
; CHECK: OpLoopMerge %[[#merge:]] %[[#continue:]] None
; CHECK: OpBranch %[[#split_header:]]
; CHECK: %[[#split_header]] = OpLabel
; CHECK: OpSelectionMerge %[[#inner_merge:]] None
; CHECK: OpBranchConditional %[[#]] %[[#left:]] %[[#right:]]
header:
%2 = call token @llvm.experimental.convergence.loop() [ "convergencectrl"(token %0) ]
br i1 true, label %left, label %right
; CHECK: %[[#left]] = OpLabel
; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_0]]
; CHECK-DAG: OpStore %[[#variable]] %[[#int_1]]
; CHECK: OpBranchConditional %[[#]] %[[#inner_merge]] %[[#left_next:]]
left:
store i32 1, ptr %var
br i1 true, label %merge, label %left_next
; CHECK: %[[#right]] = OpLabel
; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_0]]
; CHECK-DAG: OpStore %[[#variable]] %[[#int_2]]
; CHECK: OpBranchConditional %[[#]] %[[#inner_merge]] %[[#right_next:]]
right:
store i32 2, ptr %var
br i1 true, label %merge, label %right_next
; CHECK: %[[#left_next]] = OpLabel
; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_1]]
; CHECK-DAG: OpStore %[[#variable]] %[[#int_3]]
; CHECK: OpBranch %[[#inner_merge]]
left_next:
store i32 3, ptr %var
br label %continue
; CHECK: %[[#right_next]] = OpLabel
; CHECK-DAG: OpStore %[[#switch_0]] %[[#int_1]]
; CHECK-DAG: OpStore %[[#variable]] %[[#int_4]]
; CHECK: OpBranch %[[#inner_merge]]
right_next:
store i32 4, ptr %var
br label %continue
; CHECK: %[[#inner_merge]] = OpLabel
; CHECK: %[[#tmp:]] = OpLoad %[[#]] %[[#switch_0]]
; CHECK: %[[#cond:]] = OpIEqual %[[#]] %[[#int_0]] %[[#tmp]]
; CHECK: OpBranchConditional %[[#cond]] %[[#merge]] %[[#continue]]
; CHECK: %[[#continue]] = OpLabel
; CHECK: OpBranch %[[#header]]
continue:
br label %header
; CHECK: %[[#merge]] = OpLabel
; CHECK: OpReturn
merge:
ret void
}
declare token @llvm.experimental.convergence.entry() #0
declare token @llvm.experimental.convergence.loop() #0
attributes #0 = { convergent nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { convergent noinline norecurse nounwind optnone "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
!llvm.module.flags = !{!0, !1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 4, !"dx.disable_optimizations", i32 1}