summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Regression/JitBlue/GitHub_8231/GitHub_8231.cs
blob: 4d2ec7628a3c37bd09daa6c634b2dc892128c5a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Numerics;
using System.Runtime.CompilerServices;

namespace N
{
    public static class C
    {
        // This is a regression test for a failure in loop unrolling when
        // the unrolled loop contains a switch statement.
        [MethodImpl(MethodImplOptions.NoInlining)]
        static int Test()
        {
            int s = 0;

            // Loop to some Vector<T>.Count to trigger unrolling.
            for (int i = 0; i < Vector<int>.Count; i++)
            {
                // Loop contains switch; the bug was that the clones
                // of the switch were all sharing its BBswtDesc instead
                // of getting their own, so updates to their jump targets
                // were incorrectly shared.
                switch (i)
                {
                    case 1: s += 4; break;
                    case 2: s += 2; break;
                    case 3: s += i; break;
                }
            }

            return s;
        }

        public static int Main(string[] args)
        {
            int result = Test();

            // Expected result is a function of Vector<int>.Count.
            int expected;
            switch(Vector<int>.Count)
            {
                case 1:
                    expected = 4;
                    break;
                case 2:
                    expected = 6;
                    break;
                default:
                    expected = 9;
                    break;
            }

            // Return 100 on success (result == expected), other
            // values on failure.
            return 100 + result - expected;
        }
   }
}