1; RUN: opt -indvars -S < %s | FileCheck %s
2; rdar://8197217
3
4; Indvars should be able to emit a clean GEP here, not an uglygep.
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"
7target triple = "x86_64-apple-darwin11.0"
8
9@numf2s = external global i32                     ; <i32*> [#uses=1]
10@numf1s = external global i32                     ; <i32*> [#uses=1]
11@tds = external global double**                   ; <double***> [#uses=1]
12
13define void @init_td(i32 %tmp7) nounwind {
14; CHECK-LABEL: @init_td
15; CHECK-NOT: uglygep
16entry:
17  br label %bb4
18
19bb4:                                              ; preds = %bb3, %entry
20  %i.0 = phi i32 [ 0, %entry ], [ %tmp9, %bb3 ]   ; <i32> [#uses=3]
21  br label %bb
22
23bb:                                               ; preds = %bb4
24  br label %bb2
25
26bb2:                                              ; preds = %bb1, %bb
27  %j.0 = phi i32 [ 0, %bb ], [ %tmp6, %bb1 ]      ; <i32> [#uses=3]
28  %tmp8 = icmp slt i32 %j.0, %tmp7                ; <i1> [#uses=1]
29  br i1 %tmp8, label %bb1, label %bb3
30
31bb1:                                              ; preds = %bb2
32  %tmp = load double**, double*** @tds, align 8             ; <double**> [#uses=1]
33  %tmp1 = sext i32 %i.0 to i64                    ; <i64> [#uses=1]
34  %tmp2 = getelementptr inbounds double*, double** %tmp, i64 %tmp1 ; <double**> [#uses=1]
35  %tmp3 = load double*, double** %tmp2, align 1            ; <double*> [#uses=1]
36  %tmp6 = add nsw i32 %j.0, 1                     ; <i32> [#uses=1]
37  br label %bb2
38
39bb3:                                              ; preds = %bb2
40  %tmp9 = add nsw i32 %i.0, 1                     ; <i32> [#uses=1]
41  br label %bb4
42}
43