1; RUN: opt < %s -loop-reduce -S | FileCheck %s 2 3; LSR shouldn't consider %t8 to be an interesting user of %t6, and it 4; should be able to form pretty GEPs. 5 6target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" 7 8define void @Z4() nounwind { 9; CHECK-LABEL: define void @Z4( 10bb: 11 br label %bb3 12 13bb1: ; preds = %bb3 14 br i1 undef, label %bb10, label %bb2 15 16bb2: ; preds = %bb1 17 %t = add i64 %t4, 1 ; <i64> [#uses=1] 18 br label %bb3 19 20bb3: ; preds = %bb2, %bb 21 %t4 = phi i64 [ %t, %bb2 ], [ 0, %bb ] ; <i64> [#uses=3] 22 br label %bb1 23 24; CHECK: bb10: 25; CHECK-NEXT: %t7 = icmp eq i64 %t4, 0 26; Host %t2 computation outside the loop. 27; CHECK-NEXT: [[SCEVGEP:%[^ ]+]] = getelementptr i8, i8* undef, i64 %t4 28; CHECK-NEXT: br label %bb14 29bb10: ; preds = %bb9 30 %t7 = icmp eq i64 %t4, 0 ; <i1> [#uses=1] 31 %t3 = add i64 %t4, 16 ; <i64> [#uses=1] 32 br label %bb14 33 34; CHECK: bb14: 35; CHECK-NEXT: store i8 undef, i8* [[SCEVGEP]] 36; CHECK-NEXT: %t6 = load float*, float** undef 37; Fold %t3's add within the address. 38; CHECK-NEXT: [[SCEVGEP1:%[^ ]+]] = getelementptr float, float* %t6, i64 4 39; CHECK-NEXT: [[SCEVGEP2:%[^ ]+]] = bitcast float* [[SCEVGEP1]] to i8* 40; Use the induction variable (%t4) to access the right element 41; CHECK-NEXT: [[ADDRESS:%[^ ]+]] = getelementptr i8, i8* [[SCEVGEP2]], i64 %t4 42; CHECK-NEXT: store i8 undef, i8* [[ADDRESS]] 43; CHECK-NEXT: br label %bb14 44bb14: ; preds = %bb14, %bb10 45 %t2 = getelementptr inbounds i8, i8* undef, i64 %t4 ; <i8*> [#uses=1] 46 store i8 undef, i8* %t2 47 %t6 = load float*, float** undef 48 %t8 = bitcast float* %t6 to i8* ; <i8*> [#uses=1] 49 %t9 = getelementptr inbounds i8, i8* %t8, i64 %t3 ; <i8*> [#uses=1] 50 store i8 undef, i8* %t9 51 br label %bb14 52} 53 54define fastcc void @TransformLine() nounwind { 55; CHECK-LABEL: @TransformLine( 56bb: 57 br label %loop0 58 59; CHECK: loop0: 60; Induction variable is initialized to -2. 61; CHECK-NEXT: [[PHIIV:%[^ ]+]] = phi i32 [ [[IVNEXT:%[^ ]+]], %loop0 ], [ -2, %bb ] 62; CHECK-NEXT: [[IVNEXT]] = add nuw nsw i32 [[PHIIV]], 1 63; CHECK-NEXT: br i1 false, label %loop0, label %bb0 64loop0: ; preds = %loop0, %bb 65 %i0 = phi i32 [ %i0.next, %loop0 ], [ 0, %bb ] ; <i32> [#uses=2] 66 %i0.next = add i32 %i0, 1 ; <i32> [#uses=1] 67 br i1 false, label %loop0, label %bb0 68 69bb0: ; preds = %loop0 70 br label %loop1 71 72; CHECK: loop1: 73; CHECK-NEXT: %i1 = phi i32 [ 0, %bb0 ], [ %i1.next, %bb5 ] 74; IVNEXT covers the uses of %i0 and %t0. 75; Therefore, %t0 has been removed. 76; The critical edge has been split. 77; CHECK-NEXT: br i1 false, label %bb2, label %[[LOOP1BB6:.+]] 78loop1: ; preds = %bb5, %bb0 79 %i1 = phi i32 [ 0, %bb0 ], [ %i1.next, %bb5 ] ; <i32> [#uses=4] 80 %t0 = add i32 %i0, %i1 ; <i32> [#uses=1] 81 br i1 false, label %bb2, label %bb6 82 83; CHECK: bb2: 84; Critical edge split. 85; CHECK-NEXT: br i1 true, label %[[BB2BB6:[^,]+]], label %bb5 86bb2: ; preds = %loop1 87 br i1 true, label %bb6, label %bb5 88 89; CHECK: bb5: 90; CHECK-NEXT: %i1.next = add i32 %i1, 1 91; CHECK-NEXT: br i1 true, label %[[BB5BB6:[^,]+]], label %loop1 92bb5: ; preds = %bb2 93 %i1.next = add i32 %i1, 1 ; <i32> [#uses=1] 94 br i1 true, label %bb6, label %loop1 95 96; bb5 to bb6 split basic block. 97; CHECK: [[BB5BB6]]: 98; CHECK-NEXT: [[INITIALVAL:%[^ ]+]] = add i32 [[IVNEXT]], %i1.next 99; CHECK-NEXT: br label %[[SPLITTOBB6:.+]] 100 101; bb2 to bb6 split basic block. 102; CHECK: [[BB2BB6]]: 103; CHECK-NEXT: br label %[[SPLITTOBB6]] 104 105; Split basic blocks to bb6. 106; CHECK: [[SPLITTOBB6]]: 107; CHECK-NEXT: [[INITP8:%[^ ]+]] = phi i32 [ [[INITIALVAL]], %[[BB5BB6]] ], [ undef, %[[BB2BB6]] ] 108; CHECK-NEXT: [[INITP9:%[^ ]+]] = phi i32 [ undef, %[[BB5BB6]] ], [ %i1, %[[BB2BB6]] ] 109; CHECK-NEXT: br label %bb6 110 111; CHECK: [[LOOP1BB6]]: 112; CHECK-NEXT: br label %bb6 113 114; CHECK: bb6: 115; CHECK-NEXT: %p8 = phi i32 [ undef, %[[LOOP1BB6]] ], [ [[INITP8]], %[[SPLITTOBB6]] ] 116; CHECK-NEXT: %p9 = phi i32 [ %i1, %[[LOOP1BB6]] ], [ [[INITP9]], %[[SPLITTOBB6]] ] 117; CHECK-NEXT: unreachable 118bb6: ; preds = %bb5, %bb2, %loop1 119 %p8 = phi i32 [ %t0, %bb5 ], [ undef, %loop1 ], [ undef, %bb2 ] ; <i32> [#uses=0] 120 %p9 = phi i32 [ undef, %bb5 ], [ %i1, %loop1 ], [ %i1, %bb2 ] ; <i32> [#uses=0] 121 unreachable 122} 123