Skip to content

Commit 2fdf963

Browse files
committed
[GlobalISel] Explicitly fail trying to translate gc.statepoint and related intrinsics
The provided testcase would previously fail with an assertion due to later down below trying to allocate registers for `token` return types and arguments. This is especially problematic as the process would then exit instead of falling back to using FastIsel. This patch fixes that by simply explicitly failing translation if either of these intrinsics are encountered. Fixes llvm/llvm-project#57349 Differential Revision: https://reviews.llvm.org/D132974
1 parent f80a0ea commit 2fdf963

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "llvm/IR/LLVMContext.h"
6262
#include "llvm/IR/Metadata.h"
6363
#include "llvm/IR/PatternMatch.h"
64+
#include "llvm/IR/Statepoint.h"
6465
#include "llvm/IR/Type.h"
6566
#include "llvm/IR/User.h"
6667
#include "llvm/IR/Value.h"
@@ -2403,6 +2404,10 @@ bool IRTranslator::translateCall(const User &U, MachineIRBuilder &MIRBuilder) {
24032404
if (CI.countOperandBundlesOfType(LLVMContext::OB_cfguardtarget))
24042405
return false;
24052406

2407+
// FIXME: support statepoints and related.
2408+
if (isa<GCStatepointInst, GCRelocateInst, GCResultInst>(U))
2409+
return false;
2410+
24062411
if (CI.isInlineAsm())
24072412
return translateInlineAsm(CI, MIRBuilder);
24082413

llvm/test/CodeGen/AArch64/GlobalISel/arm64-fallback.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ entry:
141141
ret i1 %obit
142142
}
143143

144+
; FALLBACK-WITH-REPORT-ERR: remark: <unknown>:0:0: unable to translate instruction: {{.*}}llvm.experimental.gc.statepoint{{.*}} (in function: gc_intr)
145+
; FALLBACK-WITH-REPORT-ERR: warning: Instruction selection used fallback path for gc_intr
146+
; FALLBACK-WITH-REPORT-OUT-LABEL: gc_intr
147+
148+
declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, i32()*, i32 immarg, i32 immarg, ...)
149+
declare i32 @llvm.experimental.gc.result(token)
150+
151+
declare i32 @extern_returning_i32()
152+
153+
define i32 @gc_intr() gc "statepoint-example" {
154+
%statepoint_token = call token (i64, i32, i32()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, i32()* elementtype(i32 ()) @extern_returning_i32, i32 0, i32 0, i32 0, i32 0) [ "deopt"() ]
155+
%ret = call i32 (token) @llvm.experimental.gc.result(token %statepoint_token)
156+
ret i32 %ret
157+
}
158+
144159
attributes #1 = { "target-features"="+sve" }
145160
attributes #2 = { "target-features"="+ls64" }
146161

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -global-isel -global-isel-abort=2 -mtriple aarch64-unknown-unknown -verify-machineinstrs %s -o - | FileCheck %s
3+
4+
define i32 @__init__() gc "statepoint-example" {
5+
; CHECK-LABEL: __init__:
6+
; CHECK: // %bb.0:
7+
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
8+
; CHECK-NEXT: .cfi_def_cfa_offset 16
9+
; CHECK-NEXT: .cfi_offset w30, -16
10+
; CHECK-NEXT: bl builtins.__init__
11+
; CHECK-NEXT: .Ltmp0:
12+
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
13+
; CHECK-NEXT: ret
14+
%statepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 2882400000, i32 0, ptr elementtype(i32 ()) @builtins.__init__, i32 0, i32 0, i32 0, i32 0) [ "deopt"() ]
15+
%ret = call i32 (token) @llvm.experimental.gc.result(token %statepoint_token)
16+
ret i32 %ret
17+
}
18+
19+
declare i32 @builtins.__init__()
20+
21+
declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)
22+
declare i32 @llvm.experimental.gc.result(token)

0 commit comments

Comments
 (0)