Reapply 75252, with a fix to avoid the infinite recursion case. The
[oota-llvm.git] / test / Transforms / IndVarSimplify / iv-sext.ll
1 ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
2 ; RUN: grep {= sext} %t | count 4
3 ; RUN: grep {phi i64} %t | count 2
4
5 ; Indvars should be able to promote the hiPart induction variable in the
6 ; inner loop to i64.
7 ; TODO: it should promote hiPart to i64 in the outer loop too.
8
9 target 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"
10
11 define void @t(float* %pTmp1, float* %peakWeight, float* %nrgReducePeakrate, i32 %bandEdgeIndex, float %tmp1) nounwind {
12 entry:
13         %tmp = load float* %peakWeight, align 4         ; <float> [#uses=1]
14         %tmp2 = icmp sgt i32 %bandEdgeIndex, 0          ; <i1> [#uses=1]
15         br i1 %tmp2, label %bb.nph22, label %return
16
17 bb.nph22:               ; preds = %entry
18         %tmp3 = add i32 %bandEdgeIndex, -1              ; <i32> [#uses=2]
19         br label %bb
20
21 bb:             ; preds = %bb8, %bb.nph22
22         %distERBhi.121 = phi float [ %distERBhi.2.lcssa, %bb8 ], [ 0.000000e+00, %bb.nph22 ]            ; <float> [#uses=2]
23         %distERBlo.120 = phi float [ %distERBlo.0.lcssa, %bb8 ], [ 0.000000e+00, %bb.nph22 ]            ; <float> [#uses=2]
24         %hiPart.119 = phi i32 [ %hiPart.0.lcssa, %bb8 ], [ 0, %bb.nph22 ]               ; <i32> [#uses=3]
25         %loPart.118 = phi i32 [ %loPart.0.lcssa, %bb8 ], [ 0, %bb.nph22 ]               ; <i32> [#uses=2]
26         %peakCount.117 = phi float [ %peakCount.2.lcssa, %bb8 ], [ %tmp, %bb.nph22 ]            ; <float> [#uses=2]
27         %part.016 = phi i32 [ %tmp46, %bb8 ], [ 0, %bb.nph22 ]          ; <i32> [#uses=5]
28         %tmp4 = icmp sgt i32 %part.016, 0               ; <i1> [#uses=1]
29         br i1 %tmp4, label %bb1, label %bb3.preheader
30
31 bb1:            ; preds = %bb
32         %tmp5 = add i32 %part.016, -1           ; <i32> [#uses=1]
33         %tmp6 = sext i32 %tmp5 to i64           ; <i64> [#uses=1]
34         %tmp7 = getelementptr float* %pTmp1, i64 %tmp6          ; <float*> [#uses=1]
35         %tmp8 = load float* %tmp7, align 4              ; <float> [#uses=1]
36         %tmp9 = fadd float %tmp8, %distERBlo.120                ; <float> [#uses=1]
37         %tmp10 = add i32 %part.016, -1          ; <i32> [#uses=1]
38         %tmp11 = sext i32 %tmp10 to i64         ; <i64> [#uses=1]
39         %tmp12 = getelementptr float* %pTmp1, i64 %tmp11                ; <float*> [#uses=1]
40         %tmp13 = load float* %tmp12, align 4            ; <float> [#uses=1]
41         %tmp14 = fsub float %distERBhi.121, %tmp13              ; <float> [#uses=1]
42         br label %bb3.preheader
43
44 bb3.preheader:          ; preds = %bb1, %bb
45         %distERBlo.0.ph = phi float [ %distERBlo.120, %bb ], [ %tmp9, %bb1 ]            ; <float> [#uses=3]
46         %distERBhi.0.ph = phi float [ %distERBhi.121, %bb ], [ %tmp14, %bb1 ]           ; <float> [#uses=3]
47         %tmp15 = fcmp ogt float %distERBlo.0.ph, 2.500000e+00           ; <i1> [#uses=1]
48         br i1 %tmp15, label %bb.nph, label %bb5.preheader
49
50 bb.nph:         ; preds = %bb3.preheader
51         br label %bb2
52
53 bb2:            ; preds = %bb3, %bb.nph
54         %distERBlo.03 = phi float [ %tmp19, %bb3 ], [ %distERBlo.0.ph, %bb.nph ]                ; <float> [#uses=1]
55         %loPart.02 = phi i32 [ %tmp24, %bb3 ], [ %loPart.118, %bb.nph ]         ; <i32> [#uses=3]
56         %peakCount.01 = phi float [ %tmp23, %bb3 ], [ %peakCount.117, %bb.nph ]         ; <float> [#uses=1]
57         %tmp16 = sext i32 %loPart.02 to i64             ; <i64> [#uses=1]
58         %tmp17 = getelementptr float* %pTmp1, i64 %tmp16                ; <float*> [#uses=1]
59         %tmp18 = load float* %tmp17, align 4            ; <float> [#uses=1]
60         %tmp19 = fsub float %distERBlo.03, %tmp18               ; <float> [#uses=3]
61         %tmp20 = sext i32 %loPart.02 to i64             ; <i64> [#uses=1]
62         %tmp21 = getelementptr float* %peakWeight, i64 %tmp20           ; <float*> [#uses=1]
63         %tmp22 = load float* %tmp21, align 4            ; <float> [#uses=1]
64         %tmp23 = fsub float %peakCount.01, %tmp22               ; <float> [#uses=2]
65         %tmp24 = add i32 %loPart.02, 1          ; <i32> [#uses=2]
66         br label %bb3
67
68 bb3:            ; preds = %bb2
69         %tmp25 = fcmp ogt float %tmp19, 2.500000e+00            ; <i1> [#uses=1]
70         br i1 %tmp25, label %bb2, label %bb3.bb5.preheader_crit_edge
71
72 bb3.bb5.preheader_crit_edge:            ; preds = %bb3
73         %tmp24.lcssa = phi i32 [ %tmp24, %bb3 ]         ; <i32> [#uses=1]
74         %tmp23.lcssa = phi float [ %tmp23, %bb3 ]               ; <float> [#uses=1]
75         %tmp19.lcssa = phi float [ %tmp19, %bb3 ]               ; <float> [#uses=1]
76         br label %bb5.preheader
77
78 bb5.preheader:          ; preds = %bb3.bb5.preheader_crit_edge, %bb3.preheader
79         %distERBlo.0.lcssa = phi float [ %tmp19.lcssa, %bb3.bb5.preheader_crit_edge ], [ %distERBlo.0.ph, %bb3.preheader ]              ; <float> [#uses=2]
80         %loPart.0.lcssa = phi i32 [ %tmp24.lcssa, %bb3.bb5.preheader_crit_edge ], [ %loPart.118, %bb3.preheader ]               ; <i32> [#uses=1]
81         %peakCount.0.lcssa = phi float [ %tmp23.lcssa, %bb3.bb5.preheader_crit_edge ], [ %peakCount.117, %bb3.preheader ]               ; <float> [#uses=2]
82         %.not10 = fcmp olt float %distERBhi.0.ph, 2.500000e+00          ; <i1> [#uses=1]
83         %tmp26 = icmp sgt i32 %tmp3, %hiPart.119                ; <i1> [#uses=1]
84         %or.cond11 = and i1 %tmp26, %.not10             ; <i1> [#uses=1]
85         br i1 %or.cond11, label %bb.nph12, label %bb7
86
87 bb.nph12:               ; preds = %bb5.preheader
88         br label %bb4
89
90 bb4:            ; preds = %bb5, %bb.nph12
91         %distERBhi.29 = phi float [ %tmp30, %bb5 ], [ %distERBhi.0.ph, %bb.nph12 ]              ; <float> [#uses=1]
92         %hiPart.08 = phi i32 [ %tmp31, %bb5 ], [ %hiPart.119, %bb.nph12 ]               ; <i32> [#uses=2]
93         %peakCount.27 = phi float [ %tmp35, %bb5 ], [ %peakCount.0.lcssa, %bb.nph12 ]           ; <float> [#uses=1]
94         %tmp27 = sext i32 %hiPart.08 to i64             ; <i64> [#uses=1]
95         %tmp28 = getelementptr float* %pTmp1, i64 %tmp27                ; <float*> [#uses=1]
96         %tmp29 = load float* %tmp28, align 4            ; <float> [#uses=1]
97         %tmp30 = fadd float %tmp29, %distERBhi.29               ; <float> [#uses=3]
98         %tmp31 = add i32 %hiPart.08, 1          ; <i32> [#uses=4]
99         %tmp32 = sext i32 %tmp31 to i64         ; <i64> [#uses=1]
100         %tmp33 = getelementptr float* %peakWeight, i64 %tmp32           ; <float*> [#uses=1]
101         %tmp34 = load float* %tmp33, align 4            ; <float> [#uses=1]
102         %tmp35 = fadd float %tmp34, %peakCount.27               ; <float> [#uses=2]
103         br label %bb5
104
105 bb5:            ; preds = %bb4
106         %.not = fcmp olt float %tmp30, 2.500000e+00             ; <i1> [#uses=1]
107         %tmp36 = icmp sgt i32 %tmp3, %tmp31             ; <i1> [#uses=1]
108         %or.cond = and i1 %tmp36, %.not         ; <i1> [#uses=1]
109         br i1 %or.cond, label %bb4, label %bb5.bb7_crit_edge
110
111 bb5.bb7_crit_edge:              ; preds = %bb5
112         %tmp35.lcssa = phi float [ %tmp35, %bb5 ]               ; <float> [#uses=1]
113         %tmp31.lcssa = phi i32 [ %tmp31, %bb5 ]         ; <i32> [#uses=1]
114         %tmp30.lcssa = phi float [ %tmp30, %bb5 ]               ; <float> [#uses=1]
115         br label %bb7
116
117 bb7:            ; preds = %bb5.bb7_crit_edge, %bb5.preheader
118         %distERBhi.2.lcssa = phi float [ %tmp30.lcssa, %bb5.bb7_crit_edge ], [ %distERBhi.0.ph, %bb5.preheader ]                ; <float> [#uses=2]
119         %hiPart.0.lcssa = phi i32 [ %tmp31.lcssa, %bb5.bb7_crit_edge ], [ %hiPart.119, %bb5.preheader ]         ; <i32> [#uses=1]
120         %peakCount.2.lcssa = phi float [ %tmp35.lcssa, %bb5.bb7_crit_edge ], [ %peakCount.0.lcssa, %bb5.preheader ]             ; <float> [#uses=2]
121         %tmp37 = fadd float %distERBlo.0.lcssa, %distERBhi.2.lcssa              ; <float> [#uses=1]
122         %tmp38 = fdiv float %peakCount.2.lcssa, %tmp37          ; <float> [#uses=1]
123         %tmp39 = fmul float %tmp38, %tmp1               ; <float> [#uses=2]
124         %tmp40 = fmul float %tmp39, %tmp39              ; <float> [#uses=2]
125         %tmp41 = fmul float %tmp40, %tmp40              ; <float> [#uses=1]
126         %tmp42 = fadd float %tmp41, 1.000000e+00                ; <float> [#uses=1]
127         %tmp43 = fdiv float 1.000000e+00, %tmp42                ; <float> [#uses=1]
128         %tmp44 = sext i32 %part.016 to i64              ; <i64> [#uses=1]
129         %tmp45 = getelementptr float* %nrgReducePeakrate, i64 %tmp44            ; <float*> [#uses=1]
130         store float %tmp43, float* %tmp45, align 4
131         %tmp46 = add i32 %part.016, 1           ; <i32> [#uses=2]
132         br label %bb8
133
134 bb8:            ; preds = %bb7
135         %tmp47 = icmp slt i32 %tmp46, %bandEdgeIndex            ; <i1> [#uses=1]
136         br i1 %tmp47, label %bb, label %bb8.return_crit_edge
137
138 bb8.return_crit_edge:           ; preds = %bb8
139         br label %return
140
141 return:         ; preds = %bb8.return_crit_edge, %entry
142         ret void
143 }