[clang] [Clang] Add __builtin_bswapg (PR #162433)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 18 22:02:29 PDT 2025


================
@@ -3622,6 +3622,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
           Builder.CreateArithmeticFence(ArgValue, ConvertType(ArgType)));
     return RValue::get(ArgValue);
   }
+  case Builtin::BI__builtin_bswapg: {
+    Value *ArgValue = EmitScalarExpr(E->getArg(0));
+    llvm::IntegerType *IntTy = cast<llvm::IntegerType>(ArgValue->getType());
+    assert(IntTy && "LLVM's __builtin_bswapg only supports integer variants");
----------------
ojhunt wrote:

I don't think mod 16 is right either, swapping `_BitInt(24)` (etc) is in principle just as reasonable a swap, though it would be a novel choice. And at the same time as disallowing _BitInt(24), the mod 16  rule allows the equivalently odd _BitInt(48) to be swapped.

Would it be more reasonable to simply say it must be a power of 2 number of bytes (N=8*2^^N for some positive N)? @philnik777 does that sound reasonable?

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


More information about the cfe-commits mailing list