1 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
4 target triple = "thumbv7m-arm-none-eabi"
6 ; Check that the IV updates (incdec.ptr{,1,2}) are kept in the latch block
7 ; and not moved to the header/exiting block. Inserting them in the header
8 ; doubles register pressure and adds moves.
12 ; CHECK: icmp sgt i32 %n.addr.0, 0
15 ; CHECK: incdec.ptr1 =
16 ; CHECK: incdec.ptr2 =
18 define void @f(ptr nocapture readonly %a, ptr nocapture readonly %b, ptr nocapture %c, i32 %n) {
22 while.cond: ; preds = %while.body, %entry
23 %a.addr.0 = phi ptr [ %a, %entry ], [ %incdec.ptr, %while.body ]
24 %b.addr.0 = phi ptr [ %b, %entry ], [ %incdec.ptr1, %while.body ]
25 %c.addr.0 = phi ptr [ %c, %entry ], [ %incdec.ptr2, %while.body ]
26 %n.addr.0 = phi i32 [ %n, %entry ], [ %dec, %while.body ]
27 %cmp = icmp sgt i32 %n.addr.0, 0
28 br i1 %cmp, label %while.body, label %while.end
30 while.body: ; preds = %while.cond
31 %incdec.ptr = getelementptr inbounds float, ptr %a.addr.0, i32 1
32 %tmp = load float, ptr %a.addr.0, align 4
33 %incdec.ptr1 = getelementptr inbounds float, ptr %b.addr.0, i32 1
34 %tmp1 = load float, ptr %b.addr.0, align 4
35 %add = fadd float %tmp, %tmp1
36 %incdec.ptr2 = getelementptr inbounds float, ptr %c.addr.0, i32 1
37 store float %add, ptr %c.addr.0, align 4
38 %dec = add nsw i32 %n.addr.0, -1
41 while.end: ; preds = %while.cond