Skip to content

Commit e20462a

Browse files
danilamlarsenm
andauthored
[StatepointLowering] Use Constant instead of TargetConstant for undef value (#81635)
Prevents isel errors when trying to lower gc relocate of undef value (which turns into CopyToReg of TargetConstant). Such relocates may occur after DCE (e.g. after GVN removes some dead blocks) if there are not passes like instcombine scheduled after to clean them up. Fixes #80294 --------- Co-authored-by: Matt Arsenault <[email protected]>
1 parent f79f58d commit e20462a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ void SelectionDAGBuilder::visitGCRelocate(const GCRelocateInst &Relocate) {
12871287
if (SD.isUndef() && SD.getValueType().getSizeInBits() <= 64) {
12881288
// Lowering relocate(undef) as arbitrary constant. Current constant value
12891289
// is chosen such that it's unlikely to be a valid pointer.
1290-
setValue(&Relocate, DAG.getTargetConstant(0xFEFEFEFE, SDLoc(SD), MVT::i64));
1290+
setValue(&Relocate, DAG.getConstant(0xFEFEFEFE, SDLoc(SD), MVT::i64));
12911291
return;
12921292
}
12931293

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -verify-machineinstrs < %s | FileCheck %s
3+
4+
target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
5+
target triple = "x86_64-pc-linux-gnu"
6+
7+
declare void @use(...)
8+
declare void @f()
9+
declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
10+
declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32)
11+
12+
;; Check that llvm doesn't crash if relocate with undef base/derived ptr survives until isel
13+
define void @test_gcrelocate_undef(ptr addrspace(1) %ptr) gc "statepoint-example" {
14+
; CHECK-LABEL: test_gcrelocate_undef:
15+
; CHECK: # %bb.0:
16+
; CHECK-NEXT: pushq %rax
17+
; CHECK-NEXT: .cfi_def_cfa_offset 16
18+
; CHECK-NEXT: movq %rdi, (%rsp)
19+
; CHECK-NEXT: callq f@PLT
20+
; CHECK-NEXT: .Ltmp0:
21+
; CHECK-NEXT: movl $4278124286, %edi # imm = 0xFEFEFEFE
22+
; CHECK-NEXT: xorl %eax, %eax
23+
; CHECK-NEXT: callq use@PLT
24+
; CHECK-NEXT: popq %rax
25+
; CHECK-NEXT: .cfi_def_cfa_offset 8
26+
; CHECK-NEXT: retq
27+
%tok = tail call token (i64, i32, ptr, i32, i32, ...)
28+
@llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @f, i32 0, i32 0, i32 0, i32 0) ["gc-live" (ptr addrspace(1) %ptr, ptr addrspace(1) undef), "deopt" (ptr addrspace(1) %ptr, i32 undef)]
29+
%a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %tok, i32 0, i32 1)
30+
call void (...) @use(ptr addrspace(1) %a)
31+
ret void
32+
}

0 commit comments

Comments
 (0)