|
| 1 | +// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-linux -Wno-implicit-function-declaration -fclangir -emit-cir -o %t.cir %s |
| 2 | +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 | +// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-linux -Wno-implicit-function-declaration -fclangir -emit-llvm -o %t.ll %s |
| 4 | +// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s |
| 5 | + |
| 6 | +// This test mimics clang/test/CodeGen/X86/rd-builtins.c, which eventually |
| 7 | +// CIR shall be able to support fully. |
| 8 | + |
| 9 | +#include <x86intrin.h> |
| 10 | + |
| 11 | +unsigned long long test_rdtsc() { |
| 12 | + // CIR-LABEL: @test_rdtsc |
| 13 | + // LLVM-LABEL: @test_rdtsc |
| 14 | + return __rdtsc(); |
| 15 | + // CIR: {{%.*}} = cir.llvm.intrinsic "x86.rdtsc" : () -> !u64i |
| 16 | + // LLVM: call i64 @llvm.x86.rdtsc |
| 17 | +} |
| 18 | + |
| 19 | +unsigned long long test_rdtscp(unsigned int *a) { |
| 20 | + |
| 21 | + return __rdtscp(a); |
| 22 | + |
| 23 | + // CIR-LABEL: @__rdtscp |
| 24 | + // CIR: [[RDTSCP:%.*]] = cir.llvm.intrinsic "x86.rdtscp" : () -> !rec_anon_struct |
| 25 | + // CIR: [[TSC_AUX:%.*]] = cir.extract_member [[RDTSCP]][1] : !rec_anon_struct -> !u32i |
| 26 | + // CIR: cir.store [[TSC_AUX]], %{{.*}} : !u32i, !cir.ptr<!u32i> |
| 27 | + // CIR: {{%.*}} = cir.extract_member [[RDTSCP]][0] : !rec_anon_struct -> !u64i |
| 28 | + |
| 29 | + // LLVM: @test_rdtscp |
| 30 | + // LLVM: [[RDTSCP:%.*]] = call { i64, i32 } @llvm.x86.rdtscp |
| 31 | + // LLVM: [[TSC_AUX:%.*]] = extractvalue { i64, i32 } [[RDTSCP]], 1 |
| 32 | + // LLVM: store i32 [[TSC_AUX]], ptr %{{.*}} |
| 33 | + // LLVM: [[TSC:%.*]] = extractvalue { i64, i32 } [[RDTSCP]], 0 |
| 34 | +} |
| 35 | + |
0 commit comments