llvm-project
9ffa02db - [CIR] Lower __builtin_bswapg (#203618)

Commit
29 days ago
[CIR] Lower __builtin_bswapg (#203618) C++23 `std::byteswap` lowers every value wider than a single byte through the type-generic `__builtin_bswapg` builtin, which CIRGen had no case for, so `std/numerics/bit/byteswap.pass.cpp` hit `errorBuiltinNYI`. This handles `__builtin_bswapg` the way classic CodeGen does (`CGBuiltin.cpp`): a bool or single-byte integer is returned unchanged, and wider values go through `cir.byte_swap`. Unlike the unsigned-only `__builtin_bswap16/32/64`, the generic builtin also accepts signed operands, so a signed argument is reinterpreted as unsigned of the same width before the swap and cast back afterward. `cir.byte_swap` previously accepted only 16/32/64-bit operands, but `std::byteswap` instantiates it for `__int128` and wide `_BitInt` too (the libc++ test reaches `_BitInt(256)`). The operand constraint is widened to any unsigned integer whose width is a multiple of 16 bits -- which is what `llvm.bswap` requires -- and the existing CIR-to-LLVM lowering already handles any such width. With the fix, `byteswap.pass.cpp` passes under `-fclangir`.
Author
Parents
Loading