From d2cd747292a9dc95b4fd93ccfb1b52cd35a79ce2 Mon Sep 17 00:00:00 2001 From: Marcel Koester Date: Mon, 4 Sep 2023 11:47:39 +0200 Subject: [PATCH] Added new test case for improved IfConversion transformation. --- Src/ILGPU.Tests/BasicJumps.cs | 57 +++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/Src/ILGPU.Tests/BasicJumps.cs b/Src/ILGPU.Tests/BasicJumps.cs index bbbd6da86b..1facdf0ba9 100644 --- a/Src/ILGPU.Tests/BasicJumps.cs +++ b/Src/ILGPU.Tests/BasicJumps.cs @@ -1,6 +1,6 @@ // --------------------------------------------------------------------------------------- // ILGPU -// Copyright (c) 2021 ILGPU Project +// Copyright (c) 2021-2023 ILGPU Project // www.ilgpu.net // // File: BasicJumps.cs @@ -16,6 +16,7 @@ using Xunit.Abstractions; #pragma warning disable CS0162 +#pragma warning disable CS0164 namespace ILGPU.Tests { @@ -164,25 +165,63 @@ internal static void BasicNestedLoopJumpKernel( } [Theory] - [InlineData(32, 0, 67)] - [InlineData(32, 2, 25)] - [InlineData(1024, 0, 67)] - [InlineData(1024, 2, 25)] + [InlineData(0, 67)] + [InlineData(2, 25)] [KernelMethod(nameof(BasicNestedLoopJumpKernel))] - public void BasicNestedLoopJump(int length, int c, int res) + public void BasicNestedLoopJump(int c, int res) { - using var buffer = Accelerator.Allocate1D(length); - using var source = Accelerator.Allocate1D(64); + const int Length = 64; + using var buffer = Accelerator.Allocate1D(Length); + using var source = Accelerator.Allocate1D(Length); var sourceData = Enumerable.Range(0, (int)source.Length).ToArray(); sourceData[57] = 23; source.CopyFromCPU(Accelerator.DefaultStream, sourceData); Execute(buffer.Length, buffer.View, source.View, c); - var expected = Enumerable.Repeat(res, length).ToArray(); + var expected = Enumerable.Repeat(res, Length).ToArray(); + Verify(buffer.View, expected); + } + + private static void BasicNestedLoopJumpKernel2( + Index1D index, + ArrayView1D target, + ArrayView1D source) + { + int k = 0; + entry: + for (int i = 0; i < source.Length; ++i) + { + goto exit; + } + + target[index] = 42; + return; + + nested: + k = 43; + + exit: + if (k++ < 1) + goto entry; + target[index] = 23 + k; + } + + [Fact] + [KernelMethod(nameof(BasicNestedLoopJumpKernel2))] + public void BasicNestedLoopJump2() + { + const int Length = 32; + using var buffer = Accelerator.Allocate1D(Length); + using var source = Accelerator.Allocate1D(Length); + + Execute(buffer.Length, buffer.View, source.View); + + var expected = Enumerable.Repeat(25, Length).ToArray(); Verify(buffer.View, expected); } } } +#pragma warning restore CS0164 #pragma warning restore CS0162