xref: /llvm-project/llvm/test/CodeGen/X86/overflow.ll (revision 683f5743f670ca928ce02a2e417f6a0de89c17b1)
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:    movl %esp, %ebp
10; X32-NEXT:    pushl %edi
11; X32-NEXT:    pushl %esi
12; X32-NEXT:    andl $-8, %esp
13; X32-NEXT:    subl $16, %esp
14; X32-NEXT:    movl 8(%ebp), %esi
15; X32-NEXT:    movl 28(%ebp), %edi
16; X32-NEXT:    movl %esp, %eax
17; X32-NEXT:    pushl $0
18; X32-NEXT:    pushl $0
19; X32-NEXT:    pushl 24(%ebp)
20; X32-NEXT:    pushl 20(%ebp)
21; X32-NEXT:    pushl $0
22; X32-NEXT:    pushl $0
23; X32-NEXT:    pushl 16(%ebp)
24; X32-NEXT:    pushl 12(%ebp)
25; X32-NEXT:    pushl %eax
26; X32-NEXT:    calll __multi3
27; X32-NEXT:    addl $32, %esp
28; X32-NEXT:    movl {{[0-9]+}}(%esp), %eax
29; X32-NEXT:    andl $1, %edi
30; X32-NEXT:    xorl %ecx, %ecx
31; X32-NEXT:    addl {{[0-9]+}}(%esp), %edi
32; X32-NEXT:    adcl $0, %eax
33; X32-NEXT:    adcl $0, %ecx
34; X32-NEXT:    sbbl %edx, %edx
35; X32-NEXT:    andl $1, %edx
36; X32-NEXT:    movl %edi, (%esi)
37; X32-NEXT:    movl %eax, 4(%esi)
38; X32-NEXT:    movl %ecx, 8(%esi)
39; X32-NEXT:    movl %edx, 12(%esi)
40; X32-NEXT:    movl %esi, %eax
41; X32-NEXT:    leal -8(%ebp), %esp
42; X32-NEXT:    popl %esi
43; X32-NEXT:    popl %edi
44; X32-NEXT:    popl %ebp
45; X32-NEXT:    retl $4
46;
47; X64-LABEL: mulhioverflow:
48; X64:       # BB#0:
49; X64-NEXT:    movq %rdx, %rcx
50; X64-NEXT:    movq %rdi, %rax
51; X64-NEXT:    mulq %rsi
52; X64-NEXT:    andl $1, %ecx
53; X64-NEXT:    addq %rdx, %rcx
54; X64-NEXT:    sbbq %rdx, %rdx
55; X64-NEXT:    andl $1, %edx
56; X64-NEXT:    movq %rcx, %rax
57; X64-NEXT:    retq
58  %1 = zext i64 %a to i128
59  %2 = zext i64 %b to i128
60  %3 = mul i128 %1, %2
61  %4 = lshr i128 %3, 64
62  %5 = and i64 %c, 1
63  %6 = zext i64 %5 to i128
64  %7 = add i128 %4, %6
65  ret i128 %7
66}
67