mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[InstCombine] Fix !prof metadata preservation for invokes
Summary: Bug noticed by inspection. Extend the test to handle invokes as well as calls, and rewrite it to not depend on the inliner and other passes. Also simplify the call site replacement code with CallSite, similar to what I did to dead arg elimination and arg promotion (rL300235 and rL300229). Reviewers: danielcdh, davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32041 llvm-svn: 300251
This commit is contained in:
parent
0e412c4065
commit
13283fefe6
@ -4122,29 +4122,27 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
|||||||
SmallVector<OperandBundleDef, 1> OpBundles;
|
SmallVector<OperandBundleDef, 1> OpBundles;
|
||||||
CS.getOperandBundlesAsDefs(OpBundles);
|
CS.getOperandBundlesAsDefs(OpBundles);
|
||||||
|
|
||||||
Instruction *NC;
|
CallSite NewCS;
|
||||||
if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
|
if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
|
||||||
NC = Builder->CreateInvoke(Callee, II->getNormalDest(), II->getUnwindDest(),
|
NewCS = Builder->CreateInvoke(Callee, II->getNormalDest(),
|
||||||
Args, OpBundles);
|
II->getUnwindDest(), Args, OpBundles);
|
||||||
NC->takeName(II);
|
|
||||||
cast<InvokeInst>(NC)->setCallingConv(II->getCallingConv());
|
|
||||||
cast<InvokeInst>(NC)->setAttributes(NewCallerPAL);
|
|
||||||
} else {
|
} else {
|
||||||
CallInst *CI = cast<CallInst>(Caller);
|
NewCS = Builder->CreateCall(Callee, Args, OpBundles);
|
||||||
NC = Builder->CreateCall(Callee, Args, OpBundles);
|
cast<CallInst>(NewCS.getInstruction())
|
||||||
NC->takeName(CI);
|
->setTailCallKind(cast<CallInst>(Caller)->getTailCallKind());
|
||||||
// Preserve the weight metadata for the new call instruction. The metadata
|
|
||||||
// is used by SamplePGO to check callsite's hotness.
|
|
||||||
uint64_t W;
|
|
||||||
if (CI->extractProfTotalWeight(W))
|
|
||||||
NC->setProfWeight(W);
|
|
||||||
|
|
||||||
cast<CallInst>(NC)->setTailCallKind(CI->getTailCallKind());
|
|
||||||
cast<CallInst>(NC)->setCallingConv(CI->getCallingConv());
|
|
||||||
cast<CallInst>(NC)->setAttributes(NewCallerPAL);
|
|
||||||
}
|
}
|
||||||
|
NewCS->takeName(Caller);
|
||||||
|
NewCS.setCallingConv(CS.getCallingConv());
|
||||||
|
NewCS.setAttributes(NewCallerPAL);
|
||||||
|
|
||||||
|
// Preserve the weight metadata for the new call instruction. The metadata
|
||||||
|
// is used by SamplePGO to check callsite's hotness.
|
||||||
|
uint64_t W;
|
||||||
|
if (Caller->extractProfTotalWeight(W))
|
||||||
|
NewCS->setProfWeight(W);
|
||||||
|
|
||||||
// Insert a cast of the return type as necessary.
|
// Insert a cast of the return type as necessary.
|
||||||
|
Instruction *NC = NewCS.getInstruction();
|
||||||
Value *NV = NC;
|
Value *NV = NC;
|
||||||
if (OldRetTy != NV->getType() && !Caller->use_empty()) {
|
if (OldRetTy != NV->getType() && !Caller->use_empty()) {
|
||||||
if (!NV->getType()->isVoidTy()) {
|
if (!NV->getType()->isVoidTy()) {
|
||||||
|
@ -1,23 +1,38 @@
|
|||||||
; RUN: opt -instcombine -inline -S -inline-threshold=0 -hot-callsite-threshold=100 < %s | FileCheck %s
|
; RUN: opt -S -instcombine < %s | FileCheck %s
|
||||||
; Checks if VP profile is used for hotness checks in inlining after instcombine
|
|
||||||
; converted the call to a direct call.
|
|
||||||
|
|
||||||
declare void @bar(i16 *)
|
; Check that instcombine preserves !prof metadata when removing function
|
||||||
|
; prototype casts.
|
||||||
|
|
||||||
define void @foo(i16* %a) {
|
declare i32 @__gxx_personality_v0(...)
|
||||||
call void @bar(i16* %a)
|
declare void @__cxa_call_unexpected(i8*)
|
||||||
call void @bar(i16* %a)
|
declare void @foo(i16* %a)
|
||||||
ret void
|
|
||||||
}
|
|
||||||
|
|
||||||
; CHECK-LABEL: @test()
|
; CHECK-LABEL: @test_call()
|
||||||
; CHECK-NEXT: call void @bar
|
; CHECK: call void @foo(i16* null), !prof ![[PROF:[0-9]+]]
|
||||||
; CHECK-NEXT: call void @bar
|
define void @test_call() {
|
||||||
define void @test() {
|
|
||||||
call void bitcast (void (i16*)* @foo to void (i8*)*) (i8* null), !prof !0
|
call void bitcast (void (i16*)* @foo to void (i8*)*) (i8* null), !prof !0
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: @test_invoke()
|
||||||
|
; CHECK: invoke void @foo(i16* null)
|
||||||
|
; CHECK-NEXT: to label %done unwind label %lpad, !prof ![[PROF]]
|
||||||
|
define void @test_invoke() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
|
||||||
|
invoke void bitcast (void (i16*)* @foo to void (i8*)*) (i8* null)
|
||||||
|
to label %done unwind label %lpad, !prof !0
|
||||||
|
|
||||||
|
done:
|
||||||
|
ret void
|
||||||
|
|
||||||
|
lpad:
|
||||||
|
%lp = landingpad { i8*, i32 }
|
||||||
|
filter [0 x i8*] zeroinitializer
|
||||||
|
%ehptr = extractvalue { i8*, i32 } %lp, 0
|
||||||
|
tail call void @__cxa_call_unexpected(i8* %ehptr) noreturn nounwind
|
||||||
|
unreachable
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK: ![[PROF]] = !{!"branch_weights", i32 2000}
|
||||||
!0 = !{!"VP", i32 0, i64 2000, i64 -3913987384944532146, i64 2000}
|
!0 = !{!"VP", i32 0, i64 2000, i64 -3913987384944532146, i64 2000}
|
||||||
|
|
||||||
!llvm.module.flags = !{!1}
|
!llvm.module.flags = !{!1}
|
||||||
|
Loading…
Reference in New Issue
Block a user