Skip to content

Commit 8ae8594

Browse files
authored
NativeAOT: Cover more opcodes in type preinitializer (#112073)
1 parent ed8df42 commit 8ae8594

File tree

2 files changed

+324
-24
lines changed

2 files changed

+324
-24
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
835835
case ILOpcode.conv_u2:
836836
case ILOpcode.conv_u4:
837837
case ILOpcode.conv_u8:
838+
case ILOpcode.conv_r4:
839+
case ILOpcode.conv_r8:
838840
{
839841
StackEntry popped = stack.Pop();
840842
if (popped.ValueKind.WithNormalizedNativeInt(context) == StackValueKind.Int32)
@@ -874,6 +876,12 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
874876
case ILOpcode.conv_u8:
875877
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64((uint)val));
876878
break;
879+
case ILOpcode.conv_r4:
880+
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((float)val));
881+
break;
882+
case ILOpcode.conv_r8:
883+
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((double)val));
884+
break;
877885
default:
878886
return Status.Fail(methodIL.OwningMethod, opcode);
879887
}
@@ -912,6 +920,12 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
912920
case ILOpcode.conv_u8:
913921
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64(val));
914922
break;
923+
case ILOpcode.conv_r4:
924+
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((float)val));
925+
break;
926+
case ILOpcode.conv_r8:
927+
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((double)val));
928+
break;
915929
default:
916930
return Status.Fail(methodIL.OwningMethod, opcode);
917931
}
@@ -921,9 +935,44 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
921935
double val = popped.Value.AsDouble();
922936
switch (opcode)
923937
{
938+
case ILOpcode.conv_i:
939+
stack.Push(StackValueKind.NativeInt,
940+
context.Target.PointerSize == 8 ? ValueTypeValue.FromInt64((long)val) : ValueTypeValue.FromInt32((int)val));
941+
break;
942+
case ILOpcode.conv_u:
943+
stack.Push(StackValueKind.NativeInt,
944+
context.Target.PointerSize == 8 ? ValueTypeValue.FromInt64((long)(ulong)val) : ValueTypeValue.FromInt32((int)(uint)val));
945+
break;
946+
case ILOpcode.conv_i1:
947+
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((sbyte)val));
948+
break;
949+
case ILOpcode.conv_i2:
950+
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((short)val));
951+
break;
952+
case ILOpcode.conv_i4:
953+
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((int)val));
954+
break;
924955
case ILOpcode.conv_i8:
925956
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64((long)val));
926957
break;
958+
case ILOpcode.conv_u1:
959+
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((byte)val));
960+
break;
961+
case ILOpcode.conv_u2:
962+
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((ushort)val));
963+
break;
964+
case ILOpcode.conv_u4:
965+
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32((int)(uint)val));
966+
break;
967+
case ILOpcode.conv_u8:
968+
stack.Push(StackValueKind.Int64, ValueTypeValue.FromInt64((long)(ulong)val));
969+
break;
970+
case ILOpcode.conv_r4:
971+
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble((float)val));
972+
break;
973+
case ILOpcode.conv_r8:
974+
stack.Push(StackValueKind.Float, ValueTypeValue.FromDouble(val));
975+
break;
927976
default:
928977
return Status.Fail(methodIL.OwningMethod, opcode);
929978
}
@@ -1388,8 +1437,12 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
13881437
case ILOpcode.neg:
13891438
{
13901439
StackEntry value = stack.Pop();
1391-
if (value.ValueKind == StackValueKind.Int32)
1392-
stack.Push(StackValueKind.Int32, ValueTypeValue.FromInt32(-value.Value.AsInt32()));
1440+
if (value.ValueKind.WithNormalizedNativeInt(context) == StackValueKind.Int32)
1441+
stack.Push(value.ValueKind, ValueTypeValue.FromInt32(-value.Value.AsInt32()));
1442+
else if (value.ValueKind.WithNormalizedNativeInt(context) == StackValueKind.Int64)
1443+
stack.Push(value.ValueKind, ValueTypeValue.FromInt64(-value.Value.AsInt64()));
1444+
else if (value.ValueKind == StackValueKind.Float)
1445+
stack.Push(value.ValueKind, ValueTypeValue.FromDouble(-value.Value.AsDouble()));
13931446
else
13941447
return Status.Fail(methodIL.OwningMethod, opcode);
13951448
}

0 commit comments

Comments
 (0)