2 # RUN: llc --march=hexagon %s -run-pass=pipeliner -debug-only=pipeliner \
3 # RUN: -window-sched=force -filetype=null -verify-machineinstrs 2>&1 \
6 # CHECK: Best window offset is {{[0-9]+}} and Best II is {{[0-9]+}}.
9 define void @sqrt_approx(i32 noundef %N, ptr noalias %x, ptr noalias %y) #0 {
11 %isZeroLength = icmp eq i32 %N, 0
12 br i1 %isZeroLength, label %loop.exit, label %loop.preheader
14 loop.preheader: ; preds = %entry
15 %half_splat = tail call <32 x i32> @llvm.hexagon.V6.lvsplatw.128B(i32 1056964608)
16 %one_splat = tail call <32 x i32> @llvm.hexagon.V6.lvsplatw.128B(i32 1065353216)
17 %two_splat = tail call <32 x i32> @llvm.hexagon.V6.lvsplatw.128B(i32 1073741824)
20 loop.exit: ; preds = %loop.body, %entry
23 loop.body: ; preds = %loop.body, %loop.preheader
24 %lsr.iv1 = phi ptr [ %cgep3, %loop.body ], [ %x, %loop.preheader ]
25 %lsr.iv = phi ptr [ %cgep, %loop.body ], [ %y, %loop.preheader ]
26 %index = phi i32 [ 0, %loop.preheader ], [ %index.next, %loop.body ]
27 %vec_x = load <32 x i32>, ptr %lsr.iv1, align 128
28 %vec_sqrt_1 = tail call <32 x i32> @llvm.hexagon.V6.vaddw.128B(<32 x i32> %one_splat, <32 x i32> %vec_x)
29 %vec_sqrt_2 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_1, <32 x i32> %half_splat)
30 %vec_recip_1 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_2, <32 x i32> %half_splat)
31 %vec_recip_2 = tail call <32 x i32> @llvm.hexagon.V6.vsubw.128B(<32 x i32> %two_splat, <32 x i32> %vec_recip_1)
32 %vec_y1 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_2, <32 x i32> %vec_recip_2)
33 %vec_recip_3 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_2, <32 x i32> %vec_y1)
34 %vec_recop_4 = tail call <32 x i32> @llvm.hexagon.V6.vsubw.128B(<32 x i32> %two_splat, <32 x i32> %vec_recip_3)
35 %vec_y2 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_y1, <32 x i32> %vec_recop_4)
36 %vec_sqrt_3 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_x, <32 x i32> %vec_y2)
37 %vec_sqrt_4 = tail call <32 x i32> @llvm.hexagon.V6.vaddw.128B(<32 x i32> %vec_y2, <32 x i32> %vec_sqrt_3)
38 %vec_sqrt_5 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_4, <32 x i32> %half_splat)
39 %vec_recip_5 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_5, <32 x i32> %half_splat)
40 %vec_recip_6 = tail call <32 x i32> @llvm.hexagon.V6.vsubw.128B(<32 x i32> %two_splat, <32 x i32> %vec_recip_5)
41 %vec_y3 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_5, <32 x i32> %vec_recip_6)
42 %vec_recip_7 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_5, <32 x i32> %vec_y3)
43 %vec_recop_8 = tail call <32 x i32> @llvm.hexagon.V6.vsubw.128B(<32 x i32> %two_splat, <32 x i32> %vec_recip_7)
44 %vec_y4 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_y3, <32 x i32> %vec_recop_8)
45 %vec_sqrt_7 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_x, <32 x i32> %vec_y4)
46 %vec_sqrt_8 = tail call <32 x i32> @llvm.hexagon.V6.vaddw.128B(<32 x i32> %vec_y4, <32 x i32> %vec_sqrt_7)
47 %vec_sqrt_9 = tail call <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32> %vec_sqrt_8, <32 x i32> %half_splat)
48 store <32 x i32> %vec_sqrt_9, ptr %lsr.iv, align 128
49 %index.next = add nuw i32 %index, 32
50 %continue = icmp ult i32 %index.next, %N
51 %cgep = getelementptr i8, ptr %lsr.iv, i32 128
52 %cgep3 = getelementptr i8, ptr %lsr.iv1, i32 128
53 br i1 %continue, label %loop.body, label %loop.exit
56 declare <32 x i32> @llvm.hexagon.V6.lvsplatw.128B(i32)
57 declare <32 x i32> @llvm.hexagon.V6.vmpyowh.rnd.128B(<32 x i32>, <32 x i32>)
58 declare <32 x i32> @llvm.hexagon.V6.vaddw.128B(<32 x i32>, <32 x i32>)
59 declare <32 x i32> @llvm.hexagon.V6.vsubw.128B(<32 x i32>, <32 x i32>)
61 attributes #0 = { "target-features"="+hvx-length128b,+hvxv69,+v66,-long-calls" }
65 tracksRegLiveness: true
68 successors: %bb.2(0x30000000), %bb.1(0x50000000)
69 liveins: $r0, $r1, $r2
74 %3:predregs = C2_cmpeqi %2, 0
75 J2_jumpt killed %3, %bb.2, implicit-def dead $pc
76 J2_jump %bb.1, implicit-def dead $pc
79 successors: %bb.3(0x80000000)
81 %4:intregs = A2_tfrsi 1056964608
82 %5:hvxvr = V6_lvsplatw killed %4
83 %6:intregs = A2_tfrsi 1065353216
84 %7:hvxvr = V6_lvsplatw killed %6
85 %8:intregs = A2_tfrsi 1073741824
86 %9:hvxvr = V6_lvsplatw killed %8
87 %10:intregs = A2_addi %2, 31
88 %11:intregs = S2_lsr_i_r %10, 5
89 %12:intregs = COPY %11
90 J2_loop0r %bb.3, %12, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
91 J2_jump %bb.3, implicit-def dead $pc
94 PS_jmpret $r31, implicit-def dead $pc
96 bb.3.loop.body (machine-block-address-taken):
97 successors: %bb.3(0x7c000000), %bb.2(0x04000000)
99 %13:intregs = PHI %1, %bb.1, %14, %bb.3
100 %15:intregs = PHI %0, %bb.1, %16, %bb.3
101 %17:hvxvr, %14:intregs = V6_vL32b_pi %13, 128 :: (load (s1024) from %ir.lsr.iv1)
102 %18:hvxvr = V6_vaddw %7, %17
103 %19:hvxvr = V6_vmpyowh_rnd killed %18, %5
104 %20:hvxvr = V6_vmpyowh_rnd %19, %5
105 %21:hvxvr = V6_vsubw %9, killed %20
106 %22:hvxvr = V6_vmpyowh_rnd %19, killed %21
107 %23:hvxvr = V6_vmpyowh_rnd %19, %22
108 %24:hvxvr = V6_vsubw %9, killed %23
109 %25:hvxvr = V6_vmpyowh_rnd %22, killed %24
110 %26:hvxvr = V6_vmpyowh_rnd %17, %25
111 %27:hvxvr = V6_vaddw %25, killed %26
112 %28:hvxvr = V6_vmpyowh_rnd killed %27, %5
113 %29:hvxvr = V6_vmpyowh_rnd %28, %5
114 %30:hvxvr = V6_vsubw %9, killed %29
115 %31:hvxvr = V6_vmpyowh_rnd %28, killed %30
116 %32:hvxvr = V6_vmpyowh_rnd %28, %31
117 %33:hvxvr = V6_vsubw %9, killed %32
118 %34:hvxvr = V6_vmpyowh_rnd %31, killed %33
119 %35:hvxvr = V6_vmpyowh_rnd %17, %34
120 %36:hvxvr = V6_vaddw %34, killed %35
121 %37:hvxvr = V6_vmpyowh_rnd killed %36, %5
122 %16:intregs = V6_vS32b_pi %15, 128, killed %37 :: (store (s1024) into %ir.lsr.iv)
123 ENDLOOP0 %bb.3, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
124 J2_jump %bb.2, implicit-def dead $pc