RuntimeLibcalls: Fix calling conv of win32 div libcalls#149098
Merged
Conversation
There's probably an existing test this should be added to, but our test coverage is really bad that this wasn't caught by one.
Member
|
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-backend-x86 Author: Matt Arsenault (arsenm) ChangesThere's probably an existing test this should be added to, Full diff: https://github.com/llvm/llvm-project/pull/149098.diff 2 Files Affected:
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 11926d4128fcf..f0297cd1a0873 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -2129,7 +2129,7 @@ defvar X86CommonLibcalls =
);
defvar Windows32DivRemMulCalls =
- LibcallImpls<(add WindowsDivRemMulLibcalls),
+ LibcallsWithCC<(add WindowsDivRemMulLibcalls), X86_STDCALL,
RuntimeLibcallPredicate<"TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()">>;
def X86_32SystemLibrary
diff --git a/llvm/test/CodeGen/X86/win32-int-runtime-libcalls.ll b/llvm/test/CodeGen/X86/win32-int-runtime-libcalls.ll
new file mode 100644
index 0000000000000..86f24ebf6ce86
--- /dev/null
+++ b/llvm/test/CodeGen/X86/win32-int-runtime-libcalls.ll
@@ -0,0 +1,72 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck %s
+
+define i64 @test_sdiv_i64(i64 %a, i64 %b) {
+; CHECK-LABEL: test_sdiv_i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: calll __alldiv
+; CHECK-NEXT: retl
+ %ret = sdiv i64 %a, %b
+ ret i64 %ret
+}
+
+define i64 @test_srem_i64(i64 %a, i64 %b) {
+; CHECK-LABEL: test_srem_i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: calll __allrem
+; CHECK-NEXT: retl
+ %ret = srem i64 %a, %b
+ ret i64 %ret
+}
+
+define i64 @test_udiv_i64(i64 %a, i64 %b) {
+; CHECK-LABEL: test_udiv_i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: calll __aulldiv
+; CHECK-NEXT: retl
+ %ret = udiv i64 %a, %b
+ ret i64 %ret
+}
+
+define i64 @test_urem_i64(i64 %a, i64 %b) {
+; CHECK-LABEL: test_urem_i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: pushl {{[0-9]+}}(%esp)
+; CHECK-NEXT: calll __aullrem
+; CHECK-NEXT: retl
+ %ret = urem i64 %a, %b
+ ret i64 %ret
+}
+
+define i64 @test_mul_i64(i64 %a, i64 %b) {
+; CHECK-LABEL: test_mul_i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: pushl %esi
+; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
+; CHECK-NEXT: movl {{[0-9]+}}(%esp), %esi
+; CHECK-NEXT: movl %ecx, %eax
+; CHECK-NEXT: mull %esi
+; CHECK-NEXT: imull {{[0-9]+}}(%esp), %ecx
+; CHECK-NEXT: addl %ecx, %edx
+; CHECK-NEXT: imull {{[0-9]+}}(%esp), %esi
+; CHECK-NEXT: addl %esi, %edx
+; CHECK-NEXT: popl %esi
+; CHECK-NEXT: retl
+ %ret = mul i64 %a, %b
+ ret i64 %ret
+}
|
compnerd
reviewed
Jul 16, 2025
Member
compnerd
left a comment
There was a problem hiding this comment.
Can you add a test for x64 that ensures that is also called correctly (no stdcall)?
mstorsjo
approved these changes
Jul 16, 2025
Member
mstorsjo
left a comment
There was a problem hiding this comment.
Thanks! This does fix all my observed issues.
compnerd
approved these changes
Jul 16, 2025
Contributor
Author
|
/cherry-pick 0110168 |
Member
|
/pull-request #149246 |
tru
pushed a commit
to llvmbot/llvm-project
that referenced
this pull request
Jul 17, 2025
There's probably an existing test this should be added to, but our test coverage is really bad that this wasn't caught by one. (cherry picked from commit 0110168)
This was referenced Jul 23, 2025
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.

There's probably an existing test this should be added to,
but our test coverage is really bad that this wasn't caught
by one.