https://github.com/llvmbot created 
https://github.com/llvm/llvm-project/pull/210318

Backport 23b0281d75a4320a4e6e3d837edf94911d98d252

Requested by: @nikic

>From 4569a7c75e7ac10c046ab4f9b7977fa6db4f1540 Mon Sep 17 00:00:00 2001
From: Nikita Popov <[email protected]>
Date: Fri, 17 Jul 2026 14:34:11 +0200
Subject: [PATCH] [X86] Fix assertion failure for tail call on i686+pic
 (#210302)

The pattern for TCRETURNmi has a IsNotPIC predicate, but the
checkTCRetEnoughRegs() predicate that's part of the X86tcret_enough_regs
PatFrag is evaluated first, so we can't assert that PIC is disabled
here. We should just return false in that case.

Fixes https://github.com/llvm/llvm-project/issues/210300.

(cherry picked from commit 23b0281d75a4320a4e6e3d837edf94911d98d252)
---
 llvm/lib/Target/X86/X86ISelDAGToDAG.cpp    |  3 ++-
 llvm/test/CodeGen/X86/tailcall-i686-pic.ll | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/X86/tailcall-i686-pic.ll

diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp 
b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
index b794567f6a047..9a0045367a8bf 100644
--- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
+++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -3561,7 +3561,8 @@ bool X86DAGToDAGISel::checkTCRetEnoughRegs(SDNode *N) 
const {
       LoadGPRs -= 2; // Base is fixed index off ESP; no regs needed.
     } else if (BasePtr.getOpcode() == X86ISD::Wrapper &&
                isa<GlobalAddressSDNode>(BasePtr->getOperand(0))) {
-      assert(!getTargetMachine().isPositionIndependent());
+      if (getTargetMachine().isPositionIndependent())
+        return false;
       LoadGPRs -= 1; // Base is a global (immediate since this is non-PIC), no
                      // reg needed.
     }
diff --git a/llvm/test/CodeGen/X86/tailcall-i686-pic.ll 
b/llvm/test/CodeGen/X86/tailcall-i686-pic.ll
new file mode 100644
index 0000000000000..b8a4207451e8a
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tailcall-i686-pic.ll
@@ -0,0 +1,14 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 6
+; RUN: llc -mtriple=i686-pc-windows-msvc -relocation-model=pic < %s | 
FileCheck %s
+
+@fnptr = external global ptr
+
+define void @test() {
+; CHECK-LABEL: test:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    movl _fnptr, %eax
+; CHECK-NEXT:    jmpl *%eax # TAILCALL
+  %p = load ptr, ptr @fnptr
+  tail call void %p()
+  ret void
+}

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to