Skip to content

JIT: Audit GetAllSuccs/GetEHSuccs when filters are involved #86538

Closed

Description

@jakobbotsch

Liveness has special logic to take into account that control may flow from filters to practically any enclosed or enclosing handler. However, GetAllSuccs does not seem to have the same handling.

For:

public class Program
{
    public static bool IsExpectedException(Exception e)
    {
        Console.WriteLine("In filter");
        return false;
    }
    
    public static int Main()
    {
        int result = 0;
        // BB01

        try
        {
            // BB02
            try
            {
                // BB03
                try
                {
                    // BB04
                    throw new Exception();
                }
                finally
                {
                    // BB05
                    Console.WriteLine("In finally");
                }
            }
            catch (Exception e1 /* BB06, BB07 */) when (/* BB08 */ IsExpectedException(e1) /* BB09 */)
            {
                // BB10
                Console.WriteLine("In catch 1");
            }
            // BB11
        }
        catch (Exception e2)
        {
            // BB12
            Console.WriteLine("In catch 2");
            result = 100;
        }

        // BB13
        return result;
    }
}

GetAllSuccs returns the following:

BB01
  Succ BB02
  Succ BB12
BB02
  Succ BB03
  Succ BB12
  Succ BB06
BB03
  Succ BB04
  Succ BB06
  Succ BB12
  Succ BB05
BB04
  Succ BB05
  Succ BB06
  Succ BB12
BB05
  Succ BB06
  Succ BB12
BB06
  Succ BB07
  Succ BB08
  Succ BB12
BB07
  Succ BB09
  Succ BB12
BB08
  Succ BB09
  Succ BB12
BB09
  Succ BB10
  Succ BB12
BB10
  Succ BB11
  Succ BB12
BB11
  Succ BB13
  Succ BB12
BB12
  Succ BB13
BB13

In particular I would expect the successors to indicate that the finally block BB05 is reachable from the filter blocks BB06 to BB09.

Activity

  1. ghost added
    untriaged
    on May 20, 2023
  2. ghost added
    area-CodeGen-coreclr
    on May 20, 2023
  3. jakobbotsch commented on May 20, 2023

    @jakobbotsch
    MemberAuthor

    cc @dotnet/jit-contrib. @AndyAyersMS you may be the best person to take a look at this.

  4. added this to the 8.0.0 milestone on May 22, 2023
  5. ghost removed
    untriaged
    on May 22, 2023
  6. jakobbotsch commented on May 23, 2023

    @jakobbotsch
    MemberAuthor

    Example bad codegen:

    // Prints 1235 in debug, 1234 in release
    using System;
    
    public class Program
    {
        public static void Main()
        {
            int value = 1234;
            try
            {
                try
                {
                    throw new Exception();
                }
                finally
                {
                    Console.WriteLine(value);
                }
            }
            catch when (value++ == 1234)
            {
            }
        }
    }
  7. jakobbotsch commented on Jun 9, 2023

    @jakobbotsch
    MemberAuthor

    Fixing all-succ visiting is not that hard, and fixing BlockPredsWithEH also shouldn't be, but one thing I have noticed is that BlockPredsWithEH caches the "all-preds" lists. The cache never looks to be cleared and it is used by SSA, VN and CSE. We have lots of flowgraph modifying phases between CSE and and SSA, so these cached predecessors are likely out of date when we use them, which seems scary.

    BlockPredsWithEH also looks pretty inefficient, so I think I will try eagerly computing the map of all-preds (using VisitAllSuccs) before the phases that need them and see what the impact of this is.

  8. added
    Priority:3
    on Jun 20, 2023
  9. ghost added
    in-pr
    on Jul 20, 2023
  10. added a commit that references this issue on Jul 21, 2023
    18024f4
  11. ghost removed
    in-pr
    on Jul 21, 2023
  12. ghost locked as resolved and limited conversation to collaborators on Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Priority:3area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions