runtime: JIT: follow-up on importer tail recursion block loop marking

Follow-up from #33517 (comment)

  1. Further reduce cases where we mark blocks with BBF_BACKWARD_JUMP – screen out tail recursive calls that cannot become loops.
  2. Verify we’re not creating latent bugs in already imported block codegen by setting BBF_BACKWARD_JUMP while importing.

category:cq theme:importer skill-level:intermediate cost:medium

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Here’s a prototype for a test case. Compile, disassemble, modify S.ctor to carry out the commented bit, reassemble:

using System;

public struct S
{
    public static int s_i0;

    public S(int _x, int _a)
    {
        s_i0 = 0;
        // s_i0 = i0;
        x = _x;
        a = _a;
        i0 = 3;
        i1 = 4;
        s = "a string";
    }

    public int x;
    public int a;
    public int i0;
    public int i1;
    public string s;
}

class X
{
    public static int F(int x, int a)
    {
        if (x == 0) return a;
        S s = new S(x, a);
        return G(s);
    }

    public static int G(S s) =>  F(s.x - 1, s.a * s.x);
    public static int H(int x) =>  F(x, 1);

    public static int Main()
    {
        int r = H(6);
        bool ok = S.s_i0 == 0 && r == 720;
        if (ok)
        {
            Console.WriteLine("Pass");
        }
        else
        {
            Console.WriteLine($"Fail, expected S.s_i0 == 0, got {S.s_i0}, expected r == 720, got {r}");
        }
        return ok ? 100 : -1;
    }
}

We omit initializing the temp passed to construct s in F and so we’re able to observe the residual value that is there from the prior iteration:

% set complus_tieredcompilation=0
% corerun.exe ixs.exe

Fail, expected S.s_i0 == 0, got 3, expected r == 720, got 720
ERRORLEVEL=-1

% set complus_jitminopts=1
% corerun ixs.exe

Pass
ERRORLEVEL=100