1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -passes=indvars -S %s | FileCheck %s
4 @a = global [4 x i32] zeroinitializer, align 16
7 ; CHECK-LABEL: define i32 @test() {
9 ; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
11 ; CHECK-NEXT: [[IV:%.*]] = phi i8 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP_LATCH:%.*]] ]
12 ; CHECK-NEXT: [[RED:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[RED_NEXT:%.*]], [[LOOP_LATCH]] ]
13 ; CHECK-NEXT: [[IDXPROM:%.*]] = zext i8 [[IV]] to i64
14 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, ptr @a, i64 [[IDXPROM]]
15 ; CHECK-NEXT: br i1 false, label [[LOOP_LATCH]], label [[EXIT_1:%.*]]
17 ; CHECK-NEXT: [[L:%.*]] = load i32, ptr [[GEP]], align 4
18 ; CHECK-NEXT: [[RED_NEXT]] = add nsw i32 [[L]], [[RED]]
19 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i8 [[IV]], 1
20 ; CHECK-NEXT: br i1 true, label [[LOOP_HEADER]], label [[EXIT_2:%.*]]
22 ; CHECK-NEXT: ret i32 0
24 ; CHECK-NEXT: [[ADD_LCSSA:%.*]] = phi i32 [ [[RED_NEXT]], [[LOOP_LATCH]] ]
25 ; CHECK-NEXT: ret i32 [[ADD_LCSSA]]
31 %iv = phi i8 [ 0, %entry ], [ %iv.next, %loop.latch ]
32 %red = phi i32 [ 0, %entry ], [ %red.next, %loop.latch ]
33 %idxprom = zext i8 %iv to i64
34 %gep = getelementptr i32, ptr @a, i64 %idxprom
35 %f = icmp ult ptr %gep, getelementptr inbounds ([4 x i32], ptr @a, i64 1, i64 0)
36 br i1 %f, label %loop.latch, label %exit.1
39 %l = load i32, ptr %gep, align 4
40 %red.next = add nsw i32 %l, %red
41 %iv.next = add nuw nsw i8 %iv, 1
42 %cmp = icmp ult i8 %iv, 4
43 br i1 %cmp, label %loop.header, label %exit.2
45 exit.1: ; preds = %for.body
49 %add.lcssa = phi i32 [ %red.next, %loop.latch ]