[llvm] [X86] Fix assertion failure for tail call on i686+pic (PR #210302)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 17 04:00:13 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-x86
Author: Nikita Popov (nikic)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/210302.diff
2 Files Affected:
- (modified) llvm/lib/Target/X86/X86ISelDAGToDAG.cpp (+2-1)
- (added) llvm/test/CodeGen/X86/tailcall-i686-pic.ll (+14)
``````````diff
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
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/210302
More information about the llvm-commits
mailing list