[clang] [CIR] Lower __builtin_bswapg (PR #203618)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 12 14:46:43 PDT 2026


================
@@ -1277,6 +1277,21 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
     return RValue::get(cir::ByteSwapOp::create(builder, loc, arg));
   }
 
+  case Builtin::BI__builtin_bswapg: {
+    mlir::Value arg = emitScalarExpr(e->getArg(0));
+    // A bool or any single-byte integer byte-swaps to itself; cir.byte_swap
+    // only accepts an unsigned integer whose width is a multiple of 16 bits.
+    auto argTy = mlir::dyn_cast<cir::IntType>(arg.getType());
+    if (!argTy || argTy.getWidth() <= 8)
----------------
andykaylor wrote:

This is more permissive than classic codegen, which checks for exactly 1 or 8 here and then asserts the bit width is otherwise a multiple of 16.

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


More information about the cfe-commits mailing list