Skip to content

Commit 7263953

Browse files
committed
Add MaskedValueIsZero check
Add ones for every high bit that will cleared. We can remove the ugt check because if the masked value is not zero, then ugt will always be true anyway.
1 parent 5143a12 commit 7263953

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13802,11 +13802,16 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
1380213802
if (N0.getOpcode() == ISD::SHL) {
1380313803
// If the original shl may be shifting out bits, do not perform this
1380413804
// transformation.
13805-
// TODO: Add MaskedValueIsZero check.
13806-
unsigned KnownZeroBits = ShVal.getValueSizeInBits() -
13807-
ShVal.getOperand(0).getValueSizeInBits();
13808-
if (ShAmtC->getAPIntValue().ugt(KnownZeroBits))
13805+
13806+
// Create a mask that has ones for the bits being shifted out.
13807+
llvm::APInt ShiftOutMask = llvm::APInt::getHighBitsSet(
13808+
ShVal.getValueSizeInBits(),
13809+
ShAmtC->getAPIntValue().getZExtValue());
13810+
13811+
// Check if the bits being shifted out are known to be zero.
13812+
if (!DAG.MaskedValueIsZero(ShVal, ShiftOutMask)) {
1380913813
return SDValue();
13814+
}
1381013815
}
1381113816

1381213817
// Ensure that the shift amount is wide enough for the shifted value.

0 commit comments

Comments
 (0)