-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use cinc instead of csel when possible #82031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4d674aa
10b636f
9fd643a
c2481ad
1fbb2f2
40970f4
446b0f9
4f53bb5
68805e8
c0164b4
1c4f94f
fcbc7b1
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 |
---|---|---|
|
@@ -2495,6 +2495,67 @@ void Lowering::ContainCheckNeg(GenTreeOp* neg) | |
} | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------------------------- | ||
// Try converting SELECT/SELECTCC to CINC/CINCCC. Conversion is possible only if | ||
// both the trueVal and falseVal are integral constants and abs(trueVal - falseVal) = 1. | ||
// | ||
// Arguments: | ||
// select - The select node that is now SELECT or SELECTCC | ||
// cond - The condition node that SELECT or SELECTCC uses | ||
// | ||
void Lowering::TryLowerCselToCinc(GenTreeOp* select, GenTree* cond) | ||
{ | ||
assert(select->OperIs(GT_SELECT, GT_SELECTCC)); | ||
|
||
GenTree* trueVal = select->gtOp1; | ||
GenTree* falseVal = select->gtOp2; | ||
size_t op1Val = (size_t)trueVal->AsIntCon()->IconValue(); | ||
size_t op2Val = (size_t)falseVal->AsIntCon()->IconValue(); | ||
|
||
if (op1Val + 1 == op2Val || op2Val + 1 == op1Val) | ||
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. Nit for future PRs: we parenthesize all subexpressions: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/clr-jit-coding-conventions.md#111-logical-and-arithmetic-expressions Let's not rerun CI to fix this, though. 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. Cool, thanks. I will piggyback these changes along with the next related patch (probably |
||
{ | ||
const bool shouldReverseCondition = op1Val + 1 == op2Val; | ||
|
||
// Create a cinc node, insert it and update the use. | ||
if (select->OperIs(GT_SELECT)) | ||
{ | ||
if (shouldReverseCondition) | ||
{ | ||
// Reverse the condition so that op2 will be selected | ||
if (!cond->OperIsCompare()) | ||
{ | ||
// Non-compare nodes add additional GT_NOT node after reversing. | ||
// This would remove gains from this optimisation so don't proceed. | ||
return; | ||
} | ||
select->gtOp2 = select->gtOp1; | ||
GenTree* revCond = comp->gtReverseCond(cond); | ||
assert(cond == revCond); // Ensure `gtReverseCond` did not create a new node. | ||
} | ||
select->gtOp1 = cond->AsOp(); | ||
select->SetOper(GT_CINC); | ||
DISPTREERANGE(BlockRange(), select); | ||
} | ||
else | ||
{ | ||
GenTreeOpCC* selectcc = select->AsOpCC(); | ||
GenCondition selectCond = selectcc->gtCondition; | ||
if (shouldReverseCondition) | ||
{ | ||
// Reverse the condition so that op2 will be selected | ||
selectcc->gtCondition = GenCondition::Reverse(selectCond); | ||
} | ||
else | ||
{ | ||
std::swap(selectcc->gtOp1, selectcc->gtOp2); | ||
} | ||
BlockRange().Remove(selectcc->gtOp2); | ||
selectcc->SetOper(GT_CINCCC); | ||
DISPTREERANGE(BlockRange(), selectcc); | ||
} | ||
} | ||
} | ||
#endif // TARGET_ARM64 | ||
|
||
//------------------------------------------------------------------------ | ||
|
Uh oh!
There was an error while loading. Please reload this page.