Skip to content

JIT: Optimize bit-wise and operation and compare with same constant value #111933

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4122,6 +4122,20 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
}
#endif
}
else if (andOp2->IsIntegralConst() && GenTree::Compare(andOp2, op2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you leave a comment of what this transformation does?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment, hope it's okay.

{
//
// Transform EQ|NE(AND(x, y), y) into EQ|NE(AND(NOT(x), y), 0) when y is a constant.
//

GenTree* notNode = comp->gtNewOperNode(GT_NOT, andOp1->TypeGet(), andOp1);
cmp->gtGetOp1()->AsOp()->gtOp1 = notNode;
BlockRange().InsertAfter(andOp1, notNode);
op2->BashToZeroConst(op2->TypeGet());

andOp1 = notNode;
op2Value = 0;
}
}

#ifdef TARGET_XARCH
Expand Down
Loading