1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -S -passes=loop-idiom < %s | FileCheck %s
4 ; Make sure that any inserted LCSSA phi nodes are removed if the transform
8 ; CHECK-LABEL: define void @test() {
10 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [64 x i8], align 16
11 ; CHECK-NEXT: br label [[LOOP:%.*]]
13 ; CHECK-NEXT: [[PHI:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ 1, [[LOOP_LATCH:%.*]] ]
14 ; CHECK-NEXT: br i1 false, label [[LOOP_EXIT2:%.*]], label [[LOOP_LATCH]]
16 ; CHECK-NEXT: [[OR:%.*]] = or i64 [[PHI]], 4
17 ; CHECK-NEXT: br i1 false, label [[LOOP_EXIT:%.*]], label [[LOOP]]
19 ; CHECK-NEXT: [[OR_LCSSA:%.*]] = phi i64 [ [[OR]], [[LOOP_LATCH]] ]
20 ; CHECK-NEXT: br label [[LOOP2_PREHEADER:%.*]]
22 ; CHECK-NEXT: br label [[LOOP2_PREHEADER]]
23 ; CHECK: loop2.preheader:
24 ; CHECK-NEXT: [[PHI5_PH:%.*]] = phi ptr [ null, [[LOOP_EXIT2]] ], [ [[ALLOCA]], [[LOOP_EXIT]] ]
25 ; CHECK-NEXT: [[PHI6_PH:%.*]] = phi i64 [ 0, [[LOOP_EXIT2]] ], [ [[OR_LCSSA]], [[LOOP_EXIT]] ]
26 ; CHECK-NEXT: br label [[LOOP2:%.*]]
28 ; CHECK-NEXT: [[PHI5:%.*]] = phi ptr [ [[GETELEMENTPTR7:%.*]], [[LOOP2]] ], [ [[PHI5_PH]], [[LOOP2_PREHEADER]] ]
29 ; CHECK-NEXT: [[PHI6:%.*]] = phi i64 [ [[ADD:%.*]], [[LOOP2]] ], [ [[PHI6_PH]], [[LOOP2_PREHEADER]] ]
30 ; CHECK-NEXT: [[GETELEMENTPTR:%.*]] = getelementptr i8, ptr [[ALLOCA]], i64 [[PHI6]]
31 ; CHECK-NEXT: [[LOAD:%.*]] = load i8, ptr [[GETELEMENTPTR]], align 1
32 ; CHECK-NEXT: store i8 [[LOAD]], ptr [[PHI5]], align 1
33 ; CHECK-NEXT: [[GETELEMENTPTR7]] = getelementptr i8, ptr [[PHI5]], i64 1
34 ; CHECK-NEXT: [[ADD]] = add i64 [[PHI6]], 1
35 ; CHECK-NEXT: [[ICMP:%.*]] = icmp eq i64 [[PHI6]], 0
36 ; CHECK-NEXT: br i1 [[ICMP]], label [[LOOP2_EXIT:%.*]], label [[LOOP2]]
38 ; CHECK-NEXT: ret void
41 %alloca = alloca [64 x i8], align 16
45 %phi = phi i64 [ 0, %entry ], [ 1, %loop.latch ]
46 br i1 false, label %loop.exit2, label %loop.latch
50 br i1 false, label %loop.exit, label %loop
53 br label %loop2.preheader
56 br label %loop2.preheader
59 %phi5.ph = phi ptr [ null, %loop.exit2 ], [ %alloca, %loop.exit ]
60 %phi6.ph = phi i64 [ 0, %loop.exit2 ], [ %or, %loop.exit ]
64 %phi5 = phi ptr [ %getelementptr7, %loop2 ], [ %phi5.ph, %loop2.preheader ]
65 %phi6 = phi i64 [ %add, %loop2 ], [ %phi6.ph, %loop2.preheader ]
66 %getelementptr = getelementptr i8, ptr %alloca, i64 %phi6
67 %load = load i8, ptr %getelementptr, align 1
68 store i8 %load, ptr %phi5, align 1
69 %getelementptr7 = getelementptr i8, ptr %phi5, i64 1
70 %add = add i64 %phi6, 1
71 %icmp = icmp eq i64 %phi6, 0
72 br i1 %icmp, label %loop2.exit, label %loop2