Skip to content

Commit 393c211

Browse files
authored
[StatepointLowering] Use FrameIndex instead of TargetFrameIndex (#153555)
TargetFrameIndex shouldn't be used as an operand to target-independent node such as a load. This causes ISel issues. #81635 fixed a similar issue with this code using a TargetConstant, instead of a Constant. Fixes #142314.
1 parent ae90b60 commit 393c211

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ void SelectionDAGBuilder::visitGCRelocate(const GCRelocateInst &Relocate) {
12581258

12591259
if (Record.type == RecordType::Spill) {
12601260
unsigned Index = Record.payload.FI;
1261-
SDValue SpillSlot = DAG.getTargetFrameIndex(Index, getFrameIndexTy());
1261+
SDValue SpillSlot = DAG.getFrameIndex(Index, getFrameIndexTy());
12621262

12631263
// All the reloads are independent and are reading memory only modified by
12641264
// statepoints (i.e. no other aliasing stores); informing SelectionDAG of

llvm/test/CodeGen/AArch64/pr142314.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=aarch64 | FileCheck %s
3+
4+
; Crash reproducer for: https://github.com/llvm/llvm-project/issues/142314
5+
6+
define <2 x ptr addrspace(1)> @widget() nounwind gc "statepoint-example" {
7+
; CHECK-LABEL: widget:
8+
; CHECK: // %bb.0: // %bb
9+
; CHECK-NEXT: sub sp, sp, #32
10+
; CHECK-NEXT: movi v0.2d, #0000000000000000
11+
; CHECK-NEXT: mov x0, xzr
12+
; CHECK-NEXT: mov x1, xzr
13+
; CHECK-NEXT: str x30, [sp, #16] // 8-byte Folded Spill
14+
; CHECK-NEXT: str q0, [sp]
15+
; CHECK-NEXT: movi d0, #0000000000000000
16+
; CHECK-NEXT: blr xzr
17+
; CHECK-NEXT: .Ltmp0:
18+
; CHECK-NEXT: movi v0.2d, #0000000000000000
19+
; CHECK-NEXT: mov x8, sp
20+
; CHECK-NEXT: ldr x30, [sp, #16] // 8-byte Folded Reload
21+
; CHECK-NEXT: orr x8, x8, #0x8
22+
; CHECK-NEXT: ld1 { v0.d }[1], [x8]
23+
; CHECK-NEXT: add sp, sp, #32
24+
; CHECK-NEXT: ret
25+
bb:
26+
%call31 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i32 (ptr addrspace(1), ptr addrspace(1), double)) null, i32 3, i32 0, ptr addrspace(1) null, ptr addrspace(1) null, double 0.000000e+00, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) null, <2 x ptr addrspace(1)> zeroinitializer, ptr addrspace(1) null) ]
27+
%call4 = call coldcc <2 x ptr addrspace(1)> @llvm.experimental.gc.relocate.v2p1(token %call31, i32 0, i32 1) ; (null, zeroinitializer)
28+
%shufflevector = shufflevector <2 x ptr addrspace(1)> zeroinitializer, <2 x ptr addrspace(1)> %call4, <2 x i32> <i32 0, i32 3>
29+
ret <2 x ptr addrspace(1)> %shufflevector
30+
}
31+
32+
declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)
33+
declare <2 x ptr addrspace(1)> @llvm.experimental.gc.relocate.v2p1(token, i32 immarg, i32 immarg)

llvm/test/CodeGen/X86/pr33010.ll

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ define ptr addrspace(1) @test(ptr addrspace(1) %a, ptr addrspace(1) %b, i1 %whic
1919
; CHECK-NEXT: callq f@PLT
2020
; CHECK-NEXT: .Ltmp0:
2121
; CHECK-NEXT: testb $1, %bl
22-
; CHECK-NEXT: je .LBB0_1
23-
; CHECK-NEXT: # %bb.2: # %entry
24-
; CHECK-NEXT: movq (%rsp), %rax
25-
; CHECK-NEXT: jmp .LBB0_3
26-
; CHECK-NEXT: .LBB0_1:
27-
; CHECK-NEXT: movq {{[0-9]+}}(%rsp), %rax
28-
; CHECK-NEXT: .LBB0_3: # %entry
22+
; CHECK-NEXT: movq %rsp, %rax
23+
; CHECK-NEXT: leaq {{[0-9]+}}(%rsp), %rcx
24+
; CHECK-NEXT: cmovneq %rax, %rcx
25+
; CHECK-NEXT: movq (%rcx), %rax
2926
; CHECK-NEXT: addq $16, %rsp
3027
; CHECK-NEXT: .cfi_def_cfa_offset 16
3128
; CHECK-NEXT: popq %rbx

0 commit comments

Comments
 (0)