1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=i686-unknown-unknown -mattr=+avx | FileCheck %s --check-prefix=X32
3; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefix=X64
4
5define i128 @mulhioverflow(i64 %a, i64 %b, i64 %c) nounwind {
6; X32-LABEL: mulhioverflow:
7; X32:       # %bb.0:
8; X32-NEXT:    pushl %ebp
9; X32-NEXT:    pushl %ebx
10; X32-NEXT:    pushl %edi
11; X32-NEXT:    pushl %esi
12; X32-NEXT:    movl {{[0-9]+}}(%esp), %ecx
13; X32-NEXT:    movl {{[0-9]+}}(%esp), %esi
14; X32-NEXT:    movl {{[0-9]+}}(%esp), %ebp
15; X32-NEXT:    movl {{[0-9]+}}(%esp), %edi
16; X32-NEXT:    movl %ecx, %eax
17; X32-NEXT:    mull %ebp
18; X32-NEXT:    movl %edx, %ebx
19; X32-NEXT:    movl %esi, %eax
20; X32-NEXT:    mull %ebp
21; X32-NEXT:    movl %edx, %ebp
22; X32-NEXT:    movl %eax, %esi
23; X32-NEXT:    addl %ebx, %esi
24; X32-NEXT:    adcl $0, %ebp
25; X32-NEXT:    movl %ecx, %eax
26; X32-NEXT:    mull %edi
27; X32-NEXT:    movl %edx, %ebx
28; X32-NEXT:    addl %esi, %eax
29; X32-NEXT:    adcl %ebp, %ebx
30; X32-NEXT:    setb %al
31; X32-NEXT:    movzbl %al, %ecx
32; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
33; X32-NEXT:    mull %edi
34; X32-NEXT:    movl %edx, %esi
35; X32-NEXT:    movl %eax, %ebp
36; X32-NEXT:    addl %ebx, %ebp
37; X32-NEXT:    adcl %ecx, %esi
38; X32-NEXT:    xorl %ecx, %ecx
39; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
40; X32-NEXT:    mull %ecx
41; X32-NEXT:    movl %edx, %edi
42; X32-NEXT:    movl %eax, %ebx
43; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
44; X32-NEXT:    mull %ecx
45; X32-NEXT:    addl %ebx, %eax
46; X32-NEXT:    adcl %edi, %edx
47; X32-NEXT:    addl %ebp, %eax
48; X32-NEXT:    adcl %esi, %edx
49; X32-NEXT:    movl {{[0-9]+}}(%esp), %ecx
50; X32-NEXT:    andl $1, %ecx
51; X32-NEXT:    addl %eax, %ecx
52; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
53; X32-NEXT:    movl %ecx, (%eax)
54; X32-NEXT:    adcl $0, %edx
55; X32-NEXT:    movl %edx, 4(%eax)
56; X32-NEXT:    setb %cl
57; X32-NEXT:    movzbl %cl, %ecx
58; X32-NEXT:    movl %ecx, 8(%eax)
59; X32-NEXT:    movl $0, 12(%eax)
60; X32-NEXT:    popl %esi
61; X32-NEXT:    popl %edi
62; X32-NEXT:    popl %ebx
63; X32-NEXT:    popl %ebp
64; X32-NEXT:    retl $4
65;
66; X64-LABEL: mulhioverflow:
67; X64:       # %bb.0:
68; X64-NEXT:    movq %rdx, %rcx
69; X64-NEXT:    movq %rdi, %rax
70; X64-NEXT:    mulq %rsi
71; X64-NEXT:    andl $1, %ecx
72; X64-NEXT:    leaq (%rcx,%rdx), %rax
73; X64-NEXT:    xorl %edx, %edx
74; X64-NEXT:    retq
75  %1 = zext i64 %a to i128
76  %2 = zext i64 %b to i128
77  %3 = mul i128 %1, %2
78  %4 = lshr i128 %3, 64
79  %5 = and i64 %c, 1
80  %6 = zext i64 %5 to i128
81  %7 = add i128 %4, %6
82  ret i128 %7
83}
84