Use `argIsInvariant` instead of `argNode->OperIsConst()` for inlining observations...
authorSergey Andreenko <seandree@microsoft.com>
Mon, 23 Nov 2020 18:57:27 +0000 (10:57 -0800)
committerGitHub <noreply@github.com>
Mon, 23 Nov 2020 18:57:27 +0000 (10:57 -0800)
* Use `argIsInvariant` instead of `argNode->OperIsConst()`.

* add a small repro test for the current issue.

src/coreclr/src/jit/flowgraph.cpp
src/tests/JIT/Regression/JitBlue/Runtime_43130/Runtime_43130.il [new file with mode: 0644]
src/tests/JIT/Regression/JitBlue/Runtime_43130/Runtime_43130.ilproj [new file with mode: 0644]

index 7e2f3b7..5e41398 100644 (file)
@@ -5179,7 +5179,7 @@ void Compiler::fgObserveInlineConstants(OPCODE opcode, const FgStack& stack, boo
                     // Check for the double whammy of an incoming constant argument
                     // feeding a constant test.
                     unsigned varNum = FgStack::SlotTypeToArgNum(slot0);
-                    if (impInlineInfo->inlArgInfo[varNum].argNode->OperIsConst())
+                    if (impInlineInfo->inlArgInfo[varNum].argIsInvariant)
                     {
                         compInlineResult->Note(InlineObservation::CALLSITE_CONSTANT_ARG_FEEDS_TEST);
                     }
@@ -5221,7 +5221,7 @@ void Compiler::fgObserveInlineConstants(OPCODE opcode, const FgStack& stack, boo
             compInlineResult->Note(InlineObservation::CALLEE_ARG_FEEDS_TEST);
 
             unsigned varNum = FgStack::SlotTypeToArgNum(slot0);
-            if (impInlineInfo->inlArgInfo[varNum].argNode->OperIsConst())
+            if (impInlineInfo->inlArgInfo[varNum].argIsInvariant)
             {
                 compInlineResult->Note(InlineObservation::CALLSITE_CONSTANT_ARG_FEEDS_TEST);
             }
@@ -5232,7 +5232,7 @@ void Compiler::fgObserveInlineConstants(OPCODE opcode, const FgStack& stack, boo
             compInlineResult->Note(InlineObservation::CALLEE_ARG_FEEDS_TEST);
 
             unsigned varNum = FgStack::SlotTypeToArgNum(slot1);
-            if (impInlineInfo->inlArgInfo[varNum].argNode->OperIsConst())
+            if (impInlineInfo->inlArgInfo[varNum].argIsInvariant)
             {
                 compInlineResult->Note(InlineObservation::CALLSITE_CONSTANT_ARG_FEEDS_TEST);
             }
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_43130/Runtime_43130.il b/src/tests/JIT/Regression/JitBlue/Runtime_43130/Runtime_43130.il
new file mode 100644 (file)
index 0000000..d4a3a9a
--- /dev/null
@@ -0,0 +1,193 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+// Test several simple combinations when we inline a method which takes an argument
+// with an implicit cast, when we substitute the use as the argument in the inlined body
+// we should be careful about handling the 'PUTARG_TYPE' node that shows the cast.
+
+.assembly extern System.Runtime
+{
+}
+.assembly extern System.Runtime.Extensions
+{
+}
+.assembly Runtime_43130
+{
+}
+.module Runtime_43130.dll
+
+.class private auto ansi beforefieldinit Runtime_43130
+       extends [System.Runtime]System.Object
+{
+  .method public hidebysig static int32  Test1(int32 i1) cil managed noinlining
+  {
+    // Code size       20 (0x14)
+    .maxstack  2
+    .locals init (int32 V_0,
+             int32 V_1)
+    IL_0000:  nop
+    IL_0001:  ldarg.0
+    IL_0002:  ldc.i4.1
+    IL_0003:  add
+    IL_0004:  stloc.0
+    IL_0005:  ldloc.0
+    // IL_0006:  conv.i2
+    IL_0007:  call       void Runtime_43130::Inline1(int16)
+    IL_000c:  nop
+    IL_000d:  ldc.i4.s   100
+    IL_000f:  stloc.1
+    IL_0010:  br.s       IL_0012
+
+    IL_0012:  ldloc.1
+    IL_0013:  ret
+  } // end of method Runtime_43130::Test1
+
+  .method public hidebysig static void  Inline1(int16 s) cil managed aggressiveinlining
+  {
+    // Code size       9 (0x9)
+    .maxstack  8
+    IL_0000:  nop
+    IL_0001:  ldarg.0
+    IL_0002:  call       void Runtime_43130::CallAMethod1(int16)
+    IL_0007:  nop
+    IL_0008:  ret
+  } // end of method Runtime_43130::Inline1
+
+  .method public hidebysig static void  CallAMethod1(int16 s) cil managed noinlining
+  {
+    // Code size       4 (0x4)
+    .maxstack  8
+    IL_0000:  nop
+    IL_0001:  br.s       IL_0003
+
+    IL_0003:  ret
+  } // end of method Runtime_43130::CallAMethod1
+
+  .method public hidebysig static int32  Test2(int32 i1) cil managed noinlining
+  {
+    // Code size       17 (0x11)
+    .maxstack  2
+    .locals init (int32 V_0,
+             int32 V_1)
+    IL_0000:  nop
+    IL_0001:  ldarg.0
+    IL_0002:  ldc.i4.1
+    IL_0003:  add
+    IL_0004:  stloc.0
+    IL_0005:  ldloc.0
+    // IL_0006:  conv.i2
+    IL_0007:  call       int32 Runtime_43130::Inline2(int16)
+    IL_000c:  stloc.1
+    IL_000d:  br.s       IL_000f
+
+    IL_000f:  ldloc.1
+    IL_0010:  ret
+  } // end of method Runtime_43130::Test2
+
+  .method public hidebysig static int32  Inline2(int16 s) cil managed aggressiveinlining
+  {
+    // Code size       12 (0xc)
+    .maxstack  2
+    .locals init (int32 V_0,
+             int32 V_1)
+    IL_0000:  nop
+    IL_0001:  ldarg.0
+    IL_0002:  ldc.i4.s   10
+    IL_0004:  add
+    IL_0005:  stloc.0
+    IL_0006:  ldloc.0
+    IL_0007:  stloc.1
+    IL_0008:  br.s       IL_000a
+
+    IL_000a:  ldloc.1
+    IL_000b:  ret
+  } // end of method Runtime_43130::Inline2
+
+  .method public hidebysig static int32  Test3(int32 i1) cil managed noinlining
+  {
+    // Code size       20 (0x14)
+    .maxstack  2
+    .locals init (int32 V_0,
+             int32 V_1)
+    IL_0000:  nop
+    IL_0001:  ldarg.0
+    IL_0002:  ldc.i4.1
+    IL_0003:  add
+    IL_0004:  stloc.0
+    IL_0005:  ldloc.0
+    // IL_0006:  conv.i2
+    IL_0007:  call       int32 Runtime_43130::Inline3(int16)
+    IL_000c:  pop
+    IL_000d:  ldc.i4.s   100
+    IL_000f:  stloc.1
+    IL_0010:  br.s       IL_0012
+
+    IL_0012:  ldloc.1
+    IL_0013:  ret
+  } // end of method Runtime_43130::Test3
+
+  .method public hidebysig static int32  Inline3(int16 s) cil managed aggressiveinlining
+  {
+    // Code size       17 (0x11)
+    .maxstack  2
+    .locals init (int32 V_0)
+    IL_0000:  nop
+    IL_0001:  ldarg.0
+    IL_0002:  call       void Runtime_43130::CallAMethod3(int16)
+    IL_0007:  nop
+    IL_0008:  ldarg.0
+    IL_0009:  ldc.i4.s   10
+    IL_000b:  add
+    IL_000c:  stloc.0
+    IL_000d:  br.s       IL_000f
+
+    IL_000f:  ldloc.0
+    IL_0010:  ret
+  } // end of method Runtime_43130::Inline3
+
+  .method public hidebysig static void  CallAMethod3(int16 s) cil managed noinlining
+  {
+    // Code size       4 (0x4)
+    .maxstack  8
+    IL_0000:  nop
+    IL_0001:  br.s       IL_0003
+
+    IL_0003:  ret
+  } // end of method Runtime_43130::CallAMethod3
+
+  .method public hidebysig static int32  Main() cil managed
+  {
+    .entrypoint
+    // Code size       29 (0x1d)
+    .maxstack  1
+    .locals init (int32 V_0)
+    IL_0000:  nop
+    IL_0001:  ldc.i4.1
+    IL_0002:  call       int32 Runtime_43130::Test1(int32)
+    IL_0007:  pop
+    IL_0008:  ldc.i4.1
+    IL_0009:  call       int32 Runtime_43130::Test2(int32)
+    IL_000e:  pop
+    IL_000f:  ldc.i4.1
+    IL_0010:  call       int32 Runtime_43130::Test3(int32)
+    IL_0015:  pop
+    IL_0016:  ldc.i4.s   100
+    IL_0018:  stloc.0
+    IL_0019:  br.s       IL_001b
+
+    IL_001b:  ldloc.0
+    IL_001c:  ret
+  } // end of method Runtime_43130::Main
+
+  .method public hidebysig specialname rtspecialname 
+          instance void  .ctor() cil managed
+  {
+    // Code size       8 (0x8)
+    .maxstack  8
+    IL_0000:  ldarg.0
+    IL_0001:  call       instance void [System.Runtime]System.Object::.ctor()
+    IL_0006:  nop
+    IL_0007:  ret
+  } // end of method Runtime_43130::.ctor
+
+} // end of class Runtime_43130
diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_43130/Runtime_43130.ilproj b/src/tests/JIT/Regression/JitBlue/Runtime_43130/Runtime_43130.ilproj
new file mode 100644 (file)
index 0000000..7dab57f
--- /dev/null
@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk.IL">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <DebugType>None</DebugType>
+    <Optimize>True</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="$(MSBuildProjectName).il" />
+  </ItemGroup>
+</Project>