================
@@ -14166,7 +14160,48 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
         !EvaluateInteger(E->getArg(1), Amt, Info))
       return false;
 
-    return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
+    // Normalize shift amount to [0, BitWidth) range to match runtime behavior
+    unsigned BitWidth = Val.getBitWidth();
+    unsigned AmtBitWidth = Amt.getBitWidth();
+    APSInt Divisor;
+    if (AmtBitWidth > BitWidth) {
+      Divisor = APSInt(llvm::APInt(AmtBitWidth, BitWidth), Amt.isUnsigned());
+    } else {
+      Divisor = APSInt(llvm::APInt(BitWidth, BitWidth), Amt.isUnsigned());
+      Amt = Amt.extend(BitWidth);
+    }
+
+    Amt = Amt % Divisor;
+    if (Amt.isNegative()) {
+      Amt += Divisor;
+    }
+
+    // Determine rotation direction
+    bool IsRotateRight;
+    switch (BuiltinOp) {
----------------
erichkeane wrote:

Instead of this rigamarole, just return out of the switch.

https://github.com/llvm/llvm-project/pull/160259
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to