forked from OSchip/llvm-project
[rs4gc] avoid insert base computation instructions for deopt uses
If we have a value live over a call which is used for deopt at the call, we know that the value must be a base pointer. We can avoid potentially inserting IR to materialize a base for this value. In it's current form, this is mostly a compile time optimization. Building the base pointer graph (and then optimizing it away again) is a relatively expensive operation. We also sometimes end up with better codegen in practice - due to failures in optimizing away the inserted base pointer propogation - but those are optimization bugs we're fixing concurrently. The alternative to this would be to extend the base pointer inference with the ability to generally reuse multiple-base input instructions (phis and selects). That's somewhat invasive and complicated, so we're defering it a bit longer. Differential Revision: https://reviews.llvm.org/D97885
This commit is contained in:
parent
2b50ce1524
commit
99f93dd3a5
|
@ -1236,7 +1236,20 @@ static void findBasePointers(DominatorTree &DT, DefiningValueMapTy &DVCache,
|
|||
CallBase *Call,
|
||||
PartiallyConstructedSafepointRecord &result) {
|
||||
MapVector<Value *, Value *> PointerToBase;
|
||||
findBasePointers(result.LiveSet, PointerToBase, &DT, DVCache);
|
||||
StatepointLiveSetTy PotentiallyDerivedPointers = result.LiveSet;
|
||||
// We assume that all pointers passed to deopt are base pointers; as an
|
||||
// optimization, we can use this to avoid seperately materializing the base
|
||||
// pointer graph. This is only relevant since we're very conservative about
|
||||
// generating new conflict nodes during base pointer insertion. If we were
|
||||
// smarter there, this would be irrelevant.
|
||||
if (auto Opt = Call->getOperandBundle(LLVMContext::OB_deopt))
|
||||
for (Value *V : Opt->Inputs) {
|
||||
if (!PotentiallyDerivedPointers.count(V))
|
||||
continue;
|
||||
PotentiallyDerivedPointers.remove(V);
|
||||
PointerToBase[V] = V;
|
||||
}
|
||||
findBasePointers(PotentiallyDerivedPointers, PointerToBase, &DT, DVCache);
|
||||
|
||||
if (PrintBasePointers) {
|
||||
errs() << "Base Pairs (w/o Relocation):\n";
|
||||
|
|
|
@ -152,4 +152,24 @@ next: ; preds = %merge
|
|||
ret i64 addrspace(1)* %bdv
|
||||
}
|
||||
|
||||
; We know from the deopt use that %bdv must be a base value, and as
|
||||
; result can avoid materializing the extra copy of the BDV phi node.
|
||||
; (Even without a general forward analysis)
|
||||
define i64 addrspace(1)* @test6(i1 %cnd, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj2) gc "statepoint-example" {
|
||||
; CHECK-LABEL: @test6
|
||||
entry:
|
||||
br label %merge
|
||||
|
||||
merge: ; preds = %merge, %entry
|
||||
; CHECK-LABEL: merge:
|
||||
; CHECK-NEXT: phi
|
||||
; CHECK-NEXT: br i1
|
||||
%bdv = phi i64 addrspace(1)* [ %obj, %entry ], [ %obj2, %merge ]
|
||||
br i1 %cnd, label %merge, label %next
|
||||
|
||||
next: ; preds = %merge
|
||||
call void @foo() [ "deopt"(i64 addrspace(1)* %bdv) ]
|
||||
ret i64 addrspace(1)* %bdv
|
||||
}
|
||||
|
||||
declare void @foo()
|
||||
|
|
|
@ -147,24 +147,20 @@ define void @test6() gc "statepoint-example" {
|
|||
; CHECK-NEXT: bb:
|
||||
; CHECK-NEXT: br label [[HEADER:%.*]]
|
||||
; CHECK: header:
|
||||
; CHECK-NEXT: [[TMP_BASE:%.*]] = phi i8 addrspace(1)* [ [[TMP6_BASE:%.*]], [[LATCH:%.*]] ], [ null, [[BB:%.*]] ], !is_base_value !0
|
||||
; CHECK-NEXT: [[TMP:%.*]] = phi i8 addrspace(1)* [ [[TMP6:%.*]], [[LATCH]] ], [ undef, [[BB]] ]
|
||||
; CHECK-NEXT: [[TMP:%.*]] = phi i8 addrspace(1)* [ [[TMP6:%.*]], [[LATCH:%.*]] ], [ undef, [[BB:%.*]] ]
|
||||
; CHECK-NEXT: br label [[BB10:%.*]]
|
||||
; CHECK: bb10:
|
||||
; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @spam, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i8 addrspace(1)* [[TMP]]), "gc-live"(i8 addrspace(1)* [[TMP]], i8 addrspace(1)* [[TMP_BASE]]) ]
|
||||
; CHECK-NEXT: [[TMP_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 0)
|
||||
; CHECK-NEXT: [[TMP_BASE_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 1, i32 1)
|
||||
; CHECK-NEXT: [[STATEPOINT_TOKEN:%.*]] = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* @spam, i32 0, i32 0, i32 0, i32 0) [ "deopt"(i8 addrspace(1)* [[TMP]]), "gc-live"(i8 addrspace(1)* [[TMP]]) ]
|
||||
; CHECK-NEXT: [[TMP_RELOCATED:%.*]] = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token [[STATEPOINT_TOKEN]], i32 0, i32 0)
|
||||
; CHECK-NEXT: br label [[BB25:%.*]]
|
||||
; CHECK: bb25:
|
||||
; CHECK-NEXT: [[STATEPOINT_TOKEN1:%.*]] = call token (i64, i32, <2 x i8 addrspace(1)*> ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_v2p1i8f(i64 2882400000, i32 0, <2 x i8 addrspace(1)*> ()* @baz, i32 0, i32 0, i32 0, i32 0)
|
||||
; CHECK-NEXT: [[TMP262:%.*]] = call <2 x i8 addrspace(1)*> @llvm.experimental.gc.result.v2p1i8(token [[STATEPOINT_TOKEN1]])
|
||||
; CHECK-NEXT: [[BASE_EE:%.*]] = extractelement <2 x i8 addrspace(1)*> [[TMP262]], i32 0, !is_base_value !0
|
||||
; CHECK-NEXT: [[TMP27:%.*]] = extractelement <2 x i8 addrspace(1)*> [[TMP262]], i32 0
|
||||
; CHECK-NEXT: br i1 undef, label [[BB7:%.*]], label [[LATCH]]
|
||||
; CHECK: bb7:
|
||||
; CHECK-NEXT: br label [[LATCH]]
|
||||
; CHECK: latch:
|
||||
; CHECK-NEXT: [[TMP6_BASE]] = phi i8 addrspace(1)* [ [[BASE_EE]], [[BB25]] ], [ [[BASE_EE]], [[BB7]] ], !is_base_value !0
|
||||
; CHECK-NEXT: [[TMP6]] = phi i8 addrspace(1)* [ [[TMP27]], [[BB25]] ], [ [[TMP27]], [[BB7]] ]
|
||||
; CHECK-NEXT: br label [[HEADER]]
|
||||
;
|
||||
|
|
Loading…
Reference in New Issue