Skip to content

Commit 7c2c20d

Browse files
arsenmtru
authored andcommitted
RuntimeLibcalls: Fix calling conv of win32 div libcalls (#149098)
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)
1 parent 46c566f commit 7c2c20d

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,7 @@ defvar X86CommonLibcalls =
21202120
);
21212121

21222122
defvar Windows32DivRemMulCalls =
2123-
LibcallImpls<(add WindowsDivRemMulLibcalls),
2123+
LibcallsWithCC<(add WindowsDivRemMulLibcalls), X86_STDCALL,
21242124
RuntimeLibcallPredicate<"TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment()">>;
21252125

21262126
def X86_32SystemLibrary
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=i686-windows-msvc < %s | FileCheck -check-prefix=CHECK32 %s
3+
; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck -check-prefix=CHECK64 %s
4+
5+
define i64 @test_sdiv_i64(i64 %a, i64 %b) {
6+
; CHECK32-LABEL: test_sdiv_i64:
7+
; CHECK32: # %bb.0:
8+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
9+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
10+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
11+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
12+
; CHECK32-NEXT: calll __alldiv
13+
; CHECK32-NEXT: retl
14+
;
15+
; CHECK64-LABEL: test_sdiv_i64:
16+
; CHECK64: # %bb.0:
17+
; CHECK64-NEXT: movq %rdx, %r8
18+
; CHECK64-NEXT: movq %rcx, %rax
19+
; CHECK64-NEXT: cqto
20+
; CHECK64-NEXT: idivq %r8
21+
; CHECK64-NEXT: retq
22+
%ret = sdiv i64 %a, %b
23+
ret i64 %ret
24+
}
25+
26+
define i64 @test_srem_i64(i64 %a, i64 %b) {
27+
; CHECK32-LABEL: test_srem_i64:
28+
; CHECK32: # %bb.0:
29+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
30+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
31+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
32+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
33+
; CHECK32-NEXT: calll __allrem
34+
; CHECK32-NEXT: retl
35+
;
36+
; CHECK64-LABEL: test_srem_i64:
37+
; CHECK64: # %bb.0:
38+
; CHECK64-NEXT: movq %rdx, %r8
39+
; CHECK64-NEXT: movq %rcx, %rax
40+
; CHECK64-NEXT: cqto
41+
; CHECK64-NEXT: idivq %r8
42+
; CHECK64-NEXT: movq %rdx, %rax
43+
; CHECK64-NEXT: retq
44+
%ret = srem i64 %a, %b
45+
ret i64 %ret
46+
}
47+
48+
define i64 @test_udiv_i64(i64 %a, i64 %b) {
49+
; CHECK32-LABEL: test_udiv_i64:
50+
; CHECK32: # %bb.0:
51+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
52+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
53+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
54+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
55+
; CHECK32-NEXT: calll __aulldiv
56+
; CHECK32-NEXT: retl
57+
;
58+
; CHECK64-LABEL: test_udiv_i64:
59+
; CHECK64: # %bb.0:
60+
; CHECK64-NEXT: movq %rdx, %r8
61+
; CHECK64-NEXT: movq %rcx, %rax
62+
; CHECK64-NEXT: xorl %edx, %edx
63+
; CHECK64-NEXT: divq %r8
64+
; CHECK64-NEXT: retq
65+
%ret = udiv i64 %a, %b
66+
ret i64 %ret
67+
}
68+
69+
define i64 @test_urem_i64(i64 %a, i64 %b) {
70+
; CHECK32-LABEL: test_urem_i64:
71+
; CHECK32: # %bb.0:
72+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
73+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
74+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
75+
; CHECK32-NEXT: pushl {{[0-9]+}}(%esp)
76+
; CHECK32-NEXT: calll __aullrem
77+
; CHECK32-NEXT: retl
78+
;
79+
; CHECK64-LABEL: test_urem_i64:
80+
; CHECK64: # %bb.0:
81+
; CHECK64-NEXT: movq %rdx, %r8
82+
; CHECK64-NEXT: movq %rcx, %rax
83+
; CHECK64-NEXT: xorl %edx, %edx
84+
; CHECK64-NEXT: divq %r8
85+
; CHECK64-NEXT: movq %rdx, %rax
86+
; CHECK64-NEXT: retq
87+
%ret = urem i64 %a, %b
88+
ret i64 %ret
89+
}
90+
91+
define i64 @test_mul_i64(i64 %a, i64 %b) {
92+
; CHECK32-LABEL: test_mul_i64:
93+
; CHECK32: # %bb.0:
94+
; CHECK32-NEXT: pushl %esi
95+
; CHECK32-NEXT: movl {{[0-9]+}}(%esp), %ecx
96+
; CHECK32-NEXT: movl {{[0-9]+}}(%esp), %esi
97+
; CHECK32-NEXT: movl %ecx, %eax
98+
; CHECK32-NEXT: mull %esi
99+
; CHECK32-NEXT: imull {{[0-9]+}}(%esp), %ecx
100+
; CHECK32-NEXT: addl %ecx, %edx
101+
; CHECK32-NEXT: imull {{[0-9]+}}(%esp), %esi
102+
; CHECK32-NEXT: addl %esi, %edx
103+
; CHECK32-NEXT: popl %esi
104+
; CHECK32-NEXT: retl
105+
;
106+
; CHECK64-LABEL: test_mul_i64:
107+
; CHECK64: # %bb.0:
108+
; CHECK64-NEXT: movq %rcx, %rax
109+
; CHECK64-NEXT: imulq %rdx, %rax
110+
; CHECK64-NEXT: retq
111+
%ret = mul i64 %a, %b
112+
ret i64 %ret
113+
}

0 commit comments

Comments
 (0)