Delete incorrect asserts (#69354)
authorSingleAccretion <62474226+SingleAccretion@users.noreply.github.com>
Sat, 14 May 2022 19:15:13 +0000 (22:15 +0300)
committerGitHub <noreply@github.com>
Sat, 14 May 2022 19:15:13 +0000 (21:15 +0200)
* Delete incorrect asserts

In an "OBJ(LCL_VAR_ADDR)" argument, the underlying local can be of any type/HFA-ness.

* Add tests

src/coreclr/jit/codegenarmarch.cpp
src/coreclr/jit/codegenloongarch64.cpp
src/tests/JIT/Directed/StructABI/TypeMismatchedArgs.cs

index a48e7cd..6cb8646 100644 (file)
@@ -1296,18 +1296,12 @@ void CodeGen::genPutArgSplit(GenTreePutArgSplit* treeNode)
         if (varNode != nullptr)
         {
             assert(varNode->isContained());
-            srcVarNum = varNode->GetLclNum();
-
-            // handle promote situation
+            srcVarNum         = varNode->GetLclNum();
             LclVarDsc* varDsc = compiler->lvaGetDesc(srcVarNum);
 
-            // This struct also must live in the stack frame
-            // And it can't live in a register (SIMD)
-            assert(varDsc->lvType == TYP_STRUCT);
+            // This struct also must live in the stack frame.
+            // And it can't live in a register.
             assert(varDsc->lvOnFrame && !varDsc->lvRegister);
-
-            // We don't split HFA struct
-            assert(!varDsc->lvIsHfa());
         }
         else // addrNode is used
         {
index 15bb121..678346f 100644 (file)
@@ -6172,19 +6172,12 @@ void CodeGen::genPutArgSplit(GenTreePutArgSplit* treeNode)
         if (varNode != nullptr)
         {
             assert(varNode->isContained());
-            srcVarNum = varNode->GetLclNum();
-            assert(srcVarNum < compiler->lvaCount);
+            srcVarNum         = varNode->GetLclNum();
+            LclVarDsc* varDsc = compiler->lvaGetDesc(srcVarNum);
 
-            // handle promote situation
-            LclVarDsc* varDsc = compiler->lvaTable + srcVarNum;
-
-            // This struct also must live in the stack frame
-            // And it can't live in a register (SIMD)
-            assert(varDsc->lvType == TYP_STRUCT);
+            // This struct also must live in the stack frame.
+            // And it can't live in a register.
             assert(varDsc->lvOnFrame && !varDsc->lvRegister);
-
-            // We don't split HFA struct
-            assert(!varDsc->lvIsHfa());
         }
         else // addrNode is used
         {
index 722e84a..eb31300 100644 (file)
@@ -9,6 +9,7 @@ public unsafe class TypeMismatchedArgs
 {
     private static readonly HfaUnion s_hfaDblFlt = new HfaUnion { DblHfa = { FirstDblValue = 1.0, SecondDblValue = 2.0 } };
     private static readonly HfaDblLngUnion s_dblLngHfa = new HfaDblLngUnion { DblLng = { FirstLngValue = 10, SecondLngValue = 20 } };
+    private static readonly FourDblLngUnion s_fourDblLngHfa = new FourDblLngUnion { Lngs = { LongOne = 30 } };
 
     public static int Main()
     {
@@ -22,6 +23,16 @@ public unsafe class TypeMismatchedArgs
             return 102;
         }
 
+        if (ProblemWithSplitStructBlkMismatch())
+        {
+            return 103;
+        }
+
+        if (ProblemWithSplitStructHfaMismatch(s_fourDblLngHfa.Hfa))
+        {
+            return 104;
+        }
+
         return 100;
     }
 
@@ -42,7 +53,28 @@ public unsafe class TypeMismatchedArgs
     }
 
     [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool ProblemWithSplitStructBlkMismatch()
+    {
+        var blk = stackalloc byte[sizeof(StructWithFourLongs)];
+        var result = CallForSplitStructWithFourLongs(1, 1, *(StructWithFourLongs*)blk);
+
+        // The stackalloc should have been zeroed-out.
+        return result != 0;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool ProblemWithSplitStructHfaMismatch(FourDoublesHfaStruct fourDblHfa)
+    {
+        var result = CallForSplitStructWithFourLongs(1, 1, *(StructWithFourLongs*)&fourDblHfa);
+
+        return result != s_fourDblLngHfa.Lngs.LongOne;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
     private static double CallForHfaDblStruct(HfaDblStruct value) => value.FirstDblValue;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static long CallForSplitStructWithFourLongs(int arg0, int arg1, StructWithFourLongs splitArg) => splitArg.LongOne;
 }
 
 [StructLayout(LayoutKind.Explicit)]
@@ -63,6 +95,15 @@ struct HfaUnion
     public HfaFltStruct FltHfa;
 }
 
+[StructLayout(LayoutKind.Explicit)]
+struct FourDblLngUnion
+{
+    [FieldOffset(0)]
+    public FourDoublesHfaStruct Hfa;
+    [FieldOffset(0)]
+    public StructWithFourLongs Lngs;
+}
+
 struct DblLngStruct
 {
     public long FirstLngValue;
@@ -82,3 +123,19 @@ struct HfaFltStruct
     public float ThirdFltValue;
     public float FourthFltValue;
 }
+
+struct StructWithFourLongs
+{
+    public long LongOne;
+    public long LongTwo;
+    public long LongThree;
+    public long LongFour;
+}
+
+struct FourDoublesHfaStruct
+{
+    public double FirstDblValue;
+    public double SecondDblValue;
+    public double ThirdDblValue;
+    public double FourthDblValue;
+}