[RyuJIT/arm32] Assertion failed '(allRegs(theInterval->registerType) & mask) != 0'
$ COMPlus_AltJit=testout1:Main \
gdb --args clr-debug/corerun \
tests-release/JIT/Regression/CLR-x86-JIT/V1-M12-Beta2/b76267/b76267/b76267.exe
...
dotnet/coreclr#9 0xb0c6c1cc in assertAbort (why=0xb0f181a5 "(allRegs(theInterval->registerType) & mask) != 0", file=0xb0f17ed3 "/home/mskvortsov/git/coreclr/src/jit/lsra.cpp", line=892) at /home/mskvortsov/git/coreclr/src/jit/error.cpp:287
dotnet/coreclr#10 0xb0d2c1e6 in LinearScan::newRefPosition (this=0x9e5c0, theInterval=0x9fd04, theLocation=32, theRefType=RefType::RefTypeDef, theTreeNode=0x9f064, mask=131072, multiRegIdx=0, minRegCandidateCount=2) at /home/mskvortsov/git/coreclr/src/jit/lsra.cpp:892
dotnet/coreclr#11 0xb0d357a6 in LinearScan::buildRefPositionsForNode (this=0x9e5c0, tree=0x9f064, block=0x975d4, listNodePool=..., operandToLocationInfoMap=..., currentLoc=31) at /home/mskvortsov/git/coreclr/src/jit/lsra.cpp:4114
dotnet/coreclr#12 0xb0d2e36a in LinearScan::buildIntervals (this=0x9e5c0) at /home/mskvortsov/git/coreclr/src/jit/lsra.cpp:4680
dotnet/coreclr#13 0xb0d2d936 in LinearScan::doLinearScan (this=0x9e5c0) at /home/mskvortsov/git/coreclr/src/jit/lsra.cpp:1765
JIT/Directed/coverage/oldtests/cse2_cs_d
JIT/Directed/coverage/oldtests/cse2_cs_do
JIT/Directed/coverage/oldtests/cse2_cs_r
JIT/Directed/coverage/oldtests/cse2_cs_ro
JIT/jit64/hfa/main/testA/hfa_nf2A_d
JIT/jit64/hfa/main/testA/hfa_sf2A_d
JIT/jit64/hfa/main/testC/hfa_nf2C_d
JIT/jit64/hfa/main/testC/hfa_sf2C_d
JIT/jit64/hfa/main/testG/hfa_nf2G_d
JIT/jit64/hfa/main/testG/hfa_sf2G_d
JIT/Regression/CLR-x86-JIT/dev10/b464149/b464149
JIT/Regression/CLR-x86-JIT/V1-M12-Beta2/b76267/b76267
JIT/Regression/Dev11/External/dev11_111914/BadMax1
cc @dotnet/arm32-contrib
At least one bug related to this issue is at lsraarmarch.cpp:560:
regNumber argReg = curArgTabEntry->regNum;
for (GenTreeFieldList* entry = argNode->AsFieldList(); entry != nullptr; entry = entry->Rest())
{
TreeNodeInfoInitPutArgReg(entry->Current()->AsUnOp(), argReg, *info, false, &callHasFloatRegArgs);
// Update argReg for the next putarg_reg (if any)
argReg = genRegArgNext(argReg);
}
For a TYP_DOUBLE entry, genRegArgNext() should be called twice: argReg should be updated from e.g. f0 to f2, not to f1.
The issue dotnet/coreclr#11928 is related to this one.
With recent commit be21b511fc3ee42a2db1c8ce70499efd8d82d37e.
Same assertion failure.
FAILED - [ 4][ 9s]JIT/jit64/hfa/main/testA/hfa_nf2A_d/hfa_nf2A_d.sh
FAILED - [ 5][ 11s]JIT/jit64/hfa/main/testA/hfa_sf2A_d/hfa_sf2A_d.sh
FAILED - [ 6][ 4s]JIT/jit64/hfa/main/testC/hfa_nf2C_d/hfa_nf2C_d.sh
FAILED - [ 7][ 5s]JIT/jit64/hfa/main/testC/hfa_sf2C_d/hfa_sf2C_d.sh
FAILED - [ 8][ 4s]JIT/jit64/hfa/main/testG/hfa_nf2G_d/hfa_nf2G_d.sh
FAILED - [ 9][ 5s]JIT/jit64/hfa/main/testG/hfa_sf2G_d/hfa_sf2G_d.sh
Assert failure(PID 22580 [0x00005834], Thread: 22580 [0x5834]): Assertion failed '(allRegs(theInterval->registerType) & mask) != 0' in 'DomainBoundILStubClass:IL_STUB_PInvoke(struct,float,struct,int,struct,short,double,struct,struct,float,long,float,struct,float,struct):float' (IL size 179)
File: /opt/code/github/hqueue/coreclr/src/jit/lsra.cpp Line: 892
Different assertion.
FAILED - [ 13][ 7s]JIT/jit64/hfa/main/testA/hfa_nd2A_d/hfa_nd2A_d.sh
Assert failure(PID 22743 [0x000058d7], Thread: 22743 [0x58d7]): Assertion failed 'info->numSlots == 1' in 'DomainBoundILStubClass:IL_STUB_PInvoke(float,double,float,double,float,double,float,double,float,double,float,double,float,struct):double' (IL size 169)
File: /opt/code/github/hqueue/coreclr/src/jit/lsraarmarch.cpp Line: 702
Image: /mnt/albireo/mywork/device/rpi3/unittests/coreoverlays/coreoverlay.test20170608/corerun
Passed.
PASSED - [ 0][ 12s]JIT/Directed/coverage/oldtests/cse2_cs_d/cse2_cs_d.sh
PASSED - [ 1][ 11s]JIT/Directed/coverage/oldtests/cse2_cs_do/cse2_cs_do.sh
PASSED - [ 2][ 11s]JIT/Directed/coverage/oldtests/cse2_cs_r/cse2_cs_r.sh
PASSED - [ 3][ 10s]JIT/Directed/coverage/oldtests/cse2_cs_ro/cse2_cs_ro.sh
PASSED - [ 10][ 7s]JIT/Regression/CLR-x86-JIT/dev10/b464149/b464149/b464149.sh
PASSED - [ 11][ 6s]JIT/Regression/CLR-x86-JIT/V1-M12-Beta2/b76267/b76267/b76267.sh
PASSED - [ 12][ 6s]JIT/Regression/Dev11/External/dev11_111914/BadMax1/BadMax1.sh
@BruceForstall could you assign this issue to me?
I've prepared small test where bug's reprodiced:
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
namespace HFATest
{
public struct HFA01
{
public float f1;
}
public class TestMan
{
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static float Sum5_HFA01(HFA01 hfa)
{
return hfa.f1;
}
}
public class TestCase
{
static int Main()
{
HFA01 hfa01;
hfa01.f1 = 1;
TestMan.Sum5_HFA01(hfa01);
return 100;
}
}
}
And before assertions it makes following IR:
BB01 [000..016) (return), preds={} succs={}
=====
N003. IL_OFFSET IL offset: 0x0 REG NA
N005. t5 = CNS_DBL 1.0000000000000000 REG NA
internal (1):
N007. V00 MEM; t5
N009. IL_OFFSET IL offset: 0xc REG NA
N011. t11* = V00 MEM
N013. FIELD_LIST
N015. t15 = PUTARG_REG; t11*
N017. t17 = CNS_INT(h) 0xB523337C ftn REG NA
N019. t19 = IND ; t17
N021. CALL ; t15,t19
N023. IL_OFFSET IL offset: 0x13 REG NA
N025. t25 = CNS_INT 100 REG NA
N027. RETURN ; t25
So is it OK that there is FIELD_LIST instruction for sturct with one argument?
I've found // We only build GT_FIELD_LISTs for MultiReg structs for the RyuJIT backend comment in morph.cpp. Who is right?
@hqueue I've found you PR dotnet/coreclr#12604 which disable disable one filed HFA promotion. So structure like in sample above isn't being promoted now. Where should be located promotion logic in your opinion? Is PR dotnet/coreclr#12604 temporary solution?
@alpencolt Actually I also have same question for the right place of HFA implementation. According to the comment at https://github.com/dotnet/coreclr/pull/12604/files#diff-d22daaba7b83944564e10906b5ebb74aR1806, I think PR dotnet/coreclr#12604 is temporary solution and HFA logic for this kind of struct is not implemented for ARM64 either.
@hqueue do you have any assumption why HFA should be promoted different way than regular structures?
I don't think it needs to change to GT_FIELD_LIST for one-field-HFA. I think it should be handled like primitive type value.
BTY, IMHO, implementation for promoted HFA struct may be simpler than promoted general struct, because each field will have same size (4 byte or 8 byte). @YongseopKim , how do you think about this?
I'm not sure below comment.
implementation for promoted HFA struct may be simpler than promoted general struct, because each field will have same size (4 byte or 8 byte)
It's because both RA & CodeGen for general promoted struct are not normal until now (https://github.com/dotnet/coreclr/issues/12810). I don't know the case of HFA struct is same to the general one.
BTW, although I don't know HFA well, one field HFA can be morphed one primitive type value during morph phase? If it could be, it's much easier.
If one field HFA is not prmoted, the struct will be morphed into one primitive type. I think one filed HFA doesn't need to be promoted.
I've tried to compile one-field struct with int value and it has following structure:
▌ CALL float HFATest.TestMan.Sum5_HFA01 $180
└──▌ PUTARG_REG int
└──▌ CNS_INT int 1 $42
I think better to ask guys from Microsoft how HFA struct should be morphed=)
@CarolEidt @BruceForstall could you help us with understanding of behavior? We have one-field HFA and it's being translated to the:
▌ CALL float HFATest.TestMan.Sum5_HFA01 $1c1
└──▌ PUTARG_REG void
└──▌ FIELD_LIST void float at offset 0 $181
└──▌ LCL_FLD float V00 loc0 u:3[+0] (last use) $1c0
So at first it has different order of PUTARG_REG and FIELD_LIST instructions comparing to 2 field HFA:
▌ CALL float HFATest.TestMan.Sum5_HFA02 $1c2
│ ┌──▌ FIELD_LIST void float at offset 4 $181
│ │ └──▌ PUTARG_REG float
│ │ └──▌ LCL_FLD float V00 loc0 [+4]
│ │ └──▌ float V00.f1 (offs=0x00) -> V01 tmp0
│ │ └──▌ float V00.f2 (offs=0x04) -> V02 tmp1 $1c1
└──▌ FIELD_LIST void float at offset 0 $182
└──▌ PUTARG_REG float
└──▌ LCL_FLD float V00 loc0 [+0]
└──▌ float V00.f1 (offs=0x00) -> V01 tmp0
└──▌ float V00.f2 (offs=0x04) -> V02 tmp1 $1c0
Could you explain such difference? I've found that there is the same order for other architectures (at least there is notes in CoreCLR's source code).
Second question is should compiler morph one-field HFA to one primitive value and remove FIELD_LIST like it does for regular struct?
Could you explain such difference? I've found that there is the same order for other architectures (at least there is notes in CoreCLR's source code).
I'm not sure how it winds up looking like this. It should either be morphed to the primitive type, or the GT_PUT_ARG_REG should be below the GT_FIELD_LIST
Second question is should compiler morph one-field HFA to one primitive value and remove FIELD_LIST like it does for regular struct?
I think that would be the best approach.
@CarolEidt fgMorphMultiregStructArgs() transform:
▌ CALL float HFATest.TestMan.Sum5_HFA01
└──▌ OBJ(4) struct
└──▌ ADDR byref
└──▌ LCL_VAR struct V00 loc0
into the:
▌ CALL float HFATest.TestMan.Sum5_HFA01
└──▌ FIELD_LIST void float at offset 0
└──▌ LCL_FLD float V00 loc0 [+0]
since hasMultiregStructArgs is set.
Lowering::NewPutArg() creates PUTARG_REG after that:
▌ CALL float HFATest.TestMan.Sum5_HFA01 $1c1
└──▌ PUTARG_REG void
└──▌ FIELD_LIST void float at offset 0 $181
└──▌ LCL_FLD float V00 loc0 u:3[+0] (last use) $1c0
So there is few possible issues:
hasMultiregStructArgsshould be set for one-filed HFAGT_FIELD_LISTshouldn't be created for one-field HFAGT_PUTARG_REGshould be inserted bellowGT_FIELD_LIST
Here's my thinking on this:
- It would make more sense for
hasMultiregStructArgsto not be set for a one-field HFA. - We shouldn't create a
GT_FIELD_LISTfor a one-field HFA. Instead, it should be passed as the primitive type. - We should never have a
GT_FIELD_LISTbelow aGT_PUTARG_REG. I'm not sure how that's happening, and it may be useful to understand that so that we can add an assert for the condition that's causing it to be generated.
So, I think that what we would like to see after fgMorphArgs() would be:
▌ CALL float HFATest.TestMan.Sum5_HFA01
└──▌ PUTARG_REG float
└──▌ LCL_FLD float V00 loc0 [+0]
I'm not sure what is required to make this happen, but it is not too dissimilar from what is done for single-field structs on x64.
As an aside, the dump of the 2-field HFA above is rather odd, in that it is dumping the fields of the struct after the LCL_FLD.
There is two points to modify
- modify
fgMorphArg()to handle one-field hfa (float, double) - modify
fgMorphMultiregStructArg()to return without generatingGT_FIELD_LIST
Then after morphing,
▌ CALL float HFATest.TestMan.Sum5_HFA01
└──▌ LCL_FLD float V00 loc0 [+0]
And after lowering
▌ CALL float HFATest.TestMan.Sum5_HFA01
└──▌ PUTARG_REG float
└──▌ LCL_FLD float V00 loc0 [+0]
@mskvortsov And if you want to make one-field GT_FIELD_LIST, it should be:
▌ CALL float HFATest.TestMan.Sum5_HFA01 $1c1
└──▌ FIELD_LIST void float at offset 0 $181
└──▌ PUTARG_REG float
└──▌ LCL_FLD float V00 loc0 u:3[+0] (last use) $1c0
Please check this branch https://github.com/hseok-oh/coreclr/tree/ryujit/fix_11783 This branch can be effect LegacyJIT/ARM.
Thank you all, I'll prepare new solution. I think PR https://github.com/dotnet/coreclr/pull/12816 can be declined.
As an aside, the dump of the 2-field HFA above is rather odd, in that it is dumping the fields of the struct after the LCL_FLD.
@CarolEidt it occurs because Compiler::lvaShouldPromoteStructVar() return true. So if we'll revert PR https://github.com/dotnet/coreclr/pull/12604 you will see the same dump for one-field struct.
@hseok-oh are you going to merge code from fix_11783 branch?
@alpencolt No. Feel free your work using that branch.