[PATCH] D132974: [GlobalISel] Explicitly fail trying to translate `gc.statepoint` and related intrinsics

Markus Böck via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 14:08:09 PDT 2022


zero9178 created this revision.
zero9178 added reviewers: paquette, t.p.northover, arsenm, aemerson.
Herald added subscribers: hiraditya, rovka.
Herald added a project: All.
zero9178 requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

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 https://github.com/llvm/llvm-project/issues/57349

-----

Another attempt of mine modified the code below to avoid allocating registers for `token` types. I felt like that approach was more fragile however and would essentially turn to dead code in a future where these intrinsics get a custom lowering.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132974

Files:
  llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
  llvm/test/CodeGen/AArch64/GlobalISel/pr57349.ll


Index: llvm/test/CodeGen/AArch64/GlobalISel/pr57349.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/GlobalISel/pr57349.ll
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -global-isel -global-isel-abort=2 -mtriple aarch64-unknown-unknown -verify-machineinstrs %s -o - | FileCheck %s
+
+define i32 @__init__() gc "statepoint-example" {
+; CHECK-LABEL: __init__:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:    .cfi_def_cfa_offset 16
+; CHECK-NEXT:    .cfi_offset w30, -16
+; CHECK-NEXT:    bl builtins.__init__
+; CHECK-NEXT:  .Ltmp0:
+; CHECK-NEXT:    ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT:    ret
+  %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"() ]
+  %ret = call i32 (token) @llvm.experimental.gc.result(token %statepoint_token)
+  ret i32 %ret
+}
+
+declare i32 @builtins.__init__()
+
+declare token @llvm.experimental.gc.statepoint.p0(i64 immarg, i32 immarg, ptr, i32 immarg, i32 immarg, ...)
+declare i32 @llvm.experimental.gc.result(token)
Index: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -61,6 +61,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/Statepoint.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/User.h"
 #include "llvm/IR/Value.h"
@@ -2403,6 +2404,10 @@
   if (CI.countOperandBundlesOfType(LLVMContext::OB_cfguardtarget))
     return false;
 
+  // FIXME: support statepoints and related.
+  if (isa<GCStatepointInst, GCRelocateInst, GCResultInst>(U))
+    return false;
+
   if (CI.isInlineAsm())
     return translateInlineAsm(CI, MIRBuilder);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132974.456789.patch
Type: text/x-patch
Size: 2075 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220830/00efb7ec/attachment.bin>


More information about the llvm-commits mailing list