Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GC] Remove buggy untested optimization from statepoint lowering
A downstream test case (see included reduced test) revealed that we have a bug in how we handle duplicate relocations. If we have the same SDValue relocated twice, and that value happens to be a constant (such as null), we only export one of the two llvm::Values. Exporting on a per llvm::Value basis is required to allow lowering of gc.relocates in following basic blocks (e.g. invokes). Without it, we end up with a use of an undefined vreg and bad things happen. Rather than fixing the optimization - which appears to be hard - I propose we simply remove it. There are no tests in tree that change with this code removed. If we find out later that this did matter for something, we can reimplement a variation of this in CodeGenPrepare to catch the easy cases without complicating the lowering code. Thanks to Denis and Serguei who did all the hard work of figuring out what went wrong here. The patch is by far the easy part. :) Differential Revision: https://reviews.llvm.org/D75964
- Loading branch information
Showing
3 changed files
with
90 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -verify-machineinstrs < %s | FileCheck %s | ||
|
||
; Check that we can export values of "duplicated" gc.relocates without a crash | ||
; "duplicate" here means maps to same SDValue. We previously had an | ||
; optimization which tried to reduce number of spills/stackmap entries in such | ||
; cases, but it incorrectly handled exports across basis block boundaries | ||
; leading to a crash in this case. | ||
|
||
target triple = "x86_64-pc-linux-gnu" | ||
|
||
declare void @func() | ||
|
||
define i1 @test() gc "statepoint-example" { | ||
; CHECK-LABEL: test: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: pushq %rax | ||
; CHECK-NEXT: .cfi_def_cfa_offset 16 | ||
; CHECK-NEXT: callq func | ||
; CHECK-NEXT: .Ltmp0: | ||
; CHECK-NEXT: callq func | ||
; CHECK-NEXT: .Ltmp1: | ||
; CHECK-NEXT: movb $1, %al | ||
; CHECK-NEXT: popq %rcx | ||
; CHECK-NEXT: .cfi_def_cfa_offset 8 | ||
; CHECK-NEXT: retq | ||
entry: | ||
%safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* null, i32 addrspace(1)* null) | ||
%base = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 7) | ||
%derived = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 8) | ||
%safepoint_token2 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %base, i32 addrspace(1)* %derived) | ||
br label %next | ||
|
||
next: | ||
%base_reloc = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 7, i32 7) | ||
%derived_reloc = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 7, i32 8) | ||
%cmp1 = icmp eq i32 addrspace(1)* %base_reloc, null | ||
%cmp2 = icmp eq i32 addrspace(1)* %derived_reloc, null | ||
%cmp = and i1 %cmp1, %cmp2 | ||
ret i1 %cmp | ||
} | ||
|
||
; Showing redundant fill on first statepoint and spill/fill on second one | ||
define i1 @test2(i32 addrspace(1)* %arg) gc "statepoint-example" { | ||
; CHECK-LABEL: test2: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: subq $24, %rsp | ||
; CHECK-NEXT: .cfi_def_cfa_offset 32 | ||
; CHECK-NEXT: movq %rdi, {{[0-9]+}}(%rsp) | ||
; CHECK-NEXT: callq func | ||
; CHECK-NEXT: .Ltmp2: | ||
; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rax | ||
; CHECK-NEXT: movq %rax, {{[0-9]+}}(%rsp) | ||
; CHECK-NEXT: callq func | ||
; CHECK-NEXT: .Ltmp3: | ||
; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rax | ||
; CHECK-NEXT: orq {{[0-9]+}}(%rsp), %rax | ||
; CHECK-NEXT: sete %al | ||
; CHECK-NEXT: addq $24, %rsp | ||
; CHECK-NEXT: .cfi_def_cfa_offset 8 | ||
; CHECK-NEXT: retq | ||
entry: | ||
%safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %arg, i32 addrspace(1)* %arg) | ||
%base = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 7) | ||
%derived = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token, i32 7, i32 8) | ||
%safepoint_token2 = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @func, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %base, i32 addrspace(1)* %derived) | ||
br label %next | ||
|
||
next: | ||
%base_reloc = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 7, i32 7) | ||
%derived_reloc = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token %safepoint_token2, i32 7, i32 8) | ||
%cmp1 = icmp eq i32 addrspace(1)* %base_reloc, null | ||
%cmp2 = icmp eq i32 addrspace(1)* %derived_reloc, null | ||
%cmp = and i1 %cmp1, %cmp2 | ||
ret i1 %cmp | ||
} | ||
|
||
|
||
declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...) | ||
declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(token, i32, i32) |