Skip to content

[X86] Fix TC_RETURN selection failure for Win+Thunk combination#175977

Merged
nikic merged 1 commit intollvm:mainfrom
nikic:x86-win-retpoline-thunk
Jan 15, 2026
Merged

[X86] Fix TC_RETURN selection failure for Win+Thunk combination#175977
nikic merged 1 commit intollvm:mainfrom
nikic:x86-win-retpoline-thunk

Conversation

@nikic
Copy link
Copy Markdown
Contributor

@nikic nikic commented Jan 14, 2026

#158055 added a IsNotWin64CCFunc predicate to these cases for reasons that are not super clear to me, which causes selection failures as this combination is not covered elsewhere.

Fixes #175965.

Disclaimer: I have no clue what I'm doing here, I just observed that this fixed the selection failure without affecting existing tests.

llvm#158055 added a
IsNotWin64CCFunc predicate to these cases for reasons that are
not super clear to me, which causes selection failures as this
combination is not covered elsewhere.
@nikic nikic requested review from arsenm, rnk and topperc January 14, 2026 16:06
@llvmbot
Copy link
Copy Markdown
Member

llvmbot commented Jan 14, 2026

@llvm/pr-subscribers-backend-x86

Author: Nikita Popov (nikic)

Changes

#158055 added a IsNotWin64CCFunc predicate to these cases for reasons that are not super clear to me, which causes selection failures as this combination is not covered elsewhere.

Fixes #175965.

Disclaimer: I have no clue what I'm doing here, I just observed that this fixed the selection failure without affecting existing tests.


Full diff: https://github.com/llvm/llvm-project/pull/175977.diff

2 Files Affected:

  • (modified) llvm/lib/Target/X86/X86InstrCompiler.td (+2-2)
  • (added) llvm/test/CodeGen/X86/replace-thunk-tail-win.ll (+19)
diff --git a/llvm/lib/Target/X86/X86InstrCompiler.td b/llvm/lib/Target/X86/X86InstrCompiler.td
index ec31675731b79..d3acfc86ab54f 100644
--- a/llvm/lib/Target/X86/X86InstrCompiler.td
+++ b/llvm/lib/Target/X86/X86InstrCompiler.td
@@ -1381,11 +1381,11 @@ def : Pat<(X86tcret_6regs (load addr:$dst), timm:$off),
 
 def : Pat<(X86tcret ptr_rc_tailcall:$dst, timm:$off),
           (INDIRECT_THUNK_TCRETURN64 ptr_rc_tailcall:$dst, timm:$off)>,
-          Requires<[In64BitMode, IsNotWin64CCFunc, UseIndirectThunkCalls]>;
+          Requires<[In64BitMode, UseIndirectThunkCalls]>;
 
 def : Pat<(X86tcret ptr_rc_tailcall:$dst, timm:$off),
           (INDIRECT_THUNK_TCRETURN32 ptr_rc_tailcall:$dst, timm:$off)>,
-          Requires<[Not64BitMode, IsNotWin64CCFunc, UseIndirectThunkCalls]>;
+          Requires<[Not64BitMode, UseIndirectThunkCalls]>;
 
 def : Pat<(X86tcret (i64 tglobaladdr:$dst), timm:$off),
           (TCRETURNdi64 tglobaladdr:$dst, timm:$off)>,
diff --git a/llvm/test/CodeGen/X86/replace-thunk-tail-win.ll b/llvm/test/CodeGen/X86/replace-thunk-tail-win.ll
new file mode 100644
index 0000000000000..e1d2a3425886b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/replace-thunk-tail-win.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s --check-prefix=64BIT
+; RUN: llc -mtriple=i686-unknown-linux-gnu < %s | FileCheck %s --check-prefix=32BIT
+
+define void @test(ptr %g) #0 {
+; 64BIT-LABEL: test:
+; 64BIT:       # %bb.0:
+; 64BIT-NEXT:    movq %rdi, %r11
+; 64BIT-NEXT:    jmp __x86_indirect_thunk_r11 # TAILCALL
+;
+; 32BIT-LABEL: test:
+; 32BIT:       # %bb.0:
+; 32BIT-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; 32BIT-NEXT:    jmp __x86_indirect_thunk_eax # TAILCALL
+  tail call void %g()
+  ret void
+}
+
+attributes #0 = { "target-features"="+retpoline-external-thunk" }

@arsenm arsenm requested a review from dpaoliello January 14, 2026 16:07
ret void
}

attributes #0 = { "target-features"="+retpoline-external-thunk" }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, Original issue #175965 has
attribute attributes #0 = { "target-features"="+retpoline-indirect-calls" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original, non-reduced case had both. I found this variant made for an easier to understand test case than +retpoline-indirect-calls.

@nikic nikic merged commit 2789ad2 into llvm:main Jan 15, 2026
13 checks passed
@nikic nikic deleted the x86-win-retpoline-thunk branch January 15, 2026 08:23
c-rhodes pushed a commit to llvmbot/llvm-project that referenced this pull request Jan 15, 2026
…#175977)

llvm#158055 added a
IsNotWin64CCFunc predicate to these cases for reasons that are not super
clear to me, which causes selection failures as this combination is not
covered elsewhere.

Fixes llvm#175965.

(cherry picked from commit 2789ad2)
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
…#175977)

llvm#158055 added a
IsNotWin64CCFunc predicate to these cases for reasons that are not super
clear to me, which causes selection failures as this combination is not
covered elsewhere.

Fixes llvm#175965.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[X86] Cannot select TC_RETURN with +retpoline-indirect-calls

5 participants