[clang] [clang] Implement __builtin_stdc_rotate_left, __builtin_stdc_rotate_right (PR #160259)

NagaChaitanya Vellanki via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 5 21:39:18 PST 2025


================
@@ -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).
----------------
chaitanyav wrote:

@efriedma-quic added the special case for bitwidth=2.

https://github.com/llvm/llvm-project/pull/160259


More information about the cfe-commits mailing list