From ecf2e2fe312a5dd297e6c0c78b89c98cf1073b0d Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 7 Sep 2018 19:14:24 +0000 Subject: [PATCH] [X86] Custom emit __builtin_rdtscp so we can emit an explicit store for the out parameter This is the clang side of D51803. The llvm intrinsic now returns two results. So we need to emit an explicit store in IR for the out parameter. This is similar to addcarry/subborrow/rdrand/rdseed. Differential Revision: https://reviews.llvm.org/D51805 llvm-svn: 341699 --- clang/lib/CodeGen/CGBuiltin.cpp | 6 ++++++ clang/test/CodeGen/rd-builtins.c | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index a472bf59d717..90505ac088d8 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -9158,6 +9158,12 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, case X86::BI__rdtsc: { return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_rdtsc)); } + case X86::BI__builtin_ia32_rdtscp: { + Value *Call = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_rdtscp)); + Builder.CreateDefaultAlignedStore(Builder.CreateExtractValue(Call, 1), + Ops[0]); + return Builder.CreateExtractValue(Call, 0); + } case X86::BI__builtin_ia32_undef128: case X86::BI__builtin_ia32_undef256: case X86::BI__builtin_ia32_undef512: diff --git a/clang/test/CodeGen/rd-builtins.c b/clang/test/CodeGen/rd-builtins.c index 0d7cd04d6f26..38e0886f0325 100644 --- a/clang/test/CodeGen/rd-builtins.c +++ b/clang/test/CodeGen/rd-builtins.c @@ -14,3 +14,12 @@ int test_rdtsc() { // CHECK: @test_rdtsc // CHECK: call i64 @llvm.x86.rdtsc } + +unsigned long long test_rdtscp(unsigned int *a) { +// CHECK: @test_rdtscp +// CHECK: [[RDTSCP:%.*]] = call { i64, i32 } @llvm.x86.rdtscp +// CHECK: [[TSC_AUX:%.*]] = extractvalue { i64, i32 } [[RDTSCP]], 1 +// CHECK: store i32 [[TSC_AUX]], i32* %{{.*}} +// CHECK: [[TSC:%.*]] = extractvalue { i64, i32 } [[RDTSCP]], 0 + return __rdtscp(a); +}