302 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 52; RUN: opt < %s -passes='sroa<preserve-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-PRESERVE-CFG3; RUN: opt < %s -passes='sroa<modify-cfg>' -S | FileCheck %s --check-prefixes=CHECK,CHECK-MODIFY-CFG4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64"5 6; Basic tree-structured merge: 4 stores of <2 x float> into <8 x float>7define <8 x float> @basic_tree_merge(<2 x float> %a, <2 x float> %b, <2 x float> %c, <2 x float> %d) {8; CHECK-LABEL: define <8 x float> @basic_tree_merge(9; CHECK-SAME: <2 x float> [[A:%.*]], <2 x float> [[B:%.*]], <2 x float> [[C:%.*]], <2 x float> [[D:%.*]]) {10; CHECK-NEXT: [[ENTRY:.*:]]11; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x float> [[A]], <2 x float> [[B]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>12; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[C]], <2 x float> [[D]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>13; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x float> [[TMP0]], <4 x float> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>14; CHECK-NEXT: ret <8 x float> [[TMP2]]15;16entry:17 %alloca = alloca [8 x float]18 19 %ptr0 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 020 store <2 x float> %a, ptr %ptr021 22 %ptr1 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 223 store <2 x float> %b, ptr %ptr124 25 %ptr2 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 426 store <2 x float> %c, ptr %ptr227 28 %ptr3 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 629 store <2 x float> %d, ptr %ptr330 31 %result = load <8 x float>, ptr %alloca32 ret <8 x float> %result33}34 35define void @multiple_partitions(<2 x float> %a, <2 x float> %b, <2 x float> %c, <2 x float> %d, ptr %e, ptr %f) {36; CHECK-LABEL: define void @multiple_partitions(37; CHECK-SAME: <2 x float> [[A:%.*]], <2 x float> [[B:%.*]], <2 x float> [[C:%.*]], <2 x float> [[D:%.*]], ptr [[E:%.*]], ptr [[F:%.*]]) {38; CHECK-NEXT: [[ENTRY:.*:]]39; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x float> [[A]], <2 x float> [[B]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>40; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[C]], <2 x float> [[D]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>41; CHECK-NEXT: store <4 x float> [[TMP0]], ptr [[E]], align 1642; CHECK-NEXT: store <4 x float> [[TMP1]], ptr [[F]], align 1643; CHECK-NEXT: ret void44;45entry:46 %alloca = alloca [8 x float]47 48 %ptr0 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 049 store <2 x float> %a, ptr %ptr050 51 %ptr1 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 252 store <2 x float> %b, ptr %ptr153 54 %ptr2 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 455 store <2 x float> %c, ptr %ptr256 57 %ptr3 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 658 store <2 x float> %d, ptr %ptr359 60 %result1 = load <4 x float>, ptr %alloca61 62 %ptr_offset4 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 463 %result2 = load <4 x float>, ptr %ptr_offset464 65 store <4 x float> %result1, ptr %e66 store <4 x float> %result2, ptr %f67 68 ret void69}70 71; Out-of-order stores: stores happen in non-sequential order72define <8 x i32> @out_of_order_stores(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c, <2 x i32> %d) {73; CHECK-LABEL: define <8 x i32> @out_of_order_stores(74; CHECK-SAME: <2 x i32> [[A:%.*]], <2 x i32> [[B:%.*]], <2 x i32> [[C:%.*]], <2 x i32> [[D:%.*]]) {75; CHECK-NEXT: [[ENTRY:.*:]]76; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x i32> [[A]], <2 x i32> [[B]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>77; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x i32> [[C]], <2 x i32> [[D]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>78; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i32> [[TMP0]], <4 x i32> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>79; CHECK-NEXT: ret <8 x i32> [[TMP2]]80;81entry:82 %alloca = alloca [8 x i32]83 84 %ptr2 = getelementptr inbounds [8 x i32], ptr %alloca, i32 0, i32 485 store <2 x i32> %c, ptr %ptr286 87 %ptr0 = getelementptr inbounds [8 x i32], ptr %alloca, i32 0, i32 088 store <2 x i32> %a, ptr %ptr089 90 %ptr3 = getelementptr inbounds [8 x i32], ptr %alloca, i32 0, i32 691 store <2 x i32> %d, ptr %ptr392 93 %ptr1 = getelementptr inbounds [8 x i32], ptr %alloca, i32 0, i32 294 store <2 x i32> %b, ptr %ptr195 96 %result = load <8 x i32>, ptr %alloca97 ret <8 x i32> %result98}99 100; Single element stores: 8 stores of <1 x i16> into <8 x i16>101define <8 x i16> @single_element_stores(<1 x i16> %a, <1 x i16> %b, <1 x i16> %c, <1 x i16> %d, <1 x i16> %e, <1 x i16> %f, <1 x i16> %g, <1 x i16> %h) {102; CHECK-LABEL: define <8 x i16> @single_element_stores(103; CHECK-SAME: <1 x i16> [[A:%.*]], <1 x i16> [[B:%.*]], <1 x i16> [[C:%.*]], <1 x i16> [[D:%.*]], <1 x i16> [[E:%.*]], <1 x i16> [[F:%.*]], <1 x i16> [[G:%.*]], <1 x i16> [[H:%.*]]) {104; CHECK-NEXT: [[ENTRY:.*:]]105; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <1 x i16> [[A]], <1 x i16> [[B]], <2 x i32> <i32 0, i32 1>106; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <1 x i16> [[C]], <1 x i16> [[D]], <2 x i32> <i32 0, i32 1>107; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <1 x i16> [[E]], <1 x i16> [[F]], <2 x i32> <i32 0, i32 1>108; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <1 x i16> [[G]], <1 x i16> [[H]], <2 x i32> <i32 0, i32 1>109; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <2 x i16> [[TMP0]], <2 x i16> [[TMP1]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>110; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <2 x i16> [[TMP2]], <2 x i16> [[TMP3]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>111; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <4 x i16> [[TMP4]], <4 x i16> [[TMP5]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>112; CHECK-NEXT: ret <8 x i16> [[TMP6]]113;114entry:115 %alloca = alloca [8 x i16]116 117 %ptr0 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 0118 store <1 x i16> %a, ptr %ptr0119 %ptr1 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 1120 store <1 x i16> %b, ptr %ptr1121 %ptr2 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 2122 store <1 x i16> %c, ptr %ptr2123 %ptr3 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 3124 store <1 x i16> %d, ptr %ptr3125 %ptr4 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 4126 store <1 x i16> %e, ptr %ptr4127 %ptr5 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 5128 store <1 x i16> %f, ptr %ptr5129 %ptr6 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 6130 store <1 x i16> %g, ptr %ptr6131 %ptr7 = getelementptr inbounds [8 x i16], ptr %alloca, i32 0, i32 7132 store <1 x i16> %h, ptr %ptr7133 134 %result = load <8 x i16>, ptr %alloca135 ret <8 x i16> %result136}137 138; Non-power-of-2: 3 stores of <2 x float> into <6 x float>139define <6 x float> @non_power_of_2(<2 x float> %a, <2 x float> %b, <2 x float> %c) {140; CHECK-LABEL: define <6 x float> @non_power_of_2(141; CHECK-SAME: <2 x float> [[A:%.*]], <2 x float> [[B:%.*]], <2 x float> [[C:%.*]]) {142; CHECK-NEXT: [[ENTRY:.*:]]143; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x float> [[A]], <2 x float> [[B]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>144; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[C]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>145; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x float> [[TMP0]], <4 x float> [[TMP1]], <6 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5>146; CHECK-NEXT: ret <6 x float> [[TMP2]]147;148entry:149 %alloca = alloca [6 x float]150 151 %ptr0 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 0152 store <2 x float> %a, ptr %ptr0153 154 %ptr1 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 2155 store <2 x float> %b, ptr %ptr1156 157 %ptr2 = getelementptr inbounds [6 x float], ptr %alloca, i32 0, i32 4158 store <2 x float> %c, ptr %ptr2159 160 %result = load <6 x float>, ptr %alloca161 ret <6 x float> %result162}163 164; Store with different size of vectors165define <7 x float> @store_with_different_size_of_vectors(<1 x float> %a, <4 x float> %b, <2 x float> %c) {166; CHECK-LABEL: define <7 x float> @store_with_different_size_of_vectors(167; CHECK-SAME: <1 x float> [[A:%.*]], <4 x float> [[B:%.*]], <2 x float> [[C:%.*]]) {168; CHECK-NEXT: [[ENTRY:.*:]]169; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <1 x float> [[A]], <1 x float> poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison>170; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x float> [[TMP0]], <4 x float> [[B]], <5 x i32> <i32 0, i32 4, i32 5, i32 6, i32 7>171; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <2 x float> [[C]], <2 x float> poison, <5 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison>172; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <5 x float> [[TMP1]], <5 x float> [[TMP2]], <7 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6>173; CHECK-NEXT: ret <7 x float> [[TMP3]]174;175entry:176 %alloca = alloca [7 x float]177 178 %ptr0 = getelementptr inbounds [7 x float], ptr %alloca, i32 0, i32 0179 store <1 x float> %a, ptr %ptr0180 181 %ptr1 = getelementptr inbounds [7 x float], ptr %alloca, i32 0, i32 1182 store <4 x float> %b, ptr %ptr1183 184 %ptr2 = getelementptr inbounds [7 x float], ptr %alloca, i32 0, i32 5185 store <2 x float> %c, ptr %ptr2186 187 %result = load <7 x float>, ptr %alloca188 ret <7 x float> %result189}190 191; Load and store with different element type192define <4 x double> @load_store_different_element_type(<2 x i32> %a, <2 x float> %b, <2 x float> %c, <2 x i32> %d) {193; CHECK-LABEL: define <4 x double> @load_store_different_element_type(194; CHECK-SAME: <2 x i32> [[A:%.*]], <2 x float> [[B:%.*]], <2 x float> [[C:%.*]], <2 x i32> [[D:%.*]]) {195; CHECK-NEXT: [[ENTRY:.*:]]196; CHECK-NEXT: [[TMP0:%.*]] = bitcast <2 x i32> [[A]] to <1 x double>197; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x float> [[B]] to <1 x double>198; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <1 x double> [[TMP0]], <1 x double> [[TMP1]], <2 x i32> <i32 0, i32 1>199; CHECK-NEXT: [[TMP3:%.*]] = bitcast <2 x float> [[C]] to <1 x double>200; CHECK-NEXT: [[TMP4:%.*]] = bitcast <2 x i32> [[D]] to <1 x double>201; CHECK-NEXT: [[TMP5:%.*]] = shufflevector <1 x double> [[TMP3]], <1 x double> [[TMP4]], <2 x i32> <i32 0, i32 1>202; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> [[TMP5]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>203; CHECK-NEXT: ret <4 x double> [[TMP6]]204;205entry:206 %alloca = alloca [8 x float]207 208 %ptr0 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 0209 store <2 x i32> %a, ptr %ptr0210 211 %ptr1 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 2212 store <2 x float> %b, ptr %ptr1213 214 %ptr2 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 4215 store <2 x float> %c, ptr %ptr2216 217 %ptr3 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 6218 store <2 x i32> %d, ptr %ptr3219 220 %result = load <4 x double>, ptr %alloca221 ret <4 x double> %result222}223 224define <8 x float> @bitcast_needed(<2 x i32> %a, <2 x i16> %b, <12 x i8> %c, <1 x i64> %d) {225; CHECK-LABEL: define <8 x float> @bitcast_needed(226; CHECK-SAME: <2 x i32> [[A:%.*]], <2 x i16> [[B:%.*]], <12 x i8> [[C:%.*]], <1 x i64> [[D:%.*]]) {227; CHECK-NEXT: [[ENTRY:.*:]]228; CHECK-NEXT: [[TMP0:%.*]] = bitcast <2 x i32> [[A]] to <2 x float>229; CHECK-NEXT: [[TMP1:%.*]] = bitcast <2 x i16> [[B]] to <1 x float>230; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <1 x float> [[TMP1]], <1 x float> poison, <2 x i32> <i32 0, i32 poison>231; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <2 x float> [[TMP0]], <2 x float> [[TMP2]], <3 x i32> <i32 0, i32 1, i32 2>232; CHECK-NEXT: [[TMP5:%.*]] = bitcast <12 x i8> [[C]] to <3 x float>233; CHECK-NEXT: [[TMP4:%.*]] = bitcast <1 x i64> [[D]] to <2 x float>234; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <2 x float> [[TMP4]], <2 x float> poison, <3 x i32> <i32 0, i32 1, i32 poison>235; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <3 x float> [[TMP5]], <3 x float> [[TMP9]], <5 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4>236; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <3 x float> [[TMP3]], <3 x float> poison, <5 x i32> <i32 0, i32 1, i32 2, i32 poison, i32 poison>237; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <5 x float> [[TMP8]], <5 x float> [[TMP7]], <8 x i32> <i32 0, i32 1, i32 2, i32 5, i32 6, i32 7, i32 8, i32 9>238; CHECK-NEXT: ret <8 x float> [[TMP6]]239;240entry:241 %alloca = alloca [8 x float]242 243 %ptr0 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 0244 store <2 x i32> %a, ptr %ptr0245 246 %ptr1 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 2247 store <2 x i16> %b, ptr %ptr1248 249 %ptr2 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 3250 store <12 x i8> %c, ptr %ptr2251 252 %ptr3 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 6253 store <1 x i64> %d, ptr %ptr3254 255 %result = load <8 x float>, ptr %alloca256 ret <8 x float> %result257}258 259define <8 x float> @load_in_different_blocks(<2 x float> %a, <2 x float> %b, <2 x float> %c, <2 x float> %d, i1 %cond) {260; CHECK-LABEL: define <8 x float> @load_in_different_blocks(261; CHECK-SAME: <2 x float> [[A:%.*]], <2 x float> [[B:%.*]], <2 x float> [[C:%.*]], <2 x float> [[D:%.*]], i1 [[COND:%.*]]) {262; CHECK-NEXT: [[ENTRY:.*]]:263; CHECK-NEXT: [[TMP0:%.*]] = shufflevector <2 x float> [[A]], <2 x float> [[B]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>264; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[C]], <2 x float> [[D]], <4 x i32> <i32 0, i32 1, i32 2, i32 3>265; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x float> [[TMP0]], <4 x float> [[TMP1]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>266; CHECK-NEXT: br i1 [[COND]], label %[[TRUEBRANCH:.*]], label %[[FALSEBRANCH:.*]]267; CHECK: [[TRUEBRANCH]]:268; CHECK-NEXT: br label %[[FALSEBRANCH]]269; CHECK: [[FALSEBRANCH]]:270; CHECK-NEXT: [[RESULT:%.*]] = phi <8 x float> [ poison, %[[ENTRY]] ], [ [[TMP2]], %[[TRUEBRANCH]] ]271; CHECK-NEXT: ret <8 x float> [[RESULT]]272;273entry:274 %alloca = alloca [8 x float]275 276 %ptr0 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 0277 store <2 x float> %a, ptr %ptr0278 279 %ptr1 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 2280 store <2 x float> %b, ptr %ptr1281 282 %ptr2 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 4283 store <2 x float> %c, ptr %ptr2284 285 %ptr3 = getelementptr inbounds [8 x float], ptr %alloca, i32 0, i32 6286 store <2 x float> %d, ptr %ptr3287 288 br i1 %cond, label %TrueBranch, label %FalseBranch289 290TrueBranch:291 %load1 = load <8 x float>, ptr %alloca292 br label %FalseBranch293 294FalseBranch:295 %result = phi <8 x float> [ poison, %entry ], [ %load1, %TrueBranch ]296 ret <8 x float> %result297}298 299;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:300; CHECK-MODIFY-CFG: {{.*}}301; CHECK-PRESERVE-CFG: {{.*}}302