[test]: Add some test cases for for-loops

Bug: tint:952
Change-Id: I156e29a74ce3942a39f25dc5bfb3d5467e206fce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57201
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-07-08 10:00:17 +00:00 committed by Ben Clayton
parent 1e153613eb
commit 2ba8315b02
35 changed files with 624 additions and 0 deletions

View File

@ -0,0 +1,7 @@
fn some_loop_body() {}
fn f() {
for (var i : i32 = 0; i < 5; i = i + 1) {
some_loop_body();
}
}

View File

@ -0,0 +1,16 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void some_loop_body() {
}
void f() {
{
int i = 0;
for(; !(!((i < 5))); i = (i + 1)) {
some_loop_body();
}
}
}

View File

@ -0,0 +1,21 @@
#include <metal_stdlib>
using namespace metal;
void some_loop_body() {
}
void f() {
{
int i = 0;
while (true) {
if (!((i < 5))) {
break;
}
some_loop_body();
{
i = (i + 1);
}
}
}
}

View File

@ -0,0 +1,57 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 29
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %some_loop_body "some_loop_body"
OpName %f "f"
OpName %i "i"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Function_int = OpTypePointer Function %int
%13 = OpConstantNull %int
%int_5 = OpConstant %int 5
%bool = OpTypeBool
%int_1 = OpConstant %int 1
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%some_loop_body = OpFunction %void None %1
%6 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%8 = OpLabel
%i = OpVariable %_ptr_Function_int Function %13
OpStore %i %int_0
OpBranch %14
%14 = OpLabel
OpLoopMerge %15 %16 None
OpBranch %17
%17 = OpLabel
%19 = OpLoad %int %i
%21 = OpSLessThan %bool %19 %int_5
%18 = OpLogicalNot %bool %21
OpSelectionMerge %23 None
OpBranchConditional %18 %24 %23
%24 = OpLabel
OpBranch %15
%23 = OpLabel
%25 = OpFunctionCall %void %some_loop_body
OpBranch %16
%16 = OpLabel
%26 = OpLoad %int %i
%28 = OpIAdd %int %26 %int_1
OpStore %i %28
OpBranch %14
%15 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,18 @@
fn some_loop_body() {
}
fn f() {
{
var i : i32 = 0;
loop {
if (!((i < 5))) {
break;
}
some_loop_body();
continuing {
i = (i + 1);
}
}
}
}

View File

@ -0,0 +1,9 @@
fn some_loop_body() {}
fn f() {
var j : i32;
for (var i : i32 = 0; i < 5 && j < 10; i = i + 1) {
some_loop_body();
j = i * 30;
}
}

View File

@ -0,0 +1,24 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void some_loop_body() {
}
void f() {
int j = 0;
{
int i = 0;
while (true) {
bool tint_tmp = (i < 5);
if (tint_tmp) {
tint_tmp = (j < 10);
}
if (!(!(!((tint_tmp))))) { break; }
some_loop_body();
j = (i * 30);
i = (i + 1);
}
}
}

View File

@ -0,0 +1,23 @@
#include <metal_stdlib>
using namespace metal;
void some_loop_body() {
}
void f() {
int j = 0;
{
int i = 0;
while (true) {
if (!(((i < 5) && (j < 10)))) {
break;
}
some_loop_body();
j = (i * 30);
{
i = (i + 1);
}
}
}
}

View File

@ -0,0 +1,72 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 39
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %some_loop_body "some_loop_body"
OpName %f "f"
OpName %j "j"
OpName %i "i"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%12 = OpConstantNull %int
%int_0 = OpConstant %int 0
%int_5 = OpConstant %int 5
%bool = OpTypeBool
%int_10 = OpConstant %int 10
%int_30 = OpConstant %int 30
%int_1 = OpConstant %int 1
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%some_loop_body = OpFunction %void None %1
%6 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%8 = OpLabel
%j = OpVariable %_ptr_Function_int Function %12
%i = OpVariable %_ptr_Function_int Function %12
OpStore %i %int_0
OpBranch %15
%15 = OpLabel
OpLoopMerge %16 %17 None
OpBranch %18
%18 = OpLabel
%20 = OpLoad %int %i
%22 = OpSLessThan %bool %20 %int_5
OpSelectionMerge %24 None
OpBranchConditional %22 %25 %24
%25 = OpLabel
%26 = OpLoad %int %j
%28 = OpSLessThan %bool %26 %int_10
OpBranch %24
%24 = OpLabel
%29 = OpPhi %bool %22 %18 %28 %25
%19 = OpLogicalNot %bool %29
OpSelectionMerge %30 None
OpBranchConditional %19 %31 %30
%31 = OpLabel
OpBranch %16
%30 = OpLabel
%32 = OpFunctionCall %void %some_loop_body
%33 = OpLoad %int %i
%35 = OpIMul %int %33 %int_30
OpStore %j %35
OpBranch %17
%17 = OpLabel
%36 = OpLoad %int %i
%38 = OpIAdd %int %36 %int_1
OpStore %i %38
OpBranch %15
%16 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,20 @@
fn some_loop_body() {
}
fn f() {
var j : i32;
{
var i : i32 = 0;
loop {
if (!(((i < 5) && (j < 10)))) {
break;
}
some_loop_body();
j = (i * 30);
continuing {
i = (i + 1);
}
}
}
}

View File

@ -0,0 +1,5 @@
fn f() {
var i : i32;
for (;i < 4;) {
}
}

View File

@ -0,0 +1,10 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
int i = 0;
for(; !(!((i < 4))); ) {
}
}

View File

@ -0,0 +1,12 @@
#include <metal_stdlib>
using namespace metal;
void f() {
int i = 0;
while (true) {
if (!((i < 4))) {
break;
}
}
}

View File

@ -0,0 +1,45 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 22
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %i "i"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%10 = OpConstantNull %int
%int_4 = OpConstant %int 4
%bool = OpTypeBool
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%i = OpVariable %_ptr_Function_int Function %10
OpBranch %11
%11 = OpLabel
OpLoopMerge %12 %13 None
OpBranch %14
%14 = OpLabel
%16 = OpLoad %int %i
%18 = OpSLessThan %bool %16 %int_4
%15 = OpLogicalNot %bool %18
OpSelectionMerge %20 None
OpBranchConditional %15 %21 %20
%21 = OpLabel
OpBranch %12
%20 = OpLabel
OpBranch %13
%13 = OpLabel
OpBranch %11
%12 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,8 @@
fn f() {
var i : i32;
loop {
if (!((i < 4))) {
break;
}
}
}

View File

@ -0,0 +1,4 @@
fn f() {
var i : i32;
for (;;i = i + 1) {}
}

View File

@ -0,0 +1,13 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
int i = 0;
while (true) {
{
i = (i + 1);
}
}
}

View File

@ -0,0 +1,12 @@
#include <metal_stdlib>
using namespace metal;
void f() {
int i = 0;
while (true) {
{
i = (i + 1);
}
}
}

View File

@ -0,0 +1,39 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %i "i"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%_ptr_Function_int = OpTypePointer Function %int
%10 = OpConstantNull %int
%int_1 = OpConstant %int 1
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%i = OpVariable %_ptr_Function_int Function %10
OpBranch %11
%11 = OpLabel
OpLoopMerge %12 %13 None
OpBranch %14
%14 = OpLabel
OpBranch %13
%13 = OpLabel
%15 = OpLoad %int %i
%17 = OpIAdd %int %15 %int_1
OpStore %i %17
OpBranch %11
%12 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,9 @@
fn f() {
var i : i32;
loop {
continuing {
i = (i + 1);
}
}
}

View File

@ -0,0 +1,3 @@
fn f() {
for (;;) {}
}

View File

@ -0,0 +1,9 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
while (true) {
}
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void f() {
while (true) {
}
}

View File

@ -0,0 +1,30 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 11
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
OpBranch %7
%7 = OpLabel
OpLoopMerge %8 %9 None
OpBranch %10
%10 = OpLabel
OpBranch %9
%9 = OpLabel
OpBranch %7
%8 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,4 @@
fn f() {
loop {
}
}

View File

@ -0,0 +1,3 @@
fn f() {
for (var i : i32 = 0;;) {}
}

View File

@ -0,0 +1,12 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
{
int i = 0;
while (true) {
}
}
}

View File

@ -0,0 +1,11 @@
#include <metal_stdlib>
using namespace metal;
void f() {
{
int i = 0;
while (true) {
}
}
}

View File

@ -0,0 +1,37 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 16
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %i "i"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Function_int = OpTypePointer Function %int
%11 = OpConstantNull %int
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%i = OpVariable %_ptr_Function_int Function %11
OpStore %i %int_0
OpBranch %12
%12 = OpLabel
OpLoopMerge %13 %14 None
OpBranch %15
%15 = OpLabel
OpBranch %14
%14 = OpLabel
OpBranch %12
%13 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,7 @@
fn f() {
{
var i : i32 = 0;
loop {
}
}
}

View File

@ -0,0 +1,4 @@
fn f() {
for (var must_not_collide : i32 = 0;;) {}
var must_not_collide : i32;
}

View File

@ -0,0 +1,13 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
void f() {
{
int must_not_collide = 0;
while (true) {
}
}
int must_not_collide = 0;
}

View File

@ -0,0 +1,12 @@
#include <metal_stdlib>
using namespace metal;
void f() {
{
int must_not_collide = 0;
while (true) {
}
}
int must_not_collide = 0;
}

View File

@ -0,0 +1,39 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 17
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %unused_entry_point "unused_entry_point"
OpName %f "f"
OpName %must_not_collide "must_not_collide"
OpName %must_not_collide_0 "must_not_collide"
%void = OpTypeVoid
%1 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Function_int = OpTypePointer Function %int
%11 = OpConstantNull %int
%unused_entry_point = OpFunction %void None %1
%4 = OpLabel
OpReturn
OpFunctionEnd
%f = OpFunction %void None %1
%6 = OpLabel
%must_not_collide = OpVariable %_ptr_Function_int Function %11
%must_not_collide_0 = OpVariable %_ptr_Function_int Function %11
OpStore %must_not_collide %int_0
OpBranch %12
%12 = OpLabel
OpLoopMerge %13 %14 None
OpBranch %15
%15 = OpLabel
OpBranch %14
%14 = OpLabel
OpBranch %12
%13 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,8 @@
fn f() {
{
var must_not_collide : i32 = 0;
loop {
}
}
var must_not_collide : i32;
}