return Known;
}
+ // No matter the shift amount, the trailing zeros will stay zero.
+ unsigned MinTrailingZeros = LHS.countMinTrailingZeros();
+
// Minimum shift amount low bits are known zero.
- if (RHS.getMinValue().ult(BitWidth))
- Known.Zero.setLowBits(RHS.getMinValue().getZExtValue());
+ if (RHS.getMinValue().ult(BitWidth)) {
+ MinTrailingZeros += RHS.getMinValue().getZExtValue();
+ MinTrailingZeros = std::min(MinTrailingZeros, BitWidth);
+ }
- // No matter the shift amount, the trailing zeros will stay zero.
- Known.Zero.setLowBits(LHS.countMinTrailingZeros());
+ Known.Zero.setLowBits(MinTrailingZeros);
return Known;
}
return Known;
}
+ // No matter the shift amount, the leading zeros will stay zero.
+ unsigned MinLeadingZeros = LHS.countMinLeadingZeros();
+
// Minimum shift amount high bits are known zero.
- if (RHS.getMinValue().ult(BitWidth))
- Known.Zero.setHighBits(RHS.getMinValue().getZExtValue());
+ if (RHS.getMinValue().ult(BitWidth)) {
+ MinLeadingZeros += RHS.getMinValue().getZExtValue();
+ MinLeadingZeros = std::min(MinLeadingZeros, BitWidth);
+ }
- // No matter the shift amount, the leading zeros will stay zero.
- Known.Zero.setHighBits(LHS.countMinLeadingZeros());
+ Known.Zero.setHighBits(MinLeadingZeros);
return Known;
}
return Known;
}
- // TODO: Minimum shift amount high bits are known sign bits.
- // TODO: No matter the shift amount, the leading sign bits will stay.
+ // No matter the shift amount, the leading sign bits will stay.
+ unsigned MinLeadingZeros = LHS.countMinLeadingZeros();
+ unsigned MinLeadingOnes = LHS.countMinLeadingOnes();
+
+ // Minimum shift amount high bits are known sign bits.
+ if (RHS.getMinValue().ult(BitWidth)) {
+ if (MinLeadingZeros) {
+ MinLeadingZeros += RHS.getMinValue().getZExtValue();
+ MinLeadingZeros = std::min(MinLeadingZeros, BitWidth);
+ }
+ if (MinLeadingOnes) {
+ MinLeadingOnes += RHS.getMinValue().getZExtValue();
+ MinLeadingOnes = std::min(MinLeadingOnes, BitWidth);
+ }
+ }
+
+ Known.Zero.setHighBits(MinLeadingZeros);
+ Known.One.setHighBits(MinLeadingOnes);
return Known;
}