1 ; RUN: opt -instcombine -S < %s | FileCheck %s 2 3 target datalayout = "e-i64:64-f80:128-n8:16:32:64" 4 target triple = "x86_64-unknown-linux-gnu" 5 6 %A__vtbl = type { i8*, i32 (%A*)* } 7 %A = type { %A__vtbl* } 8 %B = type { i8*, i64 } 9 10 @A__vtblZ = constant %A__vtbl { i8* null, i32 (%A*)* @A.foo } 11 12 declare i32 @A.foo(%A* nocapture %this) 13 14 define void @storeA(%A* %a.ptr) { 15 ; CHECK-LABEL: storeA 16 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds %A, %A* %a.ptr, i64 0, i32 0 17 ; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8 18 ; CHECK-NEXT: ret void 19 store %A { %A__vtbl* @A__vtblZ }, %A* %a.ptr, align 8 20 ret void 21 } 22 23 define void @storeB(%B* %b.ptr) { 24 ; CHECK-LABEL: storeB 25 ; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 0 26 ; CHECK-NEXT: store i8* null, i8** [[GEP1]], align 8 27 ; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 1 28 ; CHECK-NEXT: store i64 42, i64* [[GEP2]], align 8 29 ; CHECK-NEXT: ret void 30 store %B { i8* null, i64 42 }, %B* %b.ptr, align 8 31 ret void 32 } 33 34 define void @storeStructOfA({ %A }* %sa.ptr) { 35 ; CHECK-LABEL: storeStructOfA 36 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { %A }, { %A }* %sa.ptr, i64 0, i32 0, i32 0 37 ; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8 38 ; CHECK-NEXT: ret void 39 store { %A } { %A { %A__vtbl* @A__vtblZ } }, { %A }* %sa.ptr, align 8 40 ret void 41 } 42 43 define void @storeArrayOfA([1 x %A]* %aa.ptr) { 44 ; CHECK-LABEL: storeArrayOfA 45 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds [1 x %A], [1 x %A]* %aa.ptr, i64 0, i64 0, i32 0 46 ; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8 47 ; CHECK-NEXT: ret void 48 store [1 x %A] [%A { %A__vtbl* @A__vtblZ }], [1 x %A]* %aa.ptr, align 8 49 ret void 50 } 51 52 define void @storeStructOfArrayOfA({ [1 x %A] }* %saa.ptr) { 53 ; CHECK-LABEL: storeStructOfArrayOfA 54 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { [1 x %A] }, { [1 x %A] }* %saa.ptr, i64 0, i32 0, i64 0, i32 0 55 ; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8 56 ; CHECK-NEXT: ret void 57 store { [1 x %A] } { [1 x %A] [%A { %A__vtbl* @A__vtblZ }] }, { [1 x %A] }* %saa.ptr, align 8 58 ret void 59 } 60 61 define void @storeArrayOfB([2 x %B]* %ab.ptr, [2 x %B] %ab) { 62 ; CHECK-LABEL: storeArrayOfB 63 ; CHECK-NEXT: [[EVB0:%[a-z0-9\.]+]] = extractvalue [2 x %B] %ab, 0 64 ; CHECK-NEXT: [[GEP0:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 0, i32 0 65 ; CHECK-NEXT: [[EV0:%[a-z0-9\.]+]] = extractvalue %B [[EVB0]], 0 66 ; CHECK-NEXT: store i8* [[EV0]], i8** [[GEP0]], align 8 67 ; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 0, i32 1 68 ; CHECK-NEXT: [[EV1:%[a-z0-9\.]+]] = extractvalue %B [[EVB0]], 1 69 ; CHECK-NEXT: store i64 [[EV1]], i64* [[GEP1]], align 8 70 ; CHECK-NEXT: [[EVB1:%[a-z0-9\.]+]] = extractvalue [2 x %B] %ab, 1 71 ; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 1, i32 0 72 ; CHECK-NEXT: [[EV2:%[a-z0-9\.]+]] = extractvalue %B [[EVB1]], 0 73 ; CHECK-NEXT: store i8* [[EV2]], i8** [[GEP2]], align 8 74 ; CHECK-NEXT: [[GEP3:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 1, i32 1 75 ; CHECK-NEXT: [[EV3:%[a-z0-9\.]+]] = extractvalue %B [[EVB1]], 1 76 ; CHECK-NEXT: store i64 [[EV3]], i64* [[GEP3]], align 8 77 ; CHECK-NEXT: ret void 78 store [2 x %B] %ab, [2 x %B]* %ab.ptr, align 8 79 ret void 80 } 81 82 define %A @loadA(%A* %a.ptr) { 83 ; CHECK-LABEL: loadA 84 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds %A, %A* %a.ptr, i64 0, i32 0 85 ; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8 86 ; CHECK-NEXT: [[IV:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0 87 ; CHECK-NEXT: ret %A [[IV]] 88 %1 = load %A, %A* %a.ptr, align 8 89 ret %A %1 90 } 91 92 define %B @loadB(%B* %b.ptr) { 93 ; CHECK-LABEL: loadB 94 ; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 0 95 ; CHECK-NEXT: [[LOAD1:%[a-z0-9\.]+]] = load i8*, i8** [[GEP1]], align 8 96 ; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %B undef, i8* [[LOAD1]], 0 97 ; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 1 98 ; CHECK-NEXT: [[LOAD2:%[a-z0-9\.]+]] = load i64, i64* [[GEP2]], align 8 99 ; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue %B [[IV1]], i64 [[LOAD2]], 1 100 ; CHECK-NEXT: ret %B [[IV2]] 101 %1 = load %B, %B* %b.ptr, align 8 102 ret %B %1 103 } 104 105 define { %A } @loadStructOfA({ %A }* %sa.ptr) { 106 ; CHECK-LABEL: loadStructOfA 107 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { %A }, { %A }* %sa.ptr, i64 0, i32 0, i32 0 108 ; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8 109 ; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0 110 ; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue { %A } undef, %A [[IV1]], 0 111 ; CHECK-NEXT: ret { %A } [[IV2]] 112 %1 = load { %A }, { %A }* %sa.ptr, align 8 113 ret { %A } %1 114 } 115 116 define [1 x %A] @loadArrayOfA([1 x %A]* %aa.ptr) { 117 ; CHECK-LABEL: loadArrayOfA 118 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds [1 x %A], [1 x %A]* %aa.ptr, i64 0, i64 0, i32 0 119 ; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8 120 ; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0 121 ; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue [1 x %A] undef, %A [[IV1]], 0 122 ; CHECK-NEXT: ret [1 x %A] [[IV2]] 123 %1 = load [1 x %A], [1 x %A]* %aa.ptr, align 8 124 ret [1 x %A] %1 125 } 126 127 define { [1 x %A] } @loadStructOfArrayOfA({ [1 x %A] }* %saa.ptr) { 128 ; CHECK-LABEL: loadStructOfArrayOfA 129 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { [1 x %A] }, { [1 x %A] }* %saa.ptr, i64 0, i32 0, i64 0, i32 0 130 ; CHECK-NEXT: [[LOAD:%[a-z0-9\.]+]] = load %A__vtbl*, %A__vtbl** [[GEP]], align 8 131 ; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %A undef, %A__vtbl* [[LOAD]], 0 132 ; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue [1 x %A] undef, %A [[IV1]], 0 133 ; CHECK-NEXT: [[IV3:%[a-z0-9\.]+]] = insertvalue { [1 x %A] } undef, [1 x %A] [[IV2]], 0 134 ; CHECK-NEXT: ret { [1 x %A] } [[IV3]] 135 %1 = load { [1 x %A] }, { [1 x %A] }* %saa.ptr, align 8 136 ret { [1 x %A] } %1 137 } 138 139 define { %A } @structOfA({ %A }* %sa.ptr) { 140 ; CHECK-LABEL: structOfA 141 ; CHECK-NEXT: [[GEP:%[a-z0-9\.]+]] = getelementptr inbounds { %A }, { %A }* %sa.ptr, i64 0, i32 0, i32 0 142 ; CHECK-NEXT: store %A__vtbl* @A__vtblZ, %A__vtbl** [[GEP]], align 8 143 ; CHECK-NEXT: ret { %A } { %A { %A__vtbl* @A__vtblZ } } 144 store { %A } { %A { %A__vtbl* @A__vtblZ } }, { %A }* %sa.ptr, align 8 145 %1 = load { %A }, { %A }* %sa.ptr, align 8 146 ret { %A } %1 147 } 148 149 define %B @structB(%B* %b.ptr) { 150 ; CHECK-LABEL: structB 151 ; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 0 152 ; CHECK-NEXT: store i8* null, i8** [[GEP1]], align 8 153 ; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds %B, %B* %b.ptr, i64 0, i32 1 154 ; CHECK-NEXT: store i64 42, i64* [[GEP2]], align 8 155 ; CHECK-NEXT: ret %B { i8* null, i64 42 } 156 store %B { i8* null, i64 42 }, %B* %b.ptr, align 8 157 %1 = load %B, %B* %b.ptr, align 8 158 ret %B %1 159 } 160 161 define [2 x %B] @loadArrayOfB([2 x %B]* %ab.ptr) { 162 ; CHECK-LABEL: loadArrayOfB 163 ; CHECK-NEXT: [[GEP1:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 0, i32 0 164 ; CHECK-NEXT: [[LOAD1:%[a-z0-9\.]+]] = load i8*, i8** [[GEP1]], align 8 165 ; CHECK-NEXT: [[IV1:%[a-z0-9\.]+]] = insertvalue %B undef, i8* [[LOAD1]], 0 166 ; CHECK-NEXT: [[GEP2:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 0, i32 1 167 ; CHECK-NEXT: [[LOAD2:%[a-z0-9\.]+]] = load i64, i64* [[GEP2]], align 8 168 ; CHECK-NEXT: [[IV2:%[a-z0-9\.]+]] = insertvalue %B [[IV1]], i64 [[LOAD2]], 1 169 ; CHECK-NEXT: [[IV3:%[a-z0-9\.]+]] = insertvalue [2 x %B] undef, %B [[IV2]], 0 170 ; CHECK-NEXT: [[GEP3:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 1, i32 0 171 ; CHECK-NEXT: [[LOAD3:%[a-z0-9\.]+]] = load i8*, i8** [[GEP3]], align 8 172 ; CHECK-NEXT: [[IV4:%[a-z0-9\.]+]] = insertvalue %B undef, i8* [[LOAD3]], 0 173 ; CHECK-NEXT: [[GEP4:%[a-z0-9\.]+]] = getelementptr inbounds [2 x %B], [2 x %B]* %ab.ptr, i64 0, i64 1, i32 1 174 ; CHECK-NEXT: [[LOAD4:%[a-z0-9\.]+]] = load i64, i64* [[GEP4]], align 8 175 ; CHECK-NEXT: [[IV5:%[a-z0-9\.]+]] = insertvalue %B [[IV4]], i64 [[LOAD4]], 1 176 ; CHECK-NEXT: [[IV6:%[a-z0-9\.]+]] = insertvalue [2 x %B] [[IV3]], %B [[IV5]], 1 177 ; CHECK-NEXT: ret [2 x %B] [[IV6]] 178 %1 = load [2 x %B], [2 x %B]* %ab.ptr, align 8 179 ret [2 x %B] %1 180 } 181 182 %struct.S = type <{ i8, %struct.T }> 183 %struct.T = type { i32, i32 } 184 185 ; Make sure that we do not increase alignment of packed struct element 186 define i32 @packed_alignment(%struct.S* dereferenceable(9) %s) { 187 ; CHECK-LABEL: packed_alignment 188 ; CHECK-NEXT: %tv.elt1 = getelementptr inbounds %struct.S, %struct.S* %s, i64 0, i32 1, i32 1 189 ; CHECK-NEXT: %tv.unpack2 = load i32, i32* %tv.elt1, align 1 190 ; CHECK-NEXT: ret i32 %tv.unpack2 191 %t = getelementptr inbounds %struct.S, %struct.S* %s, i32 0, i32 1 192 %tv = load %struct.T, %struct.T* %t, align 1 193 %v = extractvalue %struct.T %tv, 1 194 ret i32 %v 195 } 196 197 %struct.U = type {i8, i8, i8, i8, i8, i8, i8, i8, i64} 198 199 define void @check_alignment(%struct.U* %u, %struct.U* %v) { 200 ; CHECK-LABEL: check_alignment 201 ; CHECK: load i8, i8* {{.*}}, align 8 202 ; CHECK: load i8, i8* {{.*}}, align 1 203 ; CHECK: load i8, i8* {{.*}}, align 2 204 ; CHECK: load i8, i8* {{.*}}, align 1 205 ; CHECK: load i8, i8* {{.*}}, align 4 206 ; CHECK: load i8, i8* {{.*}}, align 1 207 ; CHECK: load i8, i8* {{.*}}, align 2 208 ; CHECK: load i8, i8* {{.*}}, align 1 209 ; CHECK: load i64, i64* {{.*}}, align 8 210 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 8 211 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 1 212 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 2 213 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 1 214 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 4 215 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 1 216 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 2 217 ; CHECK: store i8 {{.*}}, i8* {{.*}}, align 1 218 ; CHECK: store i64 {{.*}}, i64* {{.*}}, align 8 219 %1 = load %struct.U, %struct.U* %u 220 store %struct.U %1, %struct.U* %v 221 ret void 222 } 223