From a7afe2142824bace853f3573892ce3e3bd045b1d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 18 Feb 2023 19:22:50 +0100 Subject: [PATCH 1/5] replace COMMA with a statement in impCastClassOrIsInstToTree --- src/coreclr/jit/importer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index dc327ff6fd4267..f5868cc7c75b1a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -5933,11 +5933,11 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // thus we can use gtClone(op1) from now on // - GenTree* op2Var = op2; if (isCastClass && !partialExpand) { - op2Var = fgInsertCommaFormTemp(&op2); - lvaTable[op2Var->AsLclVarCommon()->GetLclNum()].lvIsCSE = true; + const unsigned clsTmpNum = lvaGrabTemp(true DEBUGARG("spilling class handle")); + impAssignTempGen(clsTmpNum, op2); + op2 = gtNewLclvNode(clsTmpNum, op2->TypeGet()); } temp = gtNewMethodTableLookup(temp); condMT = @@ -5971,7 +5971,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // use the special helper that skips the cases checked by our inlined cast specialHelper = CORINFO_HELP_CHKCASTCLASS_SPECIAL; } - condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, partialExpand ? op2 : op2Var, gtClone(op1)); + condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, gtClone(op2), gtClone(op1)); } else if (partialExpand) { From 55fe3d5882adea205204049383eadb33c0373f83 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sat, 18 Feb 2023 23:13:21 +0100 Subject: [PATCH 2/5] set lvIsCSE --- src/coreclr/jit/importer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index f5868cc7c75b1a..98585ade4217e2 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -5938,6 +5938,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( const unsigned clsTmpNum = lvaGrabTemp(true DEBUGARG("spilling class handle")); impAssignTempGen(clsTmpNum, op2); op2 = gtNewLclvNode(clsTmpNum, op2->TypeGet()); + lvaTable[clsTmpNum].lvIsCSE = true; } temp = gtNewMethodTableLookup(temp); condMT = From e0b5bbe9c13cb3cdf5d10a040ee93b4de1461726 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 19 Feb 2023 11:44:17 +0100 Subject: [PATCH 3/5] clean up --- src/coreclr/jit/importer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 97fafb69c3f543..e807c8d76e636b 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -5936,12 +5936,14 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // thus we can use gtClone(op1) from now on // + GenTree* op2Var = op2; if (isCastClass && !partialExpand) { const unsigned clsTmpNum = lvaGrabTemp(true DEBUGARG("spilling class handle")); impAssignTempGen(clsTmpNum, op2); - op2 = gtNewLclvNode(clsTmpNum, op2->TypeGet()); lvaTable[clsTmpNum].lvIsCSE = true; + op2 = gtNewLclvNode(clsTmpNum, op2->TypeGet()); + op2Var = gtNewLclvNode(clsTmpNum, op2->TypeGet()); } temp = gtNewMethodTableLookup(temp); condMT = @@ -5975,7 +5977,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // use the special helper that skips the cases checked by our inlined cast specialHelper = CORINFO_HELP_CHKCASTCLASS_SPECIAL; } - condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, gtClone(op2), gtClone(op1)); + condTrue = gtNewHelperCallNode(specialHelper, TYP_REF, partialExpand ? op2 : op2Var, gtClone(op1)); } else if (partialExpand) { From 61281cf6bfe4bba574ad31dbebc6e4cf1c709c04 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 19 Feb 2023 17:44:05 +0100 Subject: [PATCH 4/5] conservative fix --- src/coreclr/jit/importer.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index e807c8d76e636b..d303849829659d 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -5937,13 +5937,11 @@ GenTree* Compiler::impCastClassOrIsInstToTree( // GenTree* op2Var = op2; - if (isCastClass && !partialExpand) + if (isCastClass && !partialExpand && (exactCls == NO_CLASS_HANDLE)) { - const unsigned clsTmpNum = lvaGrabTemp(true DEBUGARG("spilling class handle")); - impAssignTempGen(clsTmpNum, op2); - lvaTable[clsTmpNum].lvIsCSE = true; - op2 = gtNewLclvNode(clsTmpNum, op2->TypeGet()); - op2Var = gtNewLclvNode(clsTmpNum, op2->TypeGet()); + // if exactCls is not null we won't have to clone op2 (it will be used only for the fallback) + op2Var = fgInsertCommaFormTemp(&op2); + lvaTable[op2Var->AsLclVarCommon()->GetLclNum()].lvIsCSE = true; } temp = gtNewMethodTableLookup(temp); condMT = From 7458aa87d45d0784a22fd7068c09a3d8bde16d53 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 20 Feb 2023 10:12:19 +0100 Subject: [PATCH 5/5] remove issue --- src/tests/issues.targets | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 71cb50f4000358..638d0ac1f4cea9 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -1324,9 +1324,6 @@ https://github.com/dotnet/runtime/issues/71883 - - https://github.com/dotnet/runtime/issues/82071 - https://github.com/dotnet/runtimelab/issues/155: Reflection emit