1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-linux-gnu < %s | FileCheck %s
4 ; Check that expensive divides are expanded into a more performant sequence
10 define <vscale x 16 x i8> @sdiv_i8(<vscale x 16 x i8> %a) #0 {
11 ; CHECK-LABEL: sdiv_i8:
13 ; CHECK-NEXT: ptrue p0.b
14 ; CHECK-NEXT: mov z1.b, #86 // =0x56
15 ; CHECK-NEXT: smulh z0.b, p0/m, z0.b, z1.b
16 ; CHECK-NEXT: lsr z1.b, z0.b, #7
17 ; CHECK-NEXT: add z0.b, z0.b, z1.b
19 %div = sdiv <vscale x 16 x i8> %a, shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> undef, i8 3, i32 0), <vscale x 16 x i8> undef, <vscale x 16 x i32> zeroinitializer)
20 ret <vscale x 16 x i8> %div
23 define <vscale x 8 x i16> @sdiv_i16(<vscale x 8 x i16> %a) #0 {
24 ; CHECK-LABEL: sdiv_i16:
26 ; CHECK-NEXT: ptrue p0.h
27 ; CHECK-NEXT: mov w8, #21846 // =0x5556
28 ; CHECK-NEXT: mov z1.h, w8
29 ; CHECK-NEXT: smulh z0.h, p0/m, z0.h, z1.h
30 ; CHECK-NEXT: lsr z1.h, z0.h, #15
31 ; CHECK-NEXT: add z0.h, z0.h, z1.h
33 %div = sdiv <vscale x 8 x i16> %a, shufflevector (<vscale x 8 x i16> insertelement (<vscale x 8 x i16> undef, i16 3, i32 0), <vscale x 8 x i16> undef, <vscale x 8 x i32> zeroinitializer)
34 ret <vscale x 8 x i16> %div
37 define <vscale x 4 x i32> @sdiv_i32(<vscale x 4 x i32> %a) #0 {
38 ; CHECK-LABEL: sdiv_i32:
40 ; CHECK-NEXT: ptrue p0.s
41 ; CHECK-NEXT: mov w8, #21846 // =0x5556
42 ; CHECK-NEXT: movk w8, #21845, lsl #16
43 ; CHECK-NEXT: mov z1.s, w8
44 ; CHECK-NEXT: smulh z0.s, p0/m, z0.s, z1.s
45 ; CHECK-NEXT: lsr z1.s, z0.s, #31
46 ; CHECK-NEXT: add z0.s, z0.s, z1.s
48 %div = sdiv <vscale x 4 x i32> %a, shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 3, i32 0), <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer)
49 ret <vscale x 4 x i32> %div
52 define <vscale x 2 x i64> @sdiv_i64(<vscale x 2 x i64> %a) #0 {
53 ; CHECK-LABEL: sdiv_i64:
55 ; CHECK-NEXT: ptrue p0.d
56 ; CHECK-NEXT: mov x8, #6148914691236517205 // =0x5555555555555555
57 ; CHECK-NEXT: movk x8, #21846
58 ; CHECK-NEXT: mov z1.d, x8
59 ; CHECK-NEXT: smulh z0.d, p0/m, z0.d, z1.d
60 ; CHECK-NEXT: lsr z1.d, z0.d, #63
61 ; CHECK-NEXT: add z0.d, z0.d, z1.d
63 %div = sdiv <vscale x 2 x i64> %a, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 3, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer)
64 ret <vscale x 2 x i64> %div
71 define <vscale x 16 x i8> @udiv_i8(<vscale x 16 x i8> %a) #0 {
72 ; CHECK-LABEL: udiv_i8:
74 ; CHECK-NEXT: ptrue p0.b
75 ; CHECK-NEXT: mov z1.b, #-85 // =0xffffffffffffffab
76 ; CHECK-NEXT: umulh z0.b, p0/m, z0.b, z1.b
77 ; CHECK-NEXT: lsr z0.b, z0.b, #1
79 %div = udiv <vscale x 16 x i8> %a, shufflevector (<vscale x 16 x i8> insertelement (<vscale x 16 x i8> undef, i8 3, i32 0), <vscale x 16 x i8> undef, <vscale x 16 x i32> zeroinitializer)
80 ret <vscale x 16 x i8> %div
83 define <vscale x 8 x i16> @udiv_i16(<vscale x 8 x i16> %a) #0 {
84 ; CHECK-LABEL: udiv_i16:
86 ; CHECK-NEXT: ptrue p0.h
87 ; CHECK-NEXT: mov w8, #-21845 // =0xffffaaab
88 ; CHECK-NEXT: mov z1.h, w8
89 ; CHECK-NEXT: umulh z0.h, p0/m, z0.h, z1.h
90 ; CHECK-NEXT: lsr z0.h, z0.h, #1
92 %div = udiv <vscale x 8 x i16> %a, shufflevector (<vscale x 8 x i16> insertelement (<vscale x 8 x i16> undef, i16 3, i32 0), <vscale x 8 x i16> undef, <vscale x 8 x i32> zeroinitializer)
93 ret <vscale x 8 x i16> %div
96 define <vscale x 4 x i32> @udiv_i32(<vscale x 4 x i32> %a) #0 {
97 ; CHECK-LABEL: udiv_i32:
99 ; CHECK-NEXT: ptrue p0.s
100 ; CHECK-NEXT: mov w8, #43691 // =0xaaab
101 ; CHECK-NEXT: movk w8, #43690, lsl #16
102 ; CHECK-NEXT: mov z1.s, w8
103 ; CHECK-NEXT: umulh z0.s, p0/m, z0.s, z1.s
104 ; CHECK-NEXT: lsr z0.s, z0.s, #1
106 %div = udiv <vscale x 4 x i32> %a, shufflevector (<vscale x 4 x i32> insertelement (<vscale x 4 x i32> undef, i32 3, i32 0), <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer)
107 ret <vscale x 4 x i32> %div
110 define <vscale x 2 x i64> @udiv_i64(<vscale x 2 x i64> %a) #0 {
111 ; CHECK-LABEL: udiv_i64:
113 ; CHECK-NEXT: ptrue p0.d
114 ; CHECK-NEXT: mov x8, #-6148914691236517206 // =0xaaaaaaaaaaaaaaaa
115 ; CHECK-NEXT: movk x8, #43691
116 ; CHECK-NEXT: mov z1.d, x8
117 ; CHECK-NEXT: umulh z0.d, p0/m, z0.d, z1.d
118 ; CHECK-NEXT: lsr z0.d, z0.d, #1
120 %div = udiv <vscale x 2 x i64> %a, shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> undef, i64 3, i32 0), <vscale x 2 x i64> undef, <vscale x 2 x i32> zeroinitializer)
121 ret <vscale x 2 x i64> %div
124 attributes #0 = { "target-features"="+sve" }