1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -O3 -S | FileCheck %s
3 ; RUN: opt < %s -passes='default<O3>' -S | FileCheck %s
5 ; This is based on the following most basic C++ code:
10 ; std::array<int, 6> arr;
17 ; Not only should the loops be unrolled, no alloca's should be left there.
19 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
20 target triple = "x86_64-unknown-linux-gnu"
22 %"struct.std::array" = type { [6 x i32] }
24 define dso_local void @_Z3fooi(i32 %cnt) {
25 ; CHECK-LABEL: @_Z3fooi(
27 ; CHECK-NEXT: [[INC:%.*]] = add nsw i32 [[CNT:%.*]], 1
28 ; CHECK-NEXT: [[INC_1:%.*]] = add nsw i32 [[CNT]], 2
29 ; CHECK-NEXT: [[INC_2:%.*]] = add nsw i32 [[CNT]], 3
30 ; CHECK-NEXT: [[INC_3:%.*]] = add nsw i32 [[CNT]], 4
31 ; CHECK-NEXT: [[INC_4:%.*]] = add nsw i32 [[CNT]], 5
32 ; CHECK-NEXT: [[INC_5:%.*]] = add nsw i32 [[CNT]], 6
33 ; CHECK-NEXT: call void @_Z3usei(i32 [[INC]])
34 ; CHECK-NEXT: call void @_Z3usei(i32 [[INC_1]])
35 ; CHECK-NEXT: call void @_Z3usei(i32 [[INC_2]])
36 ; CHECK-NEXT: call void @_Z3usei(i32 [[INC_3]])
37 ; CHECK-NEXT: call void @_Z3usei(i32 [[INC_4]])
38 ; CHECK-NEXT: call void @_Z3usei(i32 [[INC_5]])
39 ; CHECK-NEXT: ret void
42 %cnt.addr = alloca i32
43 %arr = alloca %"struct.std::array"
44 %__range1 = alloca %"struct.std::array"*
45 %__begin1 = alloca i32*
48 %__range12 = alloca %"struct.std::array"*
49 %__begin13 = alloca i32*
50 %__end15 = alloca i32*
52 store i32 %cnt, i32* %cnt.addr
53 %0 = bitcast %"struct.std::array"* %arr to i8*
54 call void @llvm.lifetime.start.p0i8(i64 24, i8* %0)
55 %1 = bitcast %"struct.std::array"** %__range1 to i8*
56 call void @llvm.lifetime.start.p0i8(i64 8, i8* %1)
57 store %"struct.std::array"* %arr, %"struct.std::array"** %__range1
58 %2 = bitcast i32** %__begin1 to i8*
59 call void @llvm.lifetime.start.p0i8(i64 8, i8* %2)
60 %3 = load %"struct.std::array"*, %"struct.std::array"** %__range1
61 %call = call i32* @_ZNSt5arrayIiLm6EE5beginEv(%"struct.std::array"* %3)
62 store i32* %call, i32** %__begin1
63 %4 = bitcast i32** %__end1 to i8*
64 call void @llvm.lifetime.start.p0i8(i64 8, i8* %4)
65 %5 = load %"struct.std::array"*, %"struct.std::array"** %__range1
66 %call1 = call i32* @_ZNSt5arrayIiLm6EE3endEv(%"struct.std::array"* %5)
67 store i32* %call1, i32** %__end1
71 %6 = load i32*, i32** %__begin1
72 %7 = load i32*, i32** %__end1
73 %cmp = icmp ne i32* %6, %7
74 br i1 %cmp, label %for.body, label %for.cond.cleanup
77 %8 = bitcast i32** %__end1 to i8*
78 call void @llvm.lifetime.end.p0i8(i64 8, i8* %8)
79 %9 = bitcast i32** %__begin1 to i8*
80 call void @llvm.lifetime.end.p0i8(i64 8, i8* %9)
81 %10 = bitcast %"struct.std::array"** %__range1 to i8*
82 call void @llvm.lifetime.end.p0i8(i64 8, i8* %10)
86 %11 = bitcast i32** %elt to i8*
87 call void @llvm.lifetime.start.p0i8(i64 8, i8* %11)
88 %12 = load i32*, i32** %__begin1
89 store i32* %12, i32** %elt
90 %13 = load i32, i32* %cnt.addr
91 %inc = add nsw i32 %13, 1
92 store i32 %inc, i32* %cnt.addr
93 %14 = load i32*, i32** %elt
94 store i32 %inc, i32* %14
95 %15 = bitcast i32** %elt to i8*
96 call void @llvm.lifetime.end.p0i8(i64 8, i8* %15)
100 %16 = load i32*, i32** %__begin1
101 %incdec.ptr = getelementptr inbounds i32, i32* %16, i32 1
102 store i32* %incdec.ptr, i32** %__begin1
106 %17 = bitcast %"struct.std::array"** %__range12 to i8*
107 call void @llvm.lifetime.start.p0i8(i64 8, i8* %17)
108 store %"struct.std::array"* %arr, %"struct.std::array"** %__range12
109 %18 = bitcast i32** %__begin13 to i8*
110 call void @llvm.lifetime.start.p0i8(i64 8, i8* %18)
111 %19 = load %"struct.std::array"*, %"struct.std::array"** %__range12
112 %call4 = call i32* @_ZNSt5arrayIiLm6EE5beginEv(%"struct.std::array"* %19)
113 store i32* %call4, i32** %__begin13
114 %20 = bitcast i32** %__end15 to i8*
115 call void @llvm.lifetime.start.p0i8(i64 8, i8* %20)
116 %21 = load %"struct.std::array"*, %"struct.std::array"** %__range12
117 %call6 = call i32* @_ZNSt5arrayIiLm6EE3endEv(%"struct.std::array"* %21)
118 store i32* %call6, i32** %__end15
122 %22 = load i32*, i32** %__begin13
123 %23 = load i32*, i32** %__end15
124 %cmp8 = icmp ne i32* %22, %23
125 br i1 %cmp8, label %for.body10, label %for.cond.cleanup9
128 %24 = bitcast i32** %__end15 to i8*
129 call void @llvm.lifetime.end.p0i8(i64 8, i8* %24)
130 %25 = bitcast i32** %__begin13 to i8*
131 call void @llvm.lifetime.end.p0i8(i64 8, i8* %25)
132 %26 = bitcast %"struct.std::array"** %__range12 to i8*
133 call void @llvm.lifetime.end.p0i8(i64 8, i8* %26)
137 %27 = bitcast i32** %elt11 to i8*
138 call void @llvm.lifetime.start.p0i8(i64 8, i8* %27)
139 %28 = load i32*, i32** %__begin13
140 store i32* %28, i32** %elt11
141 %29 = load i32*, i32** %elt11
142 %30 = load i32, i32* %29
143 call void @_Z3usei(i32 %30)
144 %31 = bitcast i32** %elt11 to i8*
145 call void @llvm.lifetime.end.p0i8(i64 8, i8* %31)
149 %32 = load i32*, i32** %__begin13
150 %incdec.ptr13 = getelementptr inbounds i32, i32* %32, i32 1
151 store i32* %incdec.ptr13, i32** %__begin13
155 %33 = bitcast %"struct.std::array"* %arr to i8*
156 call void @llvm.lifetime.end.p0i8(i64 24, i8* %33)
160 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
162 define linkonce_odr dso_local i32* @_ZNSt5arrayIiLm6EE5beginEv(%"struct.std::array"* %this) {
164 %this.addr = alloca %"struct.std::array"*
165 store %"struct.std::array"* %this, %"struct.std::array"** %this.addr
166 %this1 = load %"struct.std::array"*, %"struct.std::array"** %this.addr
167 %call = call i32* @_ZNSt5arrayIiLm6EE4dataEv(%"struct.std::array"* %this1)
171 define linkonce_odr dso_local i32* @_ZNSt5arrayIiLm6EE3endEv(%"struct.std::array"* %this) {
173 %this.addr = alloca %"struct.std::array"*
174 store %"struct.std::array"* %this, %"struct.std::array"** %this.addr
175 %this1 = load %"struct.std::array"*, %"struct.std::array"** %this.addr
176 %call = call i32* @_ZNSt5arrayIiLm6EE4dataEv(%"struct.std::array"* %this1)
177 %add.ptr = getelementptr inbounds i32, i32* %call, i64 6
181 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
183 declare dso_local void @_Z3usei(i32)
185 define linkonce_odr dso_local i32* @_ZNSt5arrayIiLm6EE4dataEv(%"struct.std::array"* %this) {
187 %this.addr = alloca %"struct.std::array"*
188 store %"struct.std::array"* %this, %"struct.std::array"** %this.addr
189 %this1 = load %"struct.std::array"*, %"struct.std::array"** %this.addr
190 %_M_elems = getelementptr inbounds %"struct.std::array", %"struct.std::array"* %this1, i32 0, i32 0
191 %call = call i32* @_ZNSt14__array_traitsIiLm6EE6_S_ptrERA6_Ki([6 x i32]* nonnull align 4 dereferenceable(24) %_M_elems)
195 define linkonce_odr dso_local i32* @_ZNSt14__array_traitsIiLm6EE6_S_ptrERA6_Ki([6 x i32]* nonnull align 4 dereferenceable(24) %__t) {
197 %__t.addr = alloca [6 x i32]*
198 store [6 x i32]* %__t, [6 x i32]** %__t.addr
199 %0 = load [6 x i32]*, [6 x i32]** %__t.addr
200 %arraydecay = getelementptr inbounds [6 x i32], [6 x i32]* %0, i64 0, i64 0