Skip to content

Commit

Permalink
[CIR][CIRGen] Add missing CIRGen for generic bit operation builtins (#…
Browse files Browse the repository at this point in the history
…540)

This patch adds the CIRGen for the following builtin functions:

- `__builtin_clzg`;
- `__builtin_ctzg`;
- `__builtin_popcountg`.

CIRGen for these three functions are missing in the original PR which
introduces CIR bit ops.
  • Loading branch information
Lancern authored and lanza committed Apr 29, 2024
1 parent fe396fd commit 02bbc09
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,14 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_ctz:
case Builtin::BI__builtin_ctzl:
case Builtin::BI__builtin_ctzll:
case Builtin::BI__builtin_ctzg:
return buildBuiltinBitOp<mlir::cir::BitCtzOp>(*this, E, BCK_CTZPassedZero);

case Builtin::BI__builtin_clzs:
case Builtin::BI__builtin_clz:
case Builtin::BI__builtin_clzl:
case Builtin::BI__builtin_clzll:
case Builtin::BI__builtin_clzg:
return buildBuiltinBitOp<mlir::cir::BitClzOp>(*this, E, BCK_CLZPassedZero);

case Builtin::BI__builtin_ffs:
Expand All @@ -591,6 +593,7 @@ RValue CIRGenFunction::buildBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
case Builtin::BI__builtin_popcount:
case Builtin::BI__builtin_popcountl:
case Builtin::BI__builtin_popcountll:
case Builtin::BI__builtin_popcountg:
return buildBuiltinBitOp<mlir::cir::BitPopcountOp>(*this, E, std::nullopt);

case Builtin::BI__builtin_bswap16:
Expand Down
24 changes: 24 additions & 0 deletions clang/test/CIR/CodeGen/builtin-bits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ int test_builtin_ctzll(unsigned long long x) {
// CHECK: %{{.+}} = cir.bit.ctz(%{{.+}} : !u64i) : !s32i
// CHECK: }

int test_builtin_ctzg(unsigned x) {
return __builtin_ctzg(x);
}

// CHECK: cir.func @_Z17test_builtin_ctzgj
// CHECK: %{{.+}} = cir.bit.ctz(%{{.+}} : !u32i) : !s32i
// CHECK: }

int test_builtin_clzs(unsigned short x) {
return __builtin_clzs(x);
}
Expand Down Expand Up @@ -89,6 +97,14 @@ int test_builtin_clzll(unsigned long long x) {
// CHECK: %{{.+}} = cir.bit.clz(%{{.+}} : !u64i) : !s32i
// CHECK: }

int test_builtin_clzg(unsigned x) {
return __builtin_clzg(x);
}

// CHECK: cir.func @_Z17test_builtin_clzgj
// CHECK: %{{.+}} = cir.bit.clz(%{{.+}} : !u32i) : !s32i
// CHECK: }

int test_builtin_ffs(int x) {
return __builtin_ffs(x);
}
Expand Down Expand Up @@ -160,3 +176,11 @@ int test_builtin_popcountll(unsigned long long x) {
// CHECK: cir.func @_Z23test_builtin_popcountlly
// CHECK: %{{.+}} = cir.bit.popcount(%{{.+}} : !u64i) : !s32i
// CHECK: }

int test_builtin_popcountg(unsigned x) {
return __builtin_popcountg(x);
}

// CHECK: cir.func @_Z22test_builtin_popcountgj
// CHECK: %{{.+}} = cir.bit.popcount(%{{.+}} : !u32i) : !s32i
// CHECK: }

0 comments on commit 02bbc09

Please sign in to comment.