Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3653,12 +3653,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Value *ArgValue = EmitScalarExpr(E->getArg(0));
llvm::IntegerType *IntTy = cast<llvm::IntegerType>(ArgValue->getType());
assert(IntTy && "LLVM's __builtin_bswapg only supports integer variants");
assert(((IntTy->getBitWidth() % 16 == 0 && IntTy->getBitWidth() != 0) ||
IntTy->getBitWidth() == 8) &&
if (IntTy->getBitWidth() == 1 || IntTy->getBitWidth() == 8)
return RValue::get(ArgValue);
assert(((IntTy->getBitWidth() % 16 == 0 && IntTy->getBitWidth() != 0)) &&
"LLVM's __builtin_bswapg only supports integer variants that has a "
"multiple of 16 bits as well as a single byte");
if (IntTy->getBitWidth() == 8)
return RValue::get(ArgValue);
return RValue::get(
emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::bswap));
}
Expand Down
12 changes: 9 additions & 3 deletions clang/test/CodeGen/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,10 @@ void test_builtin_ctzg(unsigned char uc, unsigned short us, unsigned int ui,

#endif

#include <stdbool.h>
// CHECK-LABEL: define{{.*}} void @test_builtin_bswapg
void test_builtin_bswapg(unsigned char uc, unsigned short us, unsigned int ui,
unsigned long ul, unsigned long long ull,
unsigned long ul, unsigned long long ull, bool b,
#ifdef __SIZEOF_INT128__
unsigned __int128 ui128,
#endif
Expand All @@ -929,9 +930,14 @@ void test_builtin_bswapg(unsigned char uc, unsigned short us, unsigned int ui,
int x = 0;
x = x * 2;
#endif
b = __builtin_bswapg(b);
// CHECK: %{{.*}} = load i8, ptr %b.addr
// CHECK: %{{.*}} = trunc i8 %{{.*}} to i1
// CHECK: %{{.*}} = zext i1 %{{.*}} to i8
// CHECK: store i8 %{{.*}}, ptr %b.addr
uc = __builtin_bswapg(uc);
// CHECK: %1 = load i8, ptr %uc.addr
// CHECK: store i8 %1, ptr %uc.addr
// CHECK: %{{.*}} = load i8, ptr %uc.addr
// CHECK: store i8 %{{.*}}, ptr %uc.addr
us = __builtin_bswapg(us);
// CHECK: call i16 @llvm.bswap.i16
ui = __builtin_bswapg(ui);
Expand Down