[X86] Fix TC_RETURN selection failure for Win+Thunk combination#175977
Merged
[X86] Fix TC_RETURN selection failure for Win+Thunk combination#175977
Conversation
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.
Member
|
@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. 2 Files Affected:
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
approved these changes
Jan 14, 2026
dpaoliello
approved these changes
Jan 14, 2026
| ret void | ||
| } | ||
|
|
||
| attributes #0 = { "target-features"="+retpoline-external-thunk" } |
Contributor
There was a problem hiding this comment.
BTW, Original issue #175965 has
attribute attributes #0 = { "target-features"="+retpoline-indirect-calls" }
Contributor
Author
There was a problem hiding this comment.
The original, non-reduced case had both. I found this variant made for an easier to understand test case than +retpoline-indirect-calls.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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.