Skip to content

[x64 Unix|arm64] Incorrect fastTailCall decision leads to bad codegen #11380

Closed
dotnet/coreclr
#26255

Description

@jashook

Current decision process requires nCalleeArgs >= nCallerArgs. This can be met, with a caller having a struct that needs to be copied onto the callee's virtual stack frame when the arg is > 8 bytes. If this is the case, only one slot is copied. See example below:

// 6 int registers on x64 unix and 16 byte stack
bool callee(long one, long two, long three, long four, long five, long six, long seven, long eight)
{
    // Callee will have incorrect incoming args.
    return ((one == 1) && (two == 2) && (three == 3) && (four == 4) && (five == 5) && (six == 6) && (seven == 7) && (eight == 8));
}

// 6 int registers on x64 unix and 24 byte stack
bool caller(StructSize16 one, long two, long three, long four, long five, long six, long seven, long eight)
{
    // hasStackArgs && nCalleeArgs > nCallerArgs Therefore will fastTailCall
    return callee(1, two, three, four, five, six, seven, eight); 
}

category:cq
theme:tail-call
skill-level:intermediate
cost:medium

Activity

  1. self-assigned this
    on Oct 31, 2018
  2. jashook commented on Oct 31, 2018

    @jashook
    ContributorAuthor

    /cc @dotnet/jit-contrib

  3. jashook commented on Oct 31, 2018

    @jashook
    ContributorAuthor

    Note this can be generalized to any caller that has more or equal arguments to the callee, and the callee has stack args. Only affects targets with #FEATURE_MULTIREG_ARGS

  4. changed the title [-][x64|arm64] Incorrect fastTailCall decision leads to bad codegen[/-] [+][x64 Unix|arm64] Incorrect fastTailCall decision leads to bad codegen[/+] on Oct 31, 2018
  5. CarolEidt commented on Oct 31, 2018

    @CarolEidt
    Contributor

    Only affects targets with #FEATURE_MULTIREG_ARGS

    Wouldn't this also affect, e.g. x86, which passes structs by value (and so it is the size of the args, not the number of args that needs to be considered)?

  6. jashook commented on Oct 31, 2018

    @jashook
    ContributorAuthor

    We only support fast tail calls on x64 unix|Windows and arm64 :)

  7. CarolEidt commented on Oct 31, 2018

    @CarolEidt
    Contributor

    Oh, of course. Thanks.

  8. transferred this issue fromdotnet/coreclron Jan 31, 2020
  9. added this to the Future milestone on Jan 31, 2020
  10. ghost locked as resolved and limited conversation to collaborators on Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions