Skip to content

Commit

Permalink
[X86] Custom emit __builtin_rdtscp so we can emit an explicit store f…
Browse files Browse the repository at this point in the history
…or 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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341699 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
topperc committed Sep 7, 2018
1 parent 6bc81b9 commit 923d959
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions test/CodeGen/rd-builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 923d959

Please sign in to comment.