blob: 52e1ea95af75a7d70aee566b151fdd904b2f1cc2 [file] [log] [blame]
Sanjoy Dasac5bf592016-08-03 20:53:23 +00001; RUN: opt < %s -indvars -S | FileCheck %s
Dan Gohman8c129d72009-07-16 17:34:36 +00002
3; Indvars should be able to compute the exit value of this loop
4; without any additional arithmetic. The only add needed should
5; be the canonical IV increment.
6
7target 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"
8
9define void @foo(double* %p, i32 %n) nounwind {
Sanjoy Dasac5bf592016-08-03 20:53:23 +000010; CHECK-LABEL: @foo(
11; CHECK: add
12; CHECK-NOT: add
13
Dan Gohman8c129d72009-07-16 17:34:36 +000014entry:
15 %0 = icmp sgt i32 %n, 0 ; <i1> [#uses=1]
16 br i1 %0, label %bb.nph, label %return
17
18bb.nph: ; preds = %entry
19 br label %bb2
20
21bb2: ; preds = %bb3, %bb.nph
22 %i.01 = phi i32 [ %7, %bb3 ], [ 0, %bb.nph ] ; <i32> [#uses=3]
23 %1 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
David Blaikie79e6c742015-02-27 19:29:02 +000024 %2 = getelementptr double, double* %p, i64 %1 ; <double*> [#uses=1]
David Blaikiea79ac142015-02-27 21:17:42 +000025 %3 = load double, double* %2, align 8 ; <double> [#uses=1]
Dan Gohman8c129d72009-07-16 17:34:36 +000026 %4 = fmul double %3, 1.100000e+00 ; <double> [#uses=1]
27 %5 = sext i32 %i.01 to i64 ; <i64> [#uses=1]
David Blaikie79e6c742015-02-27 19:29:02 +000028 %6 = getelementptr double, double* %p, i64 %5 ; <double*> [#uses=1]
Dan Gohman8c129d72009-07-16 17:34:36 +000029 store double %4, double* %6, align 8
30 %7 = add i32 %i.01, 1 ; <i32> [#uses=2]
31 br label %bb3
32
33bb3: ; preds = %bb2
34 %8 = icmp slt i32 %7, %n ; <i1> [#uses=1]
35 br i1 %8, label %bb2, label %bb3.return_crit_edge
36
37bb3.return_crit_edge: ; preds = %bb3
38 br label %return
39
40return: ; preds = %bb3.return_crit_edge, %entry
41 ret void
42}