xref: /llvm-project/clang/test/CodeGen/builtin_clrsb.c (revision 0a4f6be4434c9c5d03d9e7ed46ed21af1fdd6a1a)
1 // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
2 
test__builtin_clrsb(int x)3 int test__builtin_clrsb(int x) {
4 // CHECK-LABEL: test__builtin_clrsb
5 // CHECK: [[C:%.*]] = icmp slt i32 [[X:%.*]], 0
6 // CHECK-NEXT: [[INV:%.*]] = xor i32 [[X]], -1
7 // CHECK-NEXT: [[SEL:%.*]] = select i1 [[C]], i32 [[INV]], i32 [[X]]
8 // CHECK-NEXT: [[CTLZ:%.*]] = call i32 @llvm.ctlz.i32(i32 [[SEL]], i1 false)
9 // CHECK-NEXT: [[SUB:%.*]] = sub i32 [[CTLZ]], 1
10   return __builtin_clrsb(x);
11 }
12 
test__builtin_clrsbll(long long x)13 int test__builtin_clrsbll(long long x) {
14 // CHECK-LABEL: test__builtin_clrsbll
15 // CHECK: [[C:%.*]] = icmp slt i64 [[X:%.*]], 0
16 // CHECK-NEXT: [[INV:%.*]] = xor i64 [[X]], -1
17 // CHECK-NEXT: [[SEL:%.*]] = select i1 [[C]], i64 [[INV]], i64 [[X]]
18 // CHECK-NEXT: [[CTLZ:%.*]] = call i64 @llvm.ctlz.i64(i64 [[SEL]], i1 false)
19 // CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CTLZ]], 1
20 // CHECK-NEXT: trunc i64 [[SUB]] to i32
21   return __builtin_clrsbll(x);
22 }
23