Revert "[mono] Fix a few corner case overflow operations (#57407)" (#57501)
authorSam Patel <46026722+SamMonoRT@users.noreply.github.com>
Mon, 16 Aug 2021 23:18:10 +0000 (19:18 -0400)
committerGitHub <noreply@github.com>
Mon, 16 Aug 2021 23:18:10 +0000 (23:18 +0000)
This reverts commit e81efc832ae56978ae26ff0dbf17cb5622cee735.

src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/local-propagation.c
src/mono/mono/mini/mini-arm.c
src/mono/mono/mini/mini-mips.c
src/mono/mono/mini/mini-ppc.c
src/tests/issues.targets

index f33fb62..6db2f62 100644 (file)
@@ -5808,7 +5808,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_I4_R8) {
                        double val = LOCAL_VAR (ip [2], double);
-                       if (mono_isnan (val) || mono_trunc (val) != (gint32)val)
+                       if (val < G_MININT32 || val > G_MAXINT32 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (gint32)val;
                        ip += 3;
@@ -5840,7 +5840,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_U4_R8) {
                        double val = LOCAL_VAR (ip [2], double);
-                       if (mono_isnan (val) || mono_trunc (val) != (guint32)val)
+                       if (val < 0 || val > G_MAXUINT32 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (guint32) val;
                        ip += 3;
@@ -5880,7 +5880,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_I2_R4) {
                        float val = LOCAL_VAR (ip [2], float);
-                       if (mono_isnan (val) || mono_trunc (val) != (gint16)val)
+                       if (val < G_MININT16 || val > G_MAXINT16 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (gint16) val;
                        ip += 3;
@@ -5888,7 +5888,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_I2_R8) {
                        double val = LOCAL_VAR (ip [2], double);
-                       if (mono_isnan (val) || mono_trunc (val) != (gint16)val)
+                       if (val < G_MININT16 || val > G_MAXINT16 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (gint16) val;
                        ip += 3;
@@ -5912,7 +5912,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_U2_R4) {
                        float val = LOCAL_VAR (ip [2], float);
-                       if (mono_isnan (val) || mono_trunc (val) != (guint16)val)
+                       if (val < 0 || val > G_MAXUINT16 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (guint16) val;
                        ip += 3;
@@ -5920,7 +5920,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_U2_R8) {
                        double val = LOCAL_VAR (ip [2], double);
-                       if (mono_isnan (val) || mono_trunc (val) != (guint16)val)
+                       if (val < 0 || val > G_MAXUINT16 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (guint16) val;
                        ip += 3;
@@ -5960,7 +5960,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_I1_R4) {
                        float val = LOCAL_VAR (ip [2], float);
-                       if (mono_isnan (val) || mono_trunc (val) != (gint8)val)
+                       if (val < G_MININT8 || val > G_MAXINT8 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (gint8) val;
                        ip += 3;
@@ -5968,7 +5968,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_I1_R8) {
                        double val = LOCAL_VAR (ip [2], double);
-                       if (mono_isnan (val) || mono_trunc (val) != (gint8)val)
+                       if (val < G_MININT8 || val > G_MAXINT8 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (gint8) val;
                        ip += 3;
@@ -5992,7 +5992,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_U1_R4) {
                        float val = LOCAL_VAR (ip [2], float);
-                       if (mono_isnan (val) || mono_trunc (val) != (guint8)val)
+                       if (val < 0 || val > G_MAXUINT8 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (guint8) val;
                        ip += 3;
@@ -6000,7 +6000,7 @@ MINT_IN_CASE(MINT_BRTRUE_I8_SP) ZEROP_SP(gint64, !=); MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CONV_OVF_U1_R8) {
                        double val = LOCAL_VAR (ip [2], double);
-                       if (mono_isnan (val) || mono_trunc (val) != (guint8)val)
+                       if (val < 0 || val > G_MAXUINT8 || isnan (val))
                                THROW_EX (mono_get_exception_overflow (), ip);
                        LOCAL_VAR (ip [1], gint32) = (guint8) val;
                        ip += 3;
index 19801ed..3bd878e 100644 (file)
@@ -223,7 +223,7 @@ mono_strength_reduction_division (MonoCompile *cfg, MonoInst *ins)
                        guint32 tmp_regi;
 #endif
                        struct magic_signed mag;
-                       int power2 = (ins->inst_imm > 0) ? mono_is_power_of_two (ins->inst_imm) : -1;
+                       int power2 = mono_is_power_of_two (ins->inst_imm);
                        /* The decomposition doesn't handle exception throwing */
                        /* Optimization with MUL does not apply for -1, 0 and 1 divisors */
                        if (ins->inst_imm == 0 || ins->inst_imm == -1) {
@@ -350,7 +350,7 @@ mono_strength_reduction_ins (MonoCompile *cfg, MonoInst *ins, const char **spec)
                        ins->opcode = OP_INEG;
                } else if ((ins->opcode == OP_LMUL_IMM) && (ins->inst_imm == -1)) {
                        ins->opcode = OP_LNEG;
-               } else if (ins->inst_imm > 0) {
+               } else {
                        int power2 = mono_is_power_of_two (ins->inst_imm);
                        if (power2 >= 0) {
                                ins->opcode = (ins->opcode == OP_MUL_IMM) ? OP_SHL_IMM : ((ins->opcode == OP_LMUL_IMM) ? OP_LSHL_IMM : OP_ISHL_IMM);
index f22ba5b..58c0cef 100644 (file)
@@ -3466,7 +3466,7 @@ loop_start:
                                ins->inst_c0 = 0;
                                break;
                        }
-                       imm8 = (ins->inst_imm > 0) ? mono_is_power_of_two (ins->inst_imm) : -1;
+                       imm8 = mono_is_power_of_two (ins->inst_imm);
                        if (imm8 > 0) {
                                ins->opcode = OP_SHL_IMM;
                                ins->inst_imm = imm8;
index b77252e..9a353ce 100644 (file)
@@ -1987,7 +1987,7 @@ mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
                                        MONO_DELETE_INS (bb, ins);
                                        continue;
                                }
-                       } else if (ins->inst_imm > 0) {
+                       } else {
                                int power2 = mono_is_power_of_two (ins->inst_imm);
                                if (power2 > 0) {
                                        ins->opcode = OP_SHL_IMM;
@@ -2666,7 +2666,7 @@ loop_start:
                                ins->inst_c0 = 0;
                                break;
                        }
-                       imm = (ins->inst_imm > 0) ? mono_is_power_of_two (ins->inst_imm) : -1;
+                       imm = mono_is_power_of_two (ins->inst_imm);
                        if (imm > 0) {
                                ins->opcode = OP_SHL_IMM;
                                ins->inst_imm = imm;
index e3de468..19097c9 100644 (file)
@@ -1963,7 +1963,7 @@ mono_arch_peephole_pass_2 (MonoCompile *cfg, MonoBasicBlock *bb)
                                        MONO_DELETE_INS (bb, ins);
                                        continue;
                                }
-                       } else if (inst->inst_imm > 0) {
+                       } else {
                                int power2 = mono_is_power_of_two (ins->inst_imm);
                                if (power2 > 0) {
                                        ins->opcode = OP_SHL_IMM;
@@ -2537,7 +2537,7 @@ loop_start:
                                ins->inst_c0 = 0;
                                break;
                        }
-                       imm = (ins->inst_imm > 0) ? mono_is_power_of_two (ins->inst_imm) : -1;
+                       imm = mono_is_power_of_two (ins->inst_imm);
                        if (imm > 0) {
                                ins->opcode = OP_SHL_IMM;
                                ins->inst_imm = imm;
index 64cf26f..3712feb 100644 (file)
         </ExcludeList>
 
 
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/Convert/value_numbering_checked_casts_of_constants/*">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/int64/misc/longmul/*">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/Convert/out_of_range_fp_to_int_conversions/*">
             <Issue>Mono does not define out of range fp to int conversions</Issue>
         </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/Overflow/FloatOvfToInt2_r/*">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/Overflow/FloatOvfToInt2_ro/*">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/Overflow/FloatOvfToInt2_d/*">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Methodical/Overflow/FloatOvfToInt2_do/*">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)/JIT/opt/Devirtualization/Comparer_get_Default/*">
             <Issue>https://github.com/dotnet/runtime/issues/48190</Issue>
         </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/Convert/ldind_conv/**">
             <Issue>needs triage</Issue>
         </ExcludeList>
+        <ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/Convert/signed_overflow_conversions_are_not_treated_as_unsigned/**">
+            <Issue>https://github.com/dotnet/runtime/issues/51323</Issue>
+        </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/coverage/compiler/FilterToHandler/**">
             <Issue>needs triage</Issue>
         </ExcludeList>