1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
4 ; This test tests several things. The load and store should use the
5 ; same address instead of having it computed twice, and SCEVExpander should
6 ; be able to reconstruct the full getelementptr, despite it having a few
7 ; obstacles set in its way.
8 ; We only check that the inner loop (bb1-bb2) is "reduced" because LSR
9 ; currently only operates on inner loops.
11 target datalayout = "e-p:64:64:64-p1:16:16:16-n16:32:64"
13 define void @foo(i64 %n, i64 %m, i64 %o, i64 %q, ptr addrspace(1) nocapture %p) nounwind {
14 ; CHECK-LABEL: define void @foo
15 ; CHECK-SAME: (i64 [[N:%.*]], i64 [[M:%.*]], i64 [[O:%.*]], i64 [[Q:%.*]], ptr addrspace(1) nocapture [[P:%.*]]) #[[ATTR0:[0-9]+]] {
17 ; CHECK-NEXT: [[TMP:%.*]] = icmp sgt i64 [[N]], 0
18 ; CHECK-NEXT: br i1 [[TMP]], label [[BB_NPH3:%.*]], label [[RETURN:%.*]]
20 ; CHECK-NEXT: br label [[BB1:%.*]]
22 ; CHECK-NEXT: [[LSR_IV2:%.*]] = phi ptr addrspace(1) [ [[SCEVGEP3:%.*]], [[BB2:%.*]] ], [ [[LSR_IV:%.*]], [[BB_NPH:%.*]] ]
23 ; CHECK-NEXT: [[J_01:%.*]] = phi i64 [ [[TMP9:%.*]], [[BB2]] ], [ 0, [[BB_NPH]] ]
24 ; CHECK-NEXT: [[TMP6:%.*]] = load double, ptr addrspace(1) [[LSR_IV2]], align 8
25 ; CHECK-NEXT: [[TMP7:%.*]] = fdiv double [[TMP6]], 2.100000e+00
26 ; CHECK-NEXT: store double [[TMP7]], ptr addrspace(1) [[LSR_IV2]], align 8
27 ; CHECK-NEXT: [[TMP9]] = add i64 [[J_01]], 1
28 ; CHECK-NEXT: br label [[BB2]]
30 ; CHECK-NEXT: [[SCEVGEP3]] = getelementptr i8, ptr addrspace(1) [[LSR_IV2]], i16 8
31 ; CHECK-NEXT: [[TMP10:%.*]] = icmp slt i64 [[TMP9]], [[M]]
32 ; CHECK-NEXT: br i1 [[TMP10]], label [[BB1]], label [[BB2_BB3_CRIT_EDGE:%.*]]
33 ; CHECK: bb2.bb3_crit_edge:
34 ; CHECK-NEXT: br label [[BB3:%.*]]
36 ; CHECK-NEXT: [[TMP11:%.*]] = add i64 [[I_02:%.*]], 1
37 ; CHECK-NEXT: br label [[BB4:%.*]]
39 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr addrspace(1) [[LSR_IV]], i16 [[TMP4:%.*]]
40 ; CHECK-NEXT: [[TMP12:%.*]] = icmp slt i64 [[TMP11]], [[N]]
41 ; CHECK-NEXT: br i1 [[TMP12]], label [[BB2_PREHEADER:%.*]], label [[BB4_RETURN_CRIT_EDGE:%.*]]
42 ; CHECK: bb4.return_crit_edge:
43 ; CHECK-NEXT: br label [[BB4_RETURN_CRIT_EDGE_SPLIT:%.*]]
44 ; CHECK: bb4.return_crit_edge.split:
45 ; CHECK-NEXT: br label [[RETURN]]
47 ; CHECK-NEXT: [[TMP13:%.*]] = icmp sgt i64 [[M]], 0
48 ; CHECK-NEXT: br i1 [[TMP13]], label [[BB_NPH3_SPLIT:%.*]], label [[BB4_RETURN_CRIT_EDGE_SPLIT]]
49 ; CHECK: bb.nph3.split:
50 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr addrspace(1) [[P]], i16 -23912
51 ; CHECK-NEXT: [[TMP0:%.*]] = mul i64 [[Q]], [[O]]
52 ; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], [[N]]
53 ; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], 37
54 ; CHECK-NEXT: [[TMP3:%.*]] = trunc i64 [[TMP2]] to i16
55 ; CHECK-NEXT: [[TMP4]] = shl i16 [[TMP3]], 3
56 ; CHECK-NEXT: br label [[BB2_PREHEADER]]
57 ; CHECK: bb2.preheader:
58 ; CHECK-NEXT: [[LSR_IV]] = phi ptr addrspace(1) [ [[SCEVGEP]], [[BB_NPH3_SPLIT]] ], [ [[SCEVGEP1]], [[BB4]] ]
59 ; CHECK-NEXT: [[I_02]] = phi i64 [ [[TMP11]], [[BB4]] ], [ 0, [[BB_NPH3_SPLIT]] ]
60 ; CHECK-NEXT: br i1 true, label [[BB_NPH]], label [[BB3]]
62 ; CHECK-NEXT: ret void
65 %tmp = icmp sgt i64 %n, 0 ; <i1> [#uses=1]
66 br i1 %tmp, label %bb.nph3, label %return
68 bb.nph: ; preds = %bb2.preheader
69 %tmp1 = mul i64 %tmp16, %i.02 ; <i64> [#uses=1]
70 %tmp2 = mul i64 %tmp19, %i.02 ; <i64> [#uses=1]
73 bb1: ; preds = %bb2, %bb.nph
74 %j.01 = phi i64 [ %tmp9, %bb2 ], [ 0, %bb.nph ] ; <i64> [#uses=3]
75 %tmp3 = add i64 %j.01, %tmp1 ; <i64> [#uses=1]
76 %tmp4 = add i64 %j.01, %tmp2 ; <i64> [#uses=1]
77 %z0 = add i64 %tmp3, 5203
78 %tmp5 = getelementptr double, ptr addrspace(1) %p, i64 %z0 ; <ptr addrspace(1)> [#uses=1]
79 %tmp6 = load double, ptr addrspace(1) %tmp5, align 8 ; <double> [#uses=1]
80 %tmp7 = fdiv double %tmp6, 2.100000e+00 ; <double> [#uses=1]
81 %z1 = add i64 %tmp4, 5203
82 %tmp8 = getelementptr double, ptr addrspace(1) %p, i64 %z1 ; <ptr addrspace(1)> [#uses=1]
83 store double %tmp7, ptr addrspace(1) %tmp8, align 8
84 %tmp9 = add i64 %j.01, 1 ; <i64> [#uses=2]
88 %tmp10 = icmp slt i64 %tmp9, %m ; <i1> [#uses=1]
89 br i1 %tmp10, label %bb1, label %bb2.bb3_crit_edge
91 bb2.bb3_crit_edge: ; preds = %bb2
94 bb3: ; preds = %bb2.preheader, %bb2.bb3_crit_edge
95 %tmp11 = add i64 %i.02, 1 ; <i64> [#uses=2]
99 %tmp12 = icmp slt i64 %tmp11, %n ; <i1> [#uses=1]
100 br i1 %tmp12, label %bb2.preheader, label %bb4.return_crit_edge
102 bb4.return_crit_edge: ; preds = %bb4
103 br label %bb4.return_crit_edge.split
105 bb4.return_crit_edge.split: ; preds = %bb.nph3, %bb4.return_crit_edge
108 bb.nph3: ; preds = %entry
109 %tmp13 = icmp sgt i64 %m, 0 ; <i1> [#uses=1]
110 %tmp14 = mul i64 %n, 37 ; <i64> [#uses=1]
111 %tmp15 = mul i64 %tmp14, %o ; <i64> [#uses=1]
112 %tmp16 = mul i64 %tmp15, %q ; <i64> [#uses=1]
113 %tmp17 = mul i64 %n, 37 ; <i64> [#uses=1]
114 %tmp18 = mul i64 %tmp17, %o ; <i64> [#uses=1]
115 %tmp19 = mul i64 %tmp18, %q ; <i64> [#uses=1]
116 br i1 %tmp13, label %bb.nph3.split, label %bb4.return_crit_edge.split
118 bb.nph3.split: ; preds = %bb.nph3
119 br label %bb2.preheader
121 bb2.preheader: ; preds = %bb.nph3.split, %bb4
122 %i.02 = phi i64 [ %tmp11, %bb4 ], [ 0, %bb.nph3.split ] ; <i64> [#uses=3]
123 br i1 true, label %bb.nph, label %bb3
125 return: ; preds = %bb4.return_crit_edge.split, %entry