Minimal repro
using System;
using System.Runtime.CompilerServices;
public class Program
{
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static int Test(int n)
{
int sum = 0;
int i = 0;
for (int c = 0; c < n; c++)
{
sum += i * 1431655765; // derived IV step = 3 * 0x55555555 = -1
sum += i << 31; // derived IV step = 3 << 31 = int.MinValue
i += 3;
}
return sum;
}
public static int Main()
{
Console.WriteLine(Test(5));
return 100;
}
}
Expected
-10 (printed with DOTNET_JitEnableStrengthReduction=0)
Actual
JIT faults while compiling Test; the hardware #DE surfaces as
Unhandled exception. System.OverflowException: Arithmetic operation resulted in an overflow. at the Test call site, exit code 0xE0434352.
Notes
Two derived IVs with steps -1 and int.MinValue reach ComputeRephrasableIVByScaling (inductionvariableopts.cpp:2156), whose Gcd evaluates b % a = int.MinValue % -1 at inductionvariableopts.cpp:2059 — an unrepresentable signed quotient, lowered to idiv by MSVC. The gcd == 1 || gcd == -1 rejection happens only after the remainder. The int64_t instantiation has the same hazard.
Minimal repro
Expected
-10(printed withDOTNET_JitEnableStrengthReduction=0)Actual
JIT faults while compiling
Test; the hardware#DEsurfaces asUnhandled exception. System.OverflowException: Arithmetic operation resulted in an overflow.at theTestcall site, exit code0xE0434352.Notes
Two derived IVs with steps
-1andint.MinValuereachComputeRephrasableIVByScaling(inductionvariableopts.cpp:2156), whoseGcdevaluatesb % a=int.MinValue % -1at inductionvariableopts.cpp:2059 — an unrepresentable signed quotient, lowered toidivby MSVC. Thegcd == 1 || gcd == -1rejection happens only after the remainder. Theint64_tinstantiation has the same hazard.