[llvm] [X86] Fix assertion failure for tail call on i686+pic (PR #210302)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 17 03:57:25 PDT 2026
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/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.
>From 23a28b6f6ef4f33933ee6ebf21ce615d39696c32 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Fri, 17 Jul 2026 12:52:47 +0200
Subject: [PATCH] [X86] Fix assertion failure for tail call on i686+pic
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.
---
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
+
+ at 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
+}
More information about the llvm-commits
mailing list