Skip to content

RuntimeLibcalls: Fix calling conv of win32 div libcalls #149098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/RuntimeLibcalls.td
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,7 @@ defvar X86CommonLibcalls =
);

defvar Windows32DivRemMulCalls =
LibcallImpls<(add WindowsDivRemMulLibcalls),
LibcallsWithCC<(add WindowsDivRemMulLibcalls), X86_STDCALL,
RuntimeLibcallPredicate<"TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()">>;

def X86_32SystemLibrary
Expand Down
113 changes: 113 additions & 0 deletions llvm/test/CodeGen/X86/win32-int-runtime-libcalls.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck -check-prefix=CHECK32 %s
; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck -check-prefix=CHECK64 %s

define i64 @test_sdiv_i64(i64 %a, i64 %b) {
; CHECK32-LABEL: test_sdiv_i64:
; CHECK32: # %bb.0:
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: calll __alldiv
; CHECK32-NEXT: retl
;
; CHECK64-LABEL: test_sdiv_i64:
; CHECK64: # %bb.0:
; CHECK64-NEXT: movq %rdx, %r8
; CHECK64-NEXT: movq %rcx, %rax
; CHECK64-NEXT: cqto
; CHECK64-NEXT: idivq %r8
; CHECK64-NEXT: retq
%ret = sdiv i64 %a, %b
ret i64 %ret
}

define i64 @test_srem_i64(i64 %a, i64 %b) {
; CHECK32-LABEL: test_srem_i64:
; CHECK32: # %bb.0:
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: calll __allrem
; CHECK32-NEXT: retl
;
; CHECK64-LABEL: test_srem_i64:
; CHECK64: # %bb.0:
; CHECK64-NEXT: movq %rdx, %r8
; CHECK64-NEXT: movq %rcx, %rax
; CHECK64-NEXT: cqto
; CHECK64-NEXT: idivq %r8
; CHECK64-NEXT: movq %rdx, %rax
; CHECK64-NEXT: retq
%ret = srem i64 %a, %b
ret i64 %ret
}

define i64 @test_udiv_i64(i64 %a, i64 %b) {
; CHECK32-LABEL: test_udiv_i64:
; CHECK32: # %bb.0:
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: calll __aulldiv
; CHECK32-NEXT: retl
;
; CHECK64-LABEL: test_udiv_i64:
; CHECK64: # %bb.0:
; CHECK64-NEXT: movq %rdx, %r8
; CHECK64-NEXT: movq %rcx, %rax
; CHECK64-NEXT: xorl %edx, %edx
; CHECK64-NEXT: divq %r8
; CHECK64-NEXT: retq
%ret = udiv i64 %a, %b
ret i64 %ret
}

define i64 @test_urem_i64(i64 %a, i64 %b) {
; CHECK32-LABEL: test_urem_i64:
; CHECK32: # %bb.0:
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
; CHECK32-NEXT: calll __aullrem
; CHECK32-NEXT: retl
;
; CHECK64-LABEL: test_urem_i64:
; CHECK64: # %bb.0:
; CHECK64-NEXT: movq %rdx, %r8
; CHECK64-NEXT: movq %rcx, %rax
; CHECK64-NEXT: xorl %edx, %edx
; CHECK64-NEXT: divq %r8
; CHECK64-NEXT: movq %rdx, %rax
; CHECK64-NEXT: retq
%ret = urem i64 %a, %b
ret i64 %ret
}

define i64 @test_mul_i64(i64 %a, i64 %b) {
; CHECK32-LABEL: test_mul_i64:
; CHECK32: # %bb.0:
; CHECK32-NEXT: pushl %esi
; CHECK32-NEXT: movl {{[0-9]+}}(%esp), %ecx
; CHECK32-NEXT: movl {{[0-9]+}}(%esp), %esi
; CHECK32-NEXT: movl %ecx, %eax
; CHECK32-NEXT: mull %esi
; CHECK32-NEXT: imull {{[0-9]+}}(%esp), %ecx
; CHECK32-NEXT: addl %ecx, %edx
; CHECK32-NEXT: imull {{[0-9]+}}(%esp), %esi
; CHECK32-NEXT: addl %esi, %edx
; CHECK32-NEXT: popl %esi
; CHECK32-NEXT: retl
;
; CHECK64-LABEL: test_mul_i64:
; CHECK64: # %bb.0:
; CHECK64-NEXT: movq %rcx, %rax
; CHECK64-NEXT: imulq %rdx, %rax
; CHECK64-NEXT: retq
%ret = mul i64 %a, %b
ret i64 %ret
}
Loading