Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Invalid lowering for SELECT over mixed neg/not operands #87384

Closed
jakobbotsch opened this issue Jun 11, 2023 · 2 comments · Fixed by #87674
Closed

JIT: Invalid lowering for SELECT over mixed neg/not operands #87384

jakobbotsch opened this issue Jun 11, 2023 · 2 comments · Fixed by #87674
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented Jun 11, 2023

// Generated by Fuzzlyn v1.5 on 2023-06-11 16:59:59
// Run on Arm64 MacOS
// Seed: 16920611288177866312
// Reduced from 53.2 KiB to 0.4 KiB in 00:00:19
// Debug: Outputs 4294967294
// Release: Outputs 4294967295
public class Program
{
    public static int s_2;
    public static void Main()
    {
        byte vr2 = (byte)M5(1);
    }

    public static long M5(uint arg0)
    {
        if (arg0 <= s_2)
        {
            arg0 = (uint)(-arg0);
        }
        else
        {
            arg0 = ~arg0;
        }

        System.Console.WriteLine(arg0);
        return 0;
    }
}

Looks introduced by #84926. We drop the NOT but then convert to SELECT_NEGCC:

Converted to SELECTCC:
N001 (  1,  1) [000000] -----------                    t0 =    LCL_VAR   int    V00 arg0         u:1 $80
N002 (  3, 12) [000001] H----------                    t1 =    CNS_INT(h) long   0x7ff8b99ecca4 static Fseq[s_2] $100
                                                            ┌──▌  t1     long   
N003 (  6, 14) [000002] n---G------                    t2 =   IND       int    <l:$140, c:$81>
N005 (  1,  1) [000005] -----------                    t5 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
                                                            ┌──▌  t5     int    
N006 (  2,  2) [000006] -----------                    t6 =   NOT       int    $82
N007 (  1,  1) [000013] -----------                   t13 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
                                                            ┌──▌  t13    int    
N008 (  2,  2) [000014] -----------                   t14 =   NEG       int    $83
                                                            ┌──▌  t0     int    
                                                            ├──▌  t2     int    
N004 (  8, 16) [000003] ----G--N---                           CMP       void  
                                                            ┌──▌  t6     int    
                                                            ├──▌  t14    int    
N009 ( 13, 21) [000020] ----G------                   t20 =   SELECTCC  int    cond=SGT

Converted to: SELECT_NEGCC
N001 (  1,  1) [000000] -----------                    t0 =    LCL_VAR   int    V00 arg0         u:1 $80
N002 (  3, 12) [000001] H----------                    t1 =    CNS_INT(h) long   0x7ff8b99ecca4 static Fseq[s_2] $100
                                                            ┌──▌  t1     long   
N003 (  6, 14) [000002] n---G------                    t2 =   IND       int    <l:$140, c:$81>
N005 (  1,  1) [000005] -----------                    t5 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
N007 (  1,  1) [000013] -----------                   t13 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
                                                            ┌──▌  t13    int    
N008 (  2,  2) [000014] -----------                   t14 =   NEG       int    $83
                                                            ┌──▌  t0     int    
                                                            ├──▌  t2     int    
N004 (  8, 16) [000003] ----G--N---                           CMP       void  
                                                            ┌──▌  t14    int    
                                                            ├──▌  t5     int    
N009 ( 13, 21) [000020] ----G------                   t20 =   SELECT_NEGCC int    cond=SLE

cc @SwapnilGaikwad

@jakobbotsch jakobbotsch added this to the 8.0.0 milestone Jun 11, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 11, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 11, 2023
@ghost
Copy link

ghost commented Jun 11, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details
// Generated by Fuzzlyn v1.5 on 2023-06-11 16:59:59
// Run on Arm64 MacOS
// Seed: 16920611288177866312
// Reduced from 53.2 KiB to 0.4 KiB in 00:00:19
// Debug: Outputs 4294967294
// Release: Outputs 4294967295
public class Program
{
    public static int s_2;
    public static void Main()
    {
        byte vr2 = (byte)M5(1);
    }

    public static long M5(uint arg0)
    {
        if (arg0 <= s_2)
        {
            arg0 = (uint)(-arg0);
        }
        else
        {
            arg0 = ~arg0;
        }

        System.Console.WriteLine(arg0);
        return 0;
    }
}

Looks introduced by #84926. We drop the NOT:

Converted to SELECTCC:
N001 (  1,  1) [000000] -----------                    t0 =    LCL_VAR   int    V00 arg0         u:1 $80
N002 (  3, 12) [000001] H----------                    t1 =    CNS_INT(h) long   0x7ff8b99ecca4 static Fseq[s_2] $100
                                                            ┌──▌  t1     long   
N003 (  6, 14) [000002] n---G------                    t2 =   IND       int    <l:$140, c:$81>
N005 (  1,  1) [000005] -----------                    t5 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
                                                            ┌──▌  t5     int    
N006 (  2,  2) [000006] -----------                    t6 =   NOT       int    $82
N007 (  1,  1) [000013] -----------                   t13 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
                                                            ┌──▌  t13    int    
N008 (  2,  2) [000014] -----------                   t14 =   NEG       int    $83
                                                            ┌──▌  t0     int    
                                                            ├──▌  t2     int    
N004 (  8, 16) [000003] ----G--N---                           CMP       void  
                                                            ┌──▌  t6     int    
                                                            ├──▌  t14    int    
N009 ( 13, 21) [000020] ----G------                   t20 =   SELECTCC  int    cond=SGT

Converted to: SELECT_NEGCC
N001 (  1,  1) [000000] -----------                    t0 =    LCL_VAR   int    V00 arg0         u:1 $80
N002 (  3, 12) [000001] H----------                    t1 =    CNS_INT(h) long   0x7ff8b99ecca4 static Fseq[s_2] $100
                                                            ┌──▌  t1     long   
N003 (  6, 14) [000002] n---G------                    t2 =   IND       int    <l:$140, c:$81>
N005 (  1,  1) [000005] -----------                    t5 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
N007 (  1,  1) [000013] -----------                   t13 =    LCL_VAR   int    V00 arg0         u:1 (last use) $80
                                                            ┌──▌  t13    int    
N008 (  2,  2) [000014] -----------                   t14 =   NEG       int    $83
                                                            ┌──▌  t0     int    
                                                            ├──▌  t2     int    
N004 (  8, 16) [000003] ----G--N---                           CMP       void  
                                                            ┌──▌  t14    int    
                                                            ├──▌  t5     int    
N009 ( 13, 21) [000020] ----G------                   t20 =   SELECT_NEGCC int    cond=SLE

cc @SwapnilGaikwad

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: 8.0.0

@jakobbotsch jakobbotsch changed the title JIT: Invalid codegen for SELECT over mixed neg/not operands JIT: Invalid lowering for SELECT over mixed neg/not operands Jun 11, 2023
@SwapnilGaikwad
Copy link
Contributor

Thanks @jakobbotsch . I'll fix this 👍 .

@jakobbotsch jakobbotsch removed the untriaged New issue has not been triaged by the area owner label Jun 15, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 16, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 16, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants