[llvm] [ADT] Add fshl/fshr operations to APSInt (PR #153790)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 15 05:45:20 PDT 2025


================
@@ -41,3 +41,25 @@ void APSInt::Profile(FoldingSetNodeID& ID) const {
   ID.AddInteger((unsigned) (IsUnsigned ? 1 : 0));
   APInt::Profile(ID);
 }
+
+APSInt llvm::APSIntOps::fshl(const APSInt &Hi, const APSInt &Lo,
+                             const APSInt &Shift) {
+  bool IsUnsigned = Hi.isUnsigned();
+  APSInt BitWidth(
+    APInt(Hi.getBitWidth(), static_cast<uint64_t>(Hi.getBitWidth())),
+    IsUnsigned);
+  return APSInt((Hi << (Shift % BitWidth)) |
+                    (Lo >> (BitWidth - (Shift % BitWidth))),
+                IsUnsigned);
----------------
RKSimon wrote:

The shift right must be SRL - it isn't sign based

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


More information about the llvm-commits mailing list