[RyuJIT] Avoid emitting cdq/coq for a positive constant in rax for idiv (#41551)
authorEgor Bogatov <egorbo@gmail.com>
Tue, 1 Sep 2020 02:43:25 +0000 (05:43 +0300)
committerGitHub <noreply@github.com>
Tue, 1 Sep 2020 02:43:25 +0000 (19:43 -0700)
* avoid emitting cdq/coq for dividend if it's a positive constant

src/coreclr/src/jit/codegenxarch.cpp

index 88c021a..7e63dd6 100644 (file)
@@ -788,7 +788,8 @@ void CodeGen::genCodeForDivMod(GenTreeOp* treeNode)
     genCopyRegIfNeeded(dividend, REG_RAX);
 
     // zero or sign extend rax to rdx
-    if (oper == GT_UMOD || oper == GT_UDIV)
+    if (oper == GT_UMOD || oper == GT_UDIV ||
+        (dividend->IsIntegralConst() && (dividend->AsIntConCommon()->IconValue() > 0)))
     {
         instGen_Set_Reg_To_Zero(EA_PTRSIZE, REG_EDX);
     }