1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefix=SSE
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefix=AVX
5 declare {i32, i1} @llvm.smul.with.overflow.i32(i32, i32) nounwind readnone
6 declare {i32, i1} @llvm.umul.with.overflow.i32(i32, i32) nounwind readnone
8 declare {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32>, <4 x i32>) nounwind readnone
9 declare {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32>, <4 x i32>) nounwind readnone
11 ; fold (smulo x, 2) -> (saddo x, x)
12 define i32 @combine_smul_two(i32 %a0, i32 %a1) {
13 ; SSE-LABEL: combine_smul_two:
15 ; SSE-NEXT: movl %edi, %eax
16 ; SSE-NEXT: addl %edi, %eax
17 ; SSE-NEXT: cmovol %esi, %eax
20 ; AVX-LABEL: combine_smul_two:
22 ; AVX-NEXT: movl %edi, %eax
23 ; AVX-NEXT: addl %edi, %eax
24 ; AVX-NEXT: cmovol %esi, %eax
26 %1 = call {i32, i1} @llvm.smul.with.overflow.i32(i32 %a0, i32 2)
27 %2 = extractvalue {i32, i1} %1, 0
28 %3 = extractvalue {i32, i1} %1, 1
29 %4 = select i1 %3, i32 %a1, i32 %2
33 define <4 x i32> @combine_vec_smul_two(<4 x i32> %a0, <4 x i32> %a1) {
34 ; SSE-LABEL: combine_vec_smul_two:
36 ; SSE-NEXT: movdqa %xmm0, %xmm2
37 ; SSE-NEXT: paddd %xmm0, %xmm2
38 ; SSE-NEXT: movdqa %xmm0, %xmm3
39 ; SSE-NEXT: pcmpgtd %xmm2, %xmm3
40 ; SSE-NEXT: pxor %xmm0, %xmm3
41 ; SSE-NEXT: movdqa %xmm3, %xmm0
42 ; SSE-NEXT: blendvps %xmm0, %xmm1, %xmm2
43 ; SSE-NEXT: movaps %xmm2, %xmm0
46 ; AVX-LABEL: combine_vec_smul_two:
48 ; AVX-NEXT: vpaddd %xmm0, %xmm0, %xmm2
49 ; AVX-NEXT: vpcmpgtd %xmm2, %xmm0, %xmm3
50 ; AVX-NEXT: vpxor %xmm3, %xmm0, %xmm0
51 ; AVX-NEXT: vblendvps %xmm0, %xmm1, %xmm2, %xmm0
53 %1 = call {<4 x i32>, <4 x i1>} @llvm.smul.with.overflow.v4i32(<4 x i32> %a0, <4 x i32> <i32 2, i32 2, i32 2, i32 2>)
54 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
55 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
56 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2
60 ; fold (umulo x, 2) -> (uaddo x, x)
61 define i32 @combine_umul_two(i32 %a0, i32 %a1) {
62 ; SSE-LABEL: combine_umul_two:
64 ; SSE-NEXT: movl %edi, %eax
65 ; SSE-NEXT: addl %edi, %eax
66 ; SSE-NEXT: cmovbl %esi, %eax
69 ; AVX-LABEL: combine_umul_two:
71 ; AVX-NEXT: movl %edi, %eax
72 ; AVX-NEXT: addl %edi, %eax
73 ; AVX-NEXT: cmovbl %esi, %eax
75 %1 = call {i32, i1} @llvm.umul.with.overflow.i32(i32 %a0, i32 2)
76 %2 = extractvalue {i32, i1} %1, 0
77 %3 = extractvalue {i32, i1} %1, 1
78 %4 = select i1 %3, i32 %a1, i32 %2
82 define <4 x i32> @combine_vec_umul_two(<4 x i32> %a0, <4 x i32> %a1) {
83 ; SSE-LABEL: combine_vec_umul_two:
85 ; SSE-NEXT: movdqa %xmm0, %xmm2
86 ; SSE-NEXT: paddd %xmm0, %xmm2
87 ; SSE-NEXT: pmaxud %xmm2, %xmm0
88 ; SSE-NEXT: pcmpeqd %xmm2, %xmm0
89 ; SSE-NEXT: blendvps %xmm0, %xmm2, %xmm1
90 ; SSE-NEXT: movaps %xmm1, %xmm0
93 ; AVX-LABEL: combine_vec_umul_two:
95 ; AVX-NEXT: vpaddd %xmm0, %xmm0, %xmm2
96 ; AVX-NEXT: vpmaxud %xmm0, %xmm2, %xmm0
97 ; AVX-NEXT: vpcmpeqd %xmm0, %xmm2, %xmm0
98 ; AVX-NEXT: vblendvps %xmm0, %xmm2, %xmm1, %xmm0
100 %1 = call {<4 x i32>, <4 x i1>} @llvm.umul.with.overflow.v4i32(<4 x i32> %a0, <4 x i32> <i32 2, i32 2, i32 2, i32 2>)
101 %2 = extractvalue {<4 x i32>, <4 x i1>} %1, 0
102 %3 = extractvalue {<4 x i32>, <4 x i1>} %1, 1
103 %4 = select <4 x i1> %3, <4 x i32> %a1, <4 x i32> %2