================
@@ -19156,6 +19168,42 @@ void HandleComplexComplexDiv(APFloat A, APFloat B,
APFloat C, APFloat D,
}
}
+APSInt NormalizeRotateAmount(const APSInt &Value, const APSInt &Amount) {
+ // Normalize shift amount to [0, BitWidth) range to match runtime behavior
+ APSInt NormAmt = Amount;
+ unsigned BitWidth = Value.getBitWidth();
+ unsigned AmtBitWidth = NormAmt.getBitWidth();
+ if (BitWidth == 1) {
+ // Rotating a 1-bit value is always a no-op
+ NormAmt = APSInt(APInt(AmtBitWidth, 0), NormAmt.isUnsigned());
+ } else {
+ // Divisor is always unsigned to avoid misinterpreting BitWidth as
+ // negative in small bit widths (e.g., BitWidth=2 would be -2 if signed).
----------------
efriedma-quic wrote:
Despite this comment, `NormAmt.srem(Divisor)` below interprets the divisor as
signed.
Fixing this in the general code seems complicated, so maybe just special-case
BitWidth == 2: the rotation amount is either 0 or 1, which corresponds to
whether the amount is even or odd.
https://github.com/llvm/llvm-project/pull/160259
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits