Skip to content

Commit a37502b

Browse files
varelenEgorBo
andauthored
JIT: Optimize bit-wise and operation and compare with same constant value (dotnet#111933)
* JIT: Optimize bit-wise and operation and compare with same constant value This change optimizes bit-wise and with compare patterns like '(x & <constant>) == <constant>' Fix dotnet#101000 * JIT: Apply 'jit-format' to 'lower.cpp' * JIT: Add comment to explain bitwise AND transformation --------- Co-authored-by: Egor Bogatov <[email protected]>
1 parent 472a33b commit a37502b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/coreclr/jit/lower.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4122,6 +4122,20 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
41224122
}
41234123
#endif
41244124
}
4125+
else if (andOp2->IsIntegralConst() && GenTree::Compare(andOp2, op2))
4126+
{
4127+
//
4128+
// Transform EQ|NE(AND(x, y), y) into EQ|NE(AND(NOT(x), y), 0) when y is a constant.
4129+
//
4130+
4131+
GenTree* notNode = comp->gtNewOperNode(GT_NOT, andOp1->TypeGet(), andOp1);
4132+
cmp->gtGetOp1()->AsOp()->gtOp1 = notNode;
4133+
BlockRange().InsertAfter(andOp1, notNode);
4134+
op2->BashToZeroConst(op2->TypeGet());
4135+
4136+
andOp1 = notNode;
4137+
op2Value = 0;
4138+
}
41254139
}
41264140

41274141
#ifdef TARGET_XARCH

0 commit comments

Comments
 (0)