From 7fb9d9f96d37f7d32f328450757b3165110298f2 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Tue, 1 Sep 2020 05:43:25 +0300 Subject: [PATCH] [RyuJIT] Avoid emitting cdq/coq for a positive constant in rax for idiv (#41551) * avoid emitting cdq/coq for dividend if it's a positive constant --- src/coreclr/src/jit/codegenxarch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/jit/codegenxarch.cpp b/src/coreclr/src/jit/codegenxarch.cpp index 88c021a..7e63dd6 100644 --- a/src/coreclr/src/jit/codegenxarch.cpp +++ b/src/coreclr/src/jit/codegenxarch.cpp @@ -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); } -- 2.7.4