[PATCH] D119644: [X86][Win64] Avoid statepoints in trailing call position

Markus Böck via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 12 11:41:33 PST 2022


zero9178 created this revision.
zero9178 added reviewers: rnk, reames, hans, sanjoy.
Herald added subscribers: pengfei, hiraditya.
zero9178 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The "avoid trailing call pass" makes sure that no function ends with a call instruction for the purpose of the unwinder. 
It starts of by skipping over any non real instruction, which is approximated via the Pseudo and Meta property. This sadly leads to issues when the last machine instruction is a STATEPOINT, as it is skipped despite it lowering to a call.

This patch fixes the use of a statepoint in the trailing call position by making sure it is not skipped.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119644

Files:
  llvm/include/llvm/CodeGen/MachineInstr.h
  llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
  llvm/test/CodeGen/X86/win64-eh-trailing-statepoint.ll


Index: llvm/test/CodeGen/X86/win64-eh-trailing-statepoint.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/win64-eh-trailing-statepoint.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=x86_64-windows-gnu %s -o - | FileCheck %s
+
+; CHECK: foo:
+; CHECK: callq raise
+; CHECK-NEXT: .Ltmp0:
+; CHECK-NEXT: int3
+
+define void @foo() gc "statepoint-example" personality i8* bitcast (i32 (...)* @__gxx_personality_seh0 to i8*) {
+    %statepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 2882400000, i32 0, void ()* elementtype(void ()) @raise, i32 0, i32 0, i32 0, i32 0)
+    unreachable
+}
+
+declare void @raise()
+
+declare dso_local i32 @__gxx_personality_seh0(...)
+
+declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 immarg, i32 immarg, void ()*, i32 immarg, i32 immarg, ...)
Index: llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
===================================================================
--- llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
+++ llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
@@ -70,7 +70,7 @@
 // expand to nothing, and some expand to code. This logic conservatively assumes
 // they might expand to nothing.
 static bool isRealInstruction(MachineInstr &MI) {
-  return !MI.isPseudo() && !MI.isMetaInstruction();
+  return (!MI.isPseudo() && !MI.isMetaInstruction()) || MI.isStatepoint();
 }
 
 // Return true if this is a call instruction, but not a tail call.
Index: llvm/include/llvm/CodeGen/MachineInstr.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineInstr.h
+++ llvm/include/llvm/CodeGen/MachineInstr.h
@@ -1190,6 +1190,8 @@
     return isEHLabel() || isGCLabel() || isAnnotationLabel();
   }
 
+  bool isStatepoint() const { return getOpcode() == TargetOpcode::STATEPOINT; }
+
   bool isCFIInstruction() const {
     return getOpcode() == TargetOpcode::CFI_INSTRUCTION;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119644.408204.patch
Type: text/x-patch
Size: 1993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220212/9f3a8e98/attachment.bin>


More information about the llvm-commits mailing list