1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -loop-reduce -S %s | FileCheck %s
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5 target triple = "arm64-apple-macosx13.0.0"
10 ; CHECK-LABEL: define i32 @test() {
12 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
14 ; CHECK-NEXT: [[LSR_IV1:%.*]] = phi i32 [ [[LSR_IV_NEXT2:%.*]], [[LOOP_1]] ], [ -1, [[ENTRY:%.*]] ]
15 ; CHECK-NEXT: [[LSR_IV_NEXT2]] = add i32 [[LSR_IV1]], 1
16 ; CHECK-NEXT: br i1 false, label [[LOOP_2_PH:%.*]], label [[LOOP_1]]
18 ; CHECK-NEXT: [[LSR_IV_NEXT2_LCSSA:%.*]] = phi i32 [ [[LSR_IV_NEXT2]], [[LOOP_1]] ]
19 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
21 ; CHECK-NEXT: [[LSR_IV:%.*]] = phi i64 [ [[LSR_IV_NEXT:%.*]], [[LOOP_2]] ], [ 1, [[LOOP_2_PH]] ]
22 ; CHECK-NEXT: [[IV_2:%.*]] = phi i32 [ [[LSR_IV_NEXT2_LCSSA]], [[LOOP_2_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP_2]] ]
23 ; CHECK-NEXT: call void @use(i32 [[IV_2]])
24 ; CHECK-NEXT: [[IV_2_NEXT]] = add i32 [[IV_2]], 1
25 ; CHECK-NEXT: [[LSR_IV_NEXT]] = add nsw i64 [[LSR_IV]], -1
26 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[LSR_IV_NEXT]], 0
27 ; CHECK-NEXT: br i1 [[EC]], label [[EXIT:%.*]], label [[LOOP_2]]
29 ; CHECK-NEXT: ret i32 [[IV_2_NEXT]]
35 %iv.1 = phi i32 [ 0, %entry ], [ %iv.1.next, %loop.1 ]
36 %iv.1.next = add i32 %iv.1, 1
37 br i1 false, label %loop.2.ph, label %loop.1
43 %iv.2 = phi i32 [ %iv.1, %loop.2.ph ], [ %iv.2.next, %loop.2 ]
44 %iv.3 = phi i64 [ 0, %loop.2.ph ], [ %iv.3.next, %loop.2 ]
45 call void @use(i32 %iv.2)
46 %iv.2.next = add i32 %iv.2, 1
47 %iv.3.next = add i64 %iv.3, 1
48 %ec = icmp eq i64 %iv.3, 0
49 br i1 %ec, label %exit, label %loop.2