Skip to content

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

@jakobbotsch

Description

@jakobbotsch
// 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

Metadata

Metadata

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions