From 6e1b9db0e33ac156963da24c06095db82ed2bbaa Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 20 Jan 2023 01:20:12 +0100 Subject: [PATCH 1/4] Fold some const expressions early in importer --- src/coreclr/jit/importer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 4b556fa963469..59f1b1b134dc7 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -7562,8 +7562,9 @@ void Compiler::impImportBlockCode(BasicBlock* block) case CEE_BRFALSE_S: /* Pop the comparand (now there's a neat term) from the stack */ + // TODO: we might want to only perform gtFoldExprConst here for TP + op1 = gtFoldExpr(impPopStack().val); - op1 = impPopStack().val; type = op1->TypeGet(); // Per Ecma-355, brfalse and brtrue are only specified for nint, ref, and byref. @@ -7684,8 +7685,9 @@ void Compiler::impImportBlockCode(BasicBlock* block) goto CMP_2_OPs; CMP_2_OPs: - op2 = impPopStack().val; - op1 = impPopStack().val; + // TODO: we might want to only perform gtFoldExprConst here for TP + op2 = gtFoldExpr(impPopStack().val); + op1 = gtFoldExpr(impPopStack().val); // Recognize the IL idiom of CGT_UN(op1, 0) and normalize // it so that downstream optimizations don't have to. From 5109406241fb2df9bc840d257ffc0cf3f4a7dc93 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 20 Jan 2023 10:48:03 +0100 Subject: [PATCH 2/4] Clean up --- 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 59f1b1b134dc7..070ec92e1b9b8 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -7562,8 +7562,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) case CEE_BRFALSE_S: /* Pop the comparand (now there's a neat term) from the stack */ - // TODO: we might want to only perform gtFoldExprConst here for TP - op1 = gtFoldExpr(impPopStack().val); + op1 = impPopStack().val; + op1 = opts.OptimizationEnabled() ? gtFoldExpr(op1) : op1; type = op1->TypeGet(); @@ -7686,8 +7686,8 @@ void Compiler::impImportBlockCode(BasicBlock* block) CMP_2_OPs: // TODO: we might want to only perform gtFoldExprConst here for TP - op2 = gtFoldExpr(impPopStack().val); - op1 = gtFoldExpr(impPopStack().val); + op2 = impPopStack().val; + op1 = impPopStack().val; // Recognize the IL idiom of CGT_UN(op1, 0) and normalize // it so that downstream optimizations don't have to. From 97ff7507724a857a953fe27efa51203ce7d2ac95 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 20 Jan 2023 11:11:57 +0100 Subject: [PATCH 3/4] Update importer.cpp --- src/coreclr/jit/importer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 070ec92e1b9b8..7896f870c8cf3 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -7685,7 +7685,6 @@ void Compiler::impImportBlockCode(BasicBlock* block) goto CMP_2_OPs; CMP_2_OPs: - // TODO: we might want to only perform gtFoldExprConst here for TP op2 = impPopStack().val; op1 = impPopStack().val; From c0219f9fb61abee1300ed5cbb5f61c79d45b0623 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Fri, 20 Jan 2023 17:14:46 +0100 Subject: [PATCH 4/4] Update importer.cpp --- src/coreclr/jit/importer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 7896f870c8cf3..e1802c16acd99 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -7562,8 +7562,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) case CEE_BRFALSE_S: /* Pop the comparand (now there's a neat term) from the stack */ - op1 = impPopStack().val; - op1 = opts.OptimizationEnabled() ? gtFoldExpr(op1) : op1; + op1 = gtFoldExpr(impPopStack().val); type = op1->TypeGet();