Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch (more) mismatched args in fgMorphArgs #70846

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3399,13 +3399,28 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
makeOutArgCopy = true;
}
}
else if (genTypeSize(varDsc->TypeGet()) != genTypeSize(structBaseType))
else if (genTypeSize(varDsc) != genTypeSize(structBaseType))
{
// Not a promoted struct, so just swizzle the type by using GT_LCL_FLD
lvaSetVarDoNotEnregister(lclNum DEBUGARG(DoNotEnregisterReason::SwizzleArg));
argObj->ChangeOper(GT_LCL_FLD);
argObj->gtType = structBaseType;
}
else if (varTypeUsesFloatReg(varDsc) != varTypeUsesFloatReg(structBaseType))
{
// Here we can see int <-> float, long <-> double, long <-> simd8 mismatches, due
// to the "OBJ(ADDR(LCL))" => "LCL" folding above. The latter case is handled in
// lowering, others we will handle here via swizzling.
CLANG_FORMAT_COMMENT_ANCHOR;
#ifdef TARGET_AMD64
if (varDsc->TypeGet() != TYP_SIMD8)
#endif // TARGET_AMD64
{
lvaSetVarDoNotEnregister(lclNum DEBUGARG(DoNotEnregisterReason::SwizzleArg));
argObj->ChangeOper(GT_LCL_FLD);
argObj->gtType = structBaseType;
}
}
}
else if (argObj->OperIs(GT_LCL_FLD, GT_IND))
{
Expand Down
36 changes: 36 additions & 0 deletions src/tests/JIT/Directed/StructABI/TypeMismatchedArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static int Main()
return 105;
}

if (ProblemWithRegFileMismatch_Win_x64(12, 13))
{
return 106;
}

return 100;
}

Expand Down Expand Up @@ -86,6 +91,21 @@ private static bool ProblemWithVectorCallArg()
return result != s_vtor128.Vtor4.X;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool ProblemWithRegFileMismatch_Win_x64(double dbl, float flt)
{
if (CallForDblStruct(*(DblStruct*)&dbl) != dbl)
{
return true;
}
if (CallForFltStruct(*(FltStruct*)&flt) != flt)
{
return true;
}

return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static float CallForVector4(Vector4 value) => value.X;

Expand All @@ -97,6 +117,12 @@ private static bool ProblemWithVectorCallArg()

[MethodImpl(MethodImplOptions.NoInlining)]
private static long CallForSplitStructWithFourLongs(int arg0, int arg1, StructWithFourLongs splitArg) => splitArg.LongOne;

[MethodImpl(MethodImplOptions.NoInlining)]
private static double CallForDblStruct(DblStruct value) => value.Dbl;

[MethodImpl(MethodImplOptions.NoInlining)]
private static float CallForFltStruct(FltStruct value) => value.Flt;
}

[StructLayout(LayoutKind.Explicit)]
Expand Down Expand Up @@ -170,3 +196,13 @@ struct FourDoublesHfaStruct
public double ThirdDblValue;
public double FourthDblValue;
}

struct DblStruct
{
public double Dbl;
}

struct FltStruct
{
public float Flt;
}