From d2dd5800e5c7426968fe0ed93fcf88d836880174 Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Tue, 22 Jun 2021 10:18:44 +0300 Subject: [PATCH] Normalize GT_UN(op, 0) early in importer Normalizing this idiom helps downstream optimizations. --- src/coreclr/jit/importer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 4b6a6ddb06bc02..3fc68769c2aff0 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -13064,6 +13064,14 @@ void Compiler::impImportBlockCode(BasicBlock* block) 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. + if ((opcode == CEE_CGT_UN) && op2->IsIntegralConst(0)) + { + oper = GT_NE; + uns = false; + } + #ifdef TARGET_64BIT // TODO-Casts: create a helper that upcasts int32 -> native int when necessary. // See also identical code in impGetByRefResultType and STSFLD import. @@ -13085,7 +13093,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) op1 = gtNewOperNode(oper, TYP_INT, op1, op2); // TODO: setting both flags when only one is appropriate. - if (opcode == CEE_CGT_UN || opcode == CEE_CLT_UN) + if (uns) { op1->gtFlags |= GTF_RELOP_NAN_UN | GTF_UNSIGNED; }