-
Notifications
You must be signed in to change notification settings - Fork 2.6k
JIT: Transform X % C == 0 to X & (C-1) == 0 #25744
Changes from all commits
2459d77
37cacba
1e578c5
93e4c24
0e53872
8ec24d9
3ec39e0
a9c3508
6fc00a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12278,6 +12278,8 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) | |
| } | ||
| break; | ||
|
|
||
| CM_EQ_OP: | ||
|
|
||
| case GT_EQ: | ||
| case GT_NE: | ||
|
|
||
|
|
@@ -12326,6 +12328,25 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) | |
| } | ||
| } | ||
|
|
||
| // Transform X MOD C == 0 to X UMOD C == 0 if C is a power of two | ||
| // then lowering will be able to transform it to X & (C-1) == 0 | ||
| if (op2->IsIntegralConst(0)) | ||
| { | ||
| op1 = tree->AsOp()->gtGetOp1(); | ||
| if (op1->OperIs(GT_MOD)) | ||
| { | ||
| if (varTypeIsIntegralOrI(op1->AsOp()->gtGetOp1()->gtType) && | ||
| (op1->AsOp()->gtGetOp2()->IsIntegralConst())) | ||
| { | ||
| ssize_t divider = op1->AsOp()->gtGetOp2()->AsIntCon()->IconValue(); | ||
| if (isPow2(divider)) | ||
| { | ||
| op1->SetOper(GT_UMOD); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // | ||
| // Here we look for the following tree | ||
| // | ||
|
|
@@ -12745,6 +12766,11 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac) | |
| oper = (oper == GT_LE) ? GT_EQ : GT_NE; | ||
| tree->SetOper(oper, GenTree::PRESERVE_VN); | ||
| tree->gtFlags &= ~GTF_UNSIGNED; | ||
|
|
||
| if (op1->OperIs(GT_MOD)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @EgorBo I was trying to review that PR and lost the track of the changes, the first part and it is really scary for me to have a back edge in a function like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sandreenko I wanted to handle
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't it be better to call
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sandreenko will try, but I think there will be a few regressions |
||
| { | ||
| goto CM_EQ_OP; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.