Repository navigation
Description
Found by Fuzzlyn in build 1406547 on main (commit ebcaacc).
Assertion failed 'false && "found use of a node that is not in the LIR sequence"' in 'Program:M96(long[][]):byref' during 'Optimize post-layout' (IL size 192; hash 0x2c175bf2; FullOpts)
File: src/coreclr/jit/lir.cpp Line: 1686
Reproduces on linux arm32. Reduced repro:
public class Program
{
public static IRuntime s_rt;
public static short[][][] s_15;
public static uint[, ] s_34;
public static byte[] s_53;
public static int s_62;
public static long[][] s_90;
public static int s_108;
public static int[] s_110;
public static long s_114;
public static ushort s_130;
public static void Main()
{
CollectibleALC alc = new CollectibleALC();
System.Reflection.Assembly asm = alc.LoadFromAssemblyPath(System.Reflection.Assembly.GetExecutingAssembly().Location);
System.Reflection.MethodInfo mi = asm.GetType(typeof(Program).FullName).GetMethod(nameof(MainInner));
System.Type runtimeTy = asm.GetType(typeof(Runtime).FullName);
mi.Invoke(null, new object[] { System.Activator.CreateInstance(runtimeTy) });
}
public static void MainInner(IRuntime rt)
{
M96(s_90);
}
public static ref byte M96(long[][] arg0)
{
byte lvar0 = default(byte);
do
{
s_rt.WriteLine("c_677", 0);
}
while (++lvar0 < 252);
try
{
var vr2 = new short[]
{
1
};
M100(ref arg0[0][0], ref arg0[0][0], vr2);
}
finally
{
arg0[0] = arg0[0];
}
var vr1 = s_15[0][0][0];
if ((1 <= s_114) | (0 > M97(vr1)))
{
arg0[0][0] >>= 1;
}
else
{
s_62 = s_110[0];
}
s_rt.WriteLine("c_715", arg0[0][0]);
s_rt.WriteLine("c_716", s_108);
return ref s_53[0];
}
public static ushort M97(short arg0)
{
bool vr0 = 0 > s_34[0, 0];
return s_130;
}
public static void M100(ref long arg0, ref long arg1, short[] arg2)
{
}
}
public interface IRuntime
{
void WriteLine<T>(string site, T value);
}
public class Runtime : IRuntime
{
public void WriteLine<T>(string site, T value) => System.Console.WriteLine(value);
}
public class CollectibleALC : System.Runtime.Loader.AssemblyLoadContext
{
public CollectibleALC() : base(true)
{
}
}Analysis of jitdump
After LSRA inserts a RELOAD of a SETCC cond=SLT result, BB10 ends in:
N333 SETCC cond=SLT t74
N335 RELOAD t74 t652
N343 JTRUE (op1 = t652)
optOptimizePostLayout then runs and, for every BBJ_COND whose true edge can be made to fall through, reverses the condition:
// src/coreclr/jit/optimizer.cpp ~line 2249
if (test->OperIs(GT_JTRUE))
{
GenTree* const cond = test->gtGetOp1();
GenTree* const newCond = gtReverseCond(cond);
if (cond != newCond)
{
LIR::AsRange(block).InsertAfter(cond, newCond);
test->AsUnOp()->gtOp1 = newCond;
}
}gtReverseCond (gentree.cpp ~line 3716) only reverses in place for OperIsCompare(), GT_JCC/GT_SETCC, GT_JCMP/GT_JTEST, or integer constants. Anything else falls into:
tree = gtNewOperNode(GT_EQ, TYP_INT, tree, gtNewZeroConNode(TYP_INT));For our JTRUE, the operand is a RELOAD node — none of the in-place cases — so gtReverseCond returns a brand-new EQ(reload, CNS_INT 0) tree. The post-layout phase then inserts only the new EQ into the LIR range with InsertAfter(cond, newCond); it never inserts the freshly-allocated CNS_INT 0 operand. After the phase the tree dump shows:
[000654] EQ int <-- not threaded into LIR, but inserted here
┌── t652 (RELOAD)
├── t653 (CNS_INT 0) <-- never inserted into LIR
[000087] JTRUE
fgDebugCheckLIR (or rather the LIR check in lir.cpp line 1686) walks uses and finds the CNS_INT 0 def is not in the block's LIR sequence — hence the assert.
The fix is to also splice the new zero constant into LIR — e.g. when gtReverseCond returned a brand-new EQ, insert both the new EQ and its newly-created right operand (the zero constant) before the JTRUE. Equivalently, gtReverseCond could be changed to take an LIR range and do the splicing itself, or the post-layout phase could refuse to reverse when the cond isn't already in a directly-reversible shape (the LSRA-inserted RELOAD case in particular).
This only triggers on targets where LSRA can leave a RELOAD (or other non-reversible-in-place node) directly under the JTRUE of a BBJ_COND — typically arm32 here.
A details.zip containing repro.mc and jitdump.txt is attached.
cc @dotnet/jit-contrib
Activity
dotnet-policy-service commentedon May 4, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jakobbotsch commentedon May 4, 2026
This runs after LSRA. I do not think we can handle inserting new nodes here. I think rather we should fix it the following way:
gtReverseCondagtTryReverseCondcore that returns a bool instead of introducing new IR. Switch to use this inoptOptimizePostLayoutto avoid introducing new nodes, and just bail on flipping in that case.JTRUEcase inoptOptimizePostLayoutwe should skip copies and reloads on top of the operand viagtSkipCopyOrReload()Add a Fuzzlyn triage skill (#127752)
Add a Fuzzlyn triage skill (#127752)