Skip to content
Merged
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
12 changes: 11 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,22 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
case X86::BI__builtin_ia32_lzcnt_u64: {
mlir::Value V = builder.create<cir::ConstantOp>(
getLoc(E->getExprLoc()), cir::BoolAttr::get(&getMLIRContext(), false));

return builder
.create<cir::LLVMIntrinsicCallOp>(
getLoc(E->getExprLoc()), builder.getStringAttr("ctlz"),
Ops[0].getType(), mlir::ValueRange{Ops[0], V})
.getResult();
}
case X86::BI__builtin_ia32_tzcnt_u16:
case X86::BI__builtin_ia32_tzcnt_u32:
case X86::BI__builtin_ia32_tzcnt_u64: {
mlir::Value V = builder.create<cir::ConstantOp>(
getLoc(E->getExprLoc()), cir::BoolAttr::get(&getMLIRContext(), false));
return builder
.create<cir::LLVMIntrinsicCallOp>(
getLoc(E->getExprLoc()), builder.getStringAttr("cttz"),
Ops[0].getType(), mlir::ValueRange{Ops[0], V})
.getResult();
}
}
}
32 changes: 32 additions & 0 deletions clang/test/CIR/CodeGen/X86/bmi-builtins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-linux -Wno-implicit-function-declaration -fclangir -emit-cir -o %t.cir %s
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-linux -Wno-implicit-function-declaration -fclangir -emit-llvm -o %t.ll %s
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s

#include <immintrin.h>

unsigned short test__tzcnt_u16(unsigned short __X) {
// CIR-LABEL: __tzcnt_u16
// LLVM-LABEL: __tzcnt_u16
return __tzcnt_u16(__X);
// CIR: {{%.*}} = cir.llvm.intrinsic "cttz" {{%.*}} : (!u16i, !cir.bool) -> !u16i
// LLVM: i16 @llvm.cttz.i16(i16 %{{.*}}, i1 false)
}

unsigned int test__tzcnt_u32(unsigned int __X) {
// CIR-LABEL: __tzcnt_u32
// LLVM-LABEL: __tzcnt_u32
return __tzcnt_u32(__X);
// CIR: {{%.*}} = cir.llvm.intrinsic "cttz" {{%.*}} : (!u32i, !cir.bool) -> !u32i
// LLVM: i32 @llvm.cttz.i32(i32 %{{.*}}, i1 false)
}

#ifdef __x86_64__
unsigned long long test__tzcnt_u64(unsigned long long __X) {
// CIR-LABEL: __tzcnt_u64
// LLVM-LABEL: __tzcnt_u64
return __tzcnt_u64(__X);
// CIR: {{%.*}} = cir.llvm.intrinsic "cttz" {{%.*}} : (!u64i, !cir.bool) -> !u64i
// LLVM: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 false)
}
#endif
Loading