1206 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4 5declare void @use(<2 x i4>)6declare void @use_fp(<2 x float>)7 8define i32 @test2(float %f) {9; CHECK-LABEL: @test2(10; CHECK-NEXT: [[T5:%.*]] = fmul float [[F:%.*]], [[F]]11; CHECK-NEXT: [[T21:%.*]] = bitcast float [[T5]] to i3212; CHECK-NEXT: ret i32 [[T21]]13;14 %t5 = fmul float %f, %f15 %t9 = insertelement <4 x float> undef, float %t5, i32 016 %t10 = insertelement <4 x float> %t9, float 0.000000e+00, i32 117 %t11 = insertelement <4 x float> %t10, float 0.000000e+00, i32 218 %t12 = insertelement <4 x float> %t11, float 0.000000e+00, i32 319 %t19 = bitcast <4 x float> %t12 to <4 x i32>20 %t21 = extractelement <4 x i32> %t19, i32 021 ret i32 %t2122}23 24define void @get_image() nounwind {25; CHECK-LABEL: @get_image(26; CHECK-NEXT: entry:27; CHECK-NEXT: [[TMP0:%.*]] = call i32 @fgetc(ptr null) #[[ATTR0:[0-9]+]]28; CHECK-NEXT: br i1 false, label [[BB2:%.*]], label [[BB3:%.*]]29; CHECK: bb2:30; CHECK-NEXT: br label [[BB3]]31; CHECK: bb3:32; CHECK-NEXT: unreachable33;34entry:35 %0 = call i32 @fgetc(ptr null) nounwind36 %1 = trunc i32 %0 to i837 %t2 = insertelement <100 x i8> zeroinitializer, i8 %1, i32 138 %t1 = extractelement <100 x i8> %t2, i32 039 %2 = icmp eq i8 %t1, 8040 br i1 %2, label %bb2, label %bb341 42bb2: ; preds = %entry43 br label %bb344 45bb3: ; preds = %bb2, %entry46 unreachable47}48 49; PR434050define void @vac(ptr nocapture %a) nounwind {51; CHECK-LABEL: @vac(52; CHECK-NEXT: entry:53; CHECK-NEXT: store <4 x float> zeroinitializer, ptr [[A:%.*]], align 1654; CHECK-NEXT: ret void55;56entry:57 %t1 = load <4 x float>, ptr %a ; <<4 x float>> [#uses=1]58 %vecins = insertelement <4 x float> %t1, float 0.000000e+00, i32 0 ; <<4 x float>> [#uses=1]59 %vecins4 = insertelement <4 x float> %vecins, float 0.000000e+00, i32 1; <<4 x float>> [#uses=1]60 %vecins6 = insertelement <4 x float> %vecins4, float 0.000000e+00, i32 2; <<4 x float>> [#uses=1]61 %vecins8 = insertelement <4 x float> %vecins6, float 0.000000e+00, i32 3; <<4 x float>> [#uses=1]62 store <4 x float> %vecins8, ptr %a63 ret void64}65 66declare i32 @fgetc(ptr)67 68define <4 x float> @dead_shuffle_elt(<4 x float> %x, <2 x float> %y) nounwind {69; CHECK-LABEL: @dead_shuffle_elt(70; CHECK-NEXT: [[SHUFFLE_I:%.*]] = shufflevector <2 x float> [[Y:%.*]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>71; CHECK-NEXT: [[SHUFFLE9_I:%.*]] = shufflevector <4 x float> [[SHUFFLE_I]], <4 x float> [[X:%.*]], <4 x i32> <i32 0, i32 1, i32 6, i32 7>72; CHECK-NEXT: ret <4 x float> [[SHUFFLE9_I]]73;74 %shuffle.i = shufflevector <2 x float> %y, <2 x float> %y, <4 x i32> <i32 0, i32 1, i32 0, i32 1>75 %shuffle9.i = shufflevector <4 x float> %x, <4 x float> %shuffle.i, <4 x i32> <i32 4, i32 5, i32 2, i32 3>76 ret <4 x float> %shuffle9.i77}78 79define <2 x float> @test_fptrunc(double %f) {80; CHECK-LABEL: @test_fptrunc(81; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x double> <double poison, double 0.000000e+00>, double [[F:%.*]], i64 082; CHECK-NEXT: [[RET:%.*]] = fptrunc <2 x double> [[TMP1]] to <2 x float>83; CHECK-NEXT: ret <2 x float> [[RET]]84;85 %t9 = insertelement <4 x double> undef, double %f, i32 086 %t10 = insertelement <4 x double> %t9, double 0.000000e+00, i32 187 %t11 = insertelement <4 x double> %t10, double 0.000000e+00, i32 288 %t12 = insertelement <4 x double> %t11, double 0.000000e+00, i32 389 %t5 = fptrunc <4 x double> %t12 to <4 x float>90 %ret = shufflevector <4 x float> %t5, <4 x float> undef, <2 x i32> <i32 0, i32 1>91 ret <2 x float> %ret92}93 94define <2 x double> @test_fpext(float %f) {95; CHECK-LABEL: @test_fpext(96; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x float> <float poison, float 0.000000e+00>, float [[F:%.*]], i64 097; CHECK-NEXT: [[RET:%.*]] = fpext <2 x float> [[TMP1]] to <2 x double>98; CHECK-NEXT: ret <2 x double> [[RET]]99;100 %t9 = insertelement <4 x float> undef, float %f, i32 0101 %t10 = insertelement <4 x float> %t9, float 0.000000e+00, i32 1102 %t11 = insertelement <4 x float> %t10, float 0.000000e+00, i32 2103 %t12 = insertelement <4 x float> %t11, float 0.000000e+00, i32 3104 %t5 = fpext <4 x float> %t12 to <4 x double>105 %ret = shufflevector <4 x double> %t5, <4 x double> undef, <2 x i32> <i32 0, i32 1>106 ret <2 x double> %ret107}108 109define <4 x double> @test_shuffle(<4 x double> %f) {110; CHECK-LABEL: @test_shuffle(111; CHECK-NEXT: [[RET1:%.*]] = insertelement <4 x double> [[F:%.*]], double 1.000000e+00, i64 3112; CHECK-NEXT: ret <4 x double> [[RET1]]113;114 %ret = shufflevector <4 x double> %f, <4 x double> <double undef, double 1.0, double undef, double undef>, <4 x i32> <i32 0, i32 1, i32 2, i32 5>115 ret <4 x double> %ret116}117 118define <4 x float> @test_select(float %f, float %g) {119; CHECK-LABEL: @test_select(120; CHECK-NEXT: [[A3:%.*]] = insertelement <4 x float> <float poison, float poison, float poison, float 3.000000e+00>, float [[F:%.*]], i64 0121; CHECK-NEXT: [[RET:%.*]] = shufflevector <4 x float> [[A3]], <4 x float> <float poison, float 4.000000e+00, float 5.000000e+00, float poison>, <4 x i32> <i32 0, i32 5, i32 6, i32 3>122; CHECK-NEXT: ret <4 x float> [[RET]]123;124 %a0 = insertelement <4 x float> undef, float %f, i32 0125 %a1 = insertelement <4 x float> %a0, float 1.000000e+00, i32 1126 %a2 = insertelement <4 x float> %a1, float 2.000000e+00, i32 2127 %a3 = insertelement <4 x float> %a2, float 3.000000e+00, i32 3128 %b0 = insertelement <4 x float> undef, float %g, i32 0129 %b1 = insertelement <4 x float> %b0, float 4.000000e+00, i32 1130 %b2 = insertelement <4 x float> %b1, float 5.000000e+00, i32 2131 %b3 = insertelement <4 x float> %b2, float 6.000000e+00, i32 3132 %ret = select <4 x i1> <i1 true, i1 false, i1 false, i1 true>, <4 x float> %a3, <4 x float> %b3133 ret <4 x float> %ret134}135 136; Check that instcombine doesn't wrongly fold away the select completely.137 138define <2 x i64> @PR24922(<2 x i64> %v) {139; CHECK-LABEL: @PR24922(140; CHECK-NEXT: [[RESULT:%.*]] = select <2 x i1> <i1 ptrtoint (ptr @PR24922 to i1), i1 true>, <2 x i64> [[V:%.*]], <2 x i64> <i64 0, i64 poison>141; CHECK-NEXT: ret <2 x i64> [[RESULT]]142;143 %result = select <2 x i1> <i1 ptrtoint (ptr @PR24922 to i1), i1 true>, <2 x i64> %v, <2 x i64> zeroinitializer144 ret <2 x i64> %result145}146 147; The shuffle only demands the 0th (undef) element of 'out123', so everything should fold away.148 149define <4 x float> @inselt_shuf_no_demand(float %a1, float %a2, float %a3) {150; CHECK-LABEL: @inselt_shuf_no_demand(151; CHECK-NEXT: ret <4 x float> <float undef, float poison, float poison, float poison>152;153 %out1 = insertelement <4 x float> undef, float %a1, i32 1154 %out12 = insertelement <4 x float> %out1, float %a2, i32 2155 %out123 = insertelement <4 x float> %out12, float %a3, i32 3156 %shuffle = shufflevector <4 x float> %out123, <4 x float> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>157 ret <4 x float> %shuffle158}159 160; The shuffle only demands the 0th (undef) element of 'out123', so everything should fold away.161 162define <4 x float> @inselt_shuf_no_demand_commute(float %a1, float %a2, float %a3) {163; CHECK-LABEL: @inselt_shuf_no_demand_commute(164; CHECK-NEXT: ret <4 x float> <float undef, float poison, float poison, float poison>165;166 %out1 = insertelement <4 x float> undef, float %a1, i32 1167 %out12 = insertelement <4 x float> %out1, float %a2, i32 2168 %out123 = insertelement <4 x float> %out12, float %a3, i32 3169 %shuffle = shufflevector <4 x float> undef, <4 x float> %out123, <4 x i32> <i32 4, i32 undef, i32 undef, i32 undef>170 ret <4 x float> %shuffle171}172 173; The add uses 'out012' giving it multiple uses after the shuffle is transformed to also174; use 'out012'. The analysis should be able to see past that.175 176define <4 x i32> @inselt_shuf_no_demand_multiuse(i32 %a0, i32 %a1, <4 x i32> %b) {177; CHECK-LABEL: @inselt_shuf_no_demand_multiuse(178; CHECK-NEXT: [[OUT0:%.*]] = insertelement <4 x i32> poison, i32 [[A0:%.*]], i64 0179; CHECK-NEXT: [[OUT01:%.*]] = insertelement <4 x i32> [[OUT0]], i32 [[A1:%.*]], i64 1180; CHECK-NEXT: [[FOO:%.*]] = add <4 x i32> [[OUT01]], [[B:%.*]]181; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i32> [[FOO]], <4 x i32> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>182; CHECK-NEXT: ret <4 x i32> [[SHUFFLE]]183;184 %out0 = insertelement <4 x i32> undef, i32 %a0, i32 0185 %out01 = insertelement <4 x i32> %out0, i32 %a1, i32 1186 %out012 = insertelement <4 x i32> %out01, i32 %a0, i32 2187 %foo = add <4 x i32> %out012, %b188 %out0123 = insertelement <4 x i32> %foo, i32 %a1, i32 3189 %shuffle = shufflevector <4 x i32> %out0123, <4 x i32> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>190 ret <4 x i32> %shuffle191}192 193define <4 x float> @inselt_shuf_no_demand_bogus_insert_index_in_chain(float %a1, float %a2, float %a3, i32 %variable_index) {194; CHECK-LABEL: @inselt_shuf_no_demand_bogus_insert_index_in_chain(195; CHECK-NEXT: [[OUT12:%.*]] = insertelement <4 x float> <float undef, float poison, float poison, float poison>, float [[A2:%.*]], i32 [[VARIABLE_INDEX:%.*]]196; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x float> [[OUT12]], <4 x float> poison, <4 x i32> <i32 0, i32 poison, i32 poison, i32 poison>197; CHECK-NEXT: ret <4 x float> [[SHUFFLE]]198;199 %out1 = insertelement <4 x float> undef, float %a1, i32 1200 %out12 = insertelement <4 x float> %out1, float %a2, i32 %variable_index ; something unexpected201 %out123 = insertelement <4 x float> %out12, float %a3, i32 3202 %shuffle = shufflevector <4 x float> %out123, <4 x float> undef, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>203 ret <4 x float> %shuffle204}205 206; Test undef replacement in constant vector elements with binops.207 208define <3 x i8> @shuf_add(<3 x i8> %x) {209; CHECK-LABEL: @shuf_add(210; CHECK-NEXT: [[BO:%.*]] = add nsw <3 x i8> [[X:%.*]], <i8 poison, i8 2, i8 3>211; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 poison, i32 2>212; CHECK-NEXT: ret <3 x i8> [[R]]213;214 %bo = add nsw <3 x i8> %x, <i8 1, i8 2, i8 3>215 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 1, i32 undef, i32 2>216 ret <3 x i8> %r217}218 219define <3 x i8> @shuf_sub(<3 x i8> %x) {220; CHECK-LABEL: @shuf_sub(221; CHECK-NEXT: [[BO:%.*]] = sub nuw <3 x i8> <i8 1, i8 poison, i8 3>, [[X:%.*]]222; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 poison, i32 2>223; CHECK-NEXT: ret <3 x i8> [[R]]224;225 %bo = sub nuw <3 x i8> <i8 1, i8 2, i8 3>, %x226 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 poison, i32 2>227 ret <3 x i8> %r228}229 230define <3 x i8> @shuf_mul(<3 x i8> %x) {231; CHECK-LABEL: @shuf_mul(232; CHECK-NEXT: [[BO:%.*]] = mul nsw <3 x i8> [[X:%.*]], <i8 1, i8 poison, i8 3>233; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 2, i32 0>234; CHECK-NEXT: ret <3 x i8> [[R]]235;236 %bo = mul nsw <3 x i8> %x, <i8 1, i8 2, i8 3>237 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 2, i32 0>238 ret <3 x i8> %r239}240 241define <3 x i8> @shuf_and(<3 x i8> %x) {242; CHECK-LABEL: @shuf_and(243; CHECK-NEXT: [[BO:%.*]] = and <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 poison>244; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 1, i32 0>245; CHECK-NEXT: ret <3 x i8> [[R]]246;247 %bo = and <3 x i8> %x, <i8 1, i8 2, i8 3>248 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 1, i32 1, i32 0>249 ret <3 x i8> %r250}251 252define <3 x i8> @shuf_or(<3 x i8> %x) {253; CHECK-LABEL: @shuf_or(254; CHECK-NEXT: [[BO:%.*]] = or <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 poison>255; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 poison, i32 0>256; CHECK-NEXT: ret <3 x i8> [[R]]257;258 %bo = or <3 x i8> %x, <i8 1, i8 2, i8 3>259 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 1, i32 undef, i32 0>260 ret <3 x i8> %r261}262 263define <3 x i8> @shuf_xor(<3 x i8> %x) {264; CHECK-LABEL: @shuf_xor(265; CHECK-NEXT: [[BO:%.*]] = xor <3 x i8> [[X:%.*]], <i8 1, i8 poison, i8 3>266; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 poison, i32 0>267; CHECK-NEXT: ret <3 x i8> [[R]]268;269 %bo = xor <3 x i8> %x, <i8 1, i8 2, i8 3>270 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0>271 ret <3 x i8> %r272}273 274define <3 x i8> @shuf_lshr_const_op0(<3 x i8> %x) {275; CHECK-LABEL: @shuf_lshr_const_op0(276; CHECK-NEXT: [[BO:%.*]] = lshr <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]277; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 poison>278; CHECK-NEXT: ret <3 x i8> [[R]]279;280 %bo = lshr <3 x i8> <i8 1, i8 2, i8 3>, %x281 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 1, i32 undef>282 ret <3 x i8> %r283}284 285define <3 x i8> @shuf_lshr_const_op1(<3 x i8> %x) {286; CHECK-LABEL: @shuf_lshr_const_op1(287; CHECK-NEXT: [[BO:%.*]] = lshr exact <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>288; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 poison>289; CHECK-NEXT: ret <3 x i8> [[R]]290;291 %bo = lshr exact <3 x i8> %x, <i8 1, i8 2, i8 3>292 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 1, i32 undef>293 ret <3 x i8> %r294}295 296define <3 x i8> @shuf_ashr_const_op0(<3 x i8> %x) {297; CHECK-LABEL: @shuf_ashr_const_op0(298; CHECK-NEXT: [[BO:%.*]] = lshr <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]299; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 poison, i32 1>300; CHECK-NEXT: ret <3 x i8> [[R]]301;302 %bo = ashr <3 x i8> <i8 1, i8 2, i8 3>, %x303 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 undef, i32 1>304 ret <3 x i8> %r305}306 307define <3 x i8> @shuf_ashr_const_op1(<3 x i8> %x) {308; CHECK-LABEL: @shuf_ashr_const_op1(309; CHECK-NEXT: [[BO:%.*]] = ashr exact <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>310; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 poison, i32 1>311; CHECK-NEXT: ret <3 x i8> [[R]]312;313 %bo = ashr exact <3 x i8> %x, <i8 1, i8 2, i8 3>314 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 undef, i32 1>315 ret <3 x i8> %r316}317 318define <3 x i8> @shuf_shl_const_op0(<3 x i8> %x) {319; CHECK-LABEL: @shuf_shl_const_op0(320; CHECK-NEXT: [[BO:%.*]] = shl nsw <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]321; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 poison, i32 0>322; CHECK-NEXT: ret <3 x i8> [[R]]323;324 %bo = shl nsw <3 x i8> <i8 1, i8 2, i8 3>, %x325 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0>326 ret <3 x i8> %r327}328 329define <3 x i8> @shuf_shl_const_op1(<3 x i8> %x) {330; CHECK-LABEL: @shuf_shl_const_op1(331; CHECK-NEXT: [[BO:%.*]] = shl nuw <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>332; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 poison, i32 0>333; CHECK-NEXT: ret <3 x i8> [[R]]334;335 %bo = shl nuw <3 x i8> %x, <i8 1, i8 2, i8 3>336 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0>337 ret <3 x i8> %r338}339 340define <3 x i8> @shuf_sdiv_const_op0(<3 x i8> %x) {341; CHECK-LABEL: @shuf_sdiv_const_op0(342; CHECK-NEXT: [[BO:%.*]] = sdiv exact <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]343; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 0, i32 poison, i32 1>344; CHECK-NEXT: ret <3 x i8> [[R]]345;346 %bo = sdiv exact <3 x i8> <i8 1, i8 2, i8 3>, %x347 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 undef, i32 1>348 ret <3 x i8> %r349}350 351define <3 x i8> @shuf_sdiv_const_op1(<3 x i8> %x) {352; CHECK-LABEL: @shuf_sdiv_const_op1(353; CHECK-NEXT: [[BO:%.*]] = sdiv <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>354; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 poison, i32 0>355; CHECK-NEXT: ret <3 x i8> [[R]]356;357 %bo = sdiv <3 x i8> %x, <i8 1, i8 2, i8 3>358 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 1, i32 undef, i32 0>359 ret <3 x i8> %r360}361 362define <3 x i8> @shuf_srem_const_op0(<3 x i8> %x) {363; CHECK-LABEL: @shuf_srem_const_op0(364; CHECK-NEXT: [[BO:%.*]] = srem <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]365; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 1, i32 poison, i32 2>366; CHECK-NEXT: ret <3 x i8> [[R]]367;368 %bo = srem <3 x i8> <i8 1, i8 2, i8 3>, %x369 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 1, i32 undef, i32 2>370 ret <3 x i8> %r371}372 373define <3 x i8> @shuf_srem_const_op1(<3 x i8> %x) {374; CHECK-LABEL: @shuf_srem_const_op1(375; CHECK-NEXT: [[BO:%.*]] = srem <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>376; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 poison, i32 1>377; CHECK-NEXT: ret <3 x i8> [[R]]378;379 %bo = srem <3 x i8> %x, <i8 1, i8 2, i8 3>380 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 1>381 ret <3 x i8> %r382}383 384define <3 x i8> @shuf_udiv_const_op0(<3 x i8> %x) {385; CHECK-LABEL: @shuf_udiv_const_op0(386; CHECK-NEXT: [[BO:%.*]] = udiv exact <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]387; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 poison, i32 0>388; CHECK-NEXT: ret <3 x i8> [[R]]389;390 %bo = udiv exact <3 x i8> <i8 1, i8 2, i8 3>, %x391 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0>392 ret <3 x i8> %r393}394 395define <3 x i8> @shuf_udiv_const_op1(<3 x i8> %x) {396; CHECK-LABEL: @shuf_udiv_const_op1(397; CHECK-NEXT: [[BO:%.*]] = udiv <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>398; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 poison, i32 0>399; CHECK-NEXT: ret <3 x i8> [[R]]400;401 %bo = udiv <3 x i8> %x, <i8 1, i8 2, i8 3>402 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0>403 ret <3 x i8> %r404}405 406define <3 x i8> @shuf_urem_const_op0(<3 x i8> %x) {407; CHECK-LABEL: @shuf_urem_const_op0(408; CHECK-NEXT: [[BO:%.*]] = urem <3 x i8> <i8 1, i8 2, i8 3>, [[X:%.*]]409; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 2, i32 1, i32 poison>410; CHECK-NEXT: ret <3 x i8> [[R]]411;412 %bo = urem <3 x i8> <i8 1, i8 2, i8 3>, %x413 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 1, i32 undef>414 ret <3 x i8> %r415}416 417define <3 x i8> @shuf_urem_const_op1(<3 x i8> %x) {418; CHECK-LABEL: @shuf_urem_const_op1(419; CHECK-NEXT: [[BO:%.*]] = urem <3 x i8> [[X:%.*]], <i8 1, i8 2, i8 3>420; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i8> [[BO]], <3 x i8> poison, <3 x i32> <i32 poison, i32 1, i32 0>421; CHECK-NEXT: ret <3 x i8> [[R]]422;423 %bo = urem <3 x i8> %x, <i8 1, i8 2, i8 3>424 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 undef, i32 1, i32 0>425 ret <3 x i8> %r426}427 428define <3 x float> @shuf_fadd(<3 x float> %x) {429; CHECK-LABEL: @shuf_fadd(430; CHECK-NEXT: [[BO:%.*]] = fadd <3 x float> [[X:%.*]], <float 1.000000e+00, float 2.000000e+00, float poison>431; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 poison, i32 1, i32 0>432; CHECK-NEXT: ret <3 x float> [[R]]433;434 %bo = fadd <3 x float> %x, <float 1.0, float 2.0, float 3.0>435 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 1, i32 0>436 ret <3 x float> %r437}438 439define <3 x float> @shuf_fsub(<3 x float> %x) {440; CHECK-LABEL: @shuf_fsub(441; CHECK-NEXT: [[BO:%.*]] = fsub fast <3 x float> <float 1.000000e+00, float poison, float 3.000000e+00>, [[X:%.*]]442; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 poison, i32 0, i32 2>443; CHECK-NEXT: ret <3 x float> [[R]]444;445 %bo = fsub fast <3 x float> <float 1.0, float 2.0, float 3.0>, %x446 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 0, i32 2>447 ret <3 x float> %r448}449 450define <3 x float> @shuf_fmul(<3 x float> %x) {451; CHECK-LABEL: @shuf_fmul(452; CHECK-NEXT: [[BO:%.*]] = fmul reassoc <3 x float> [[X:%.*]], <float 1.000000e+00, float 2.000000e+00, float poison>453; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 poison, i32 1, i32 0>454; CHECK-NEXT: ret <3 x float> [[R]]455;456 %bo = fmul reassoc <3 x float> %x, <float 1.0, float 2.0, float 3.0>457 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 1, i32 0>458 ret <3 x float> %r459}460 461define <3 x float> @shuf_fdiv_const_op0(<3 x float> %x) {462; CHECK-LABEL: @shuf_fdiv_const_op0(463; CHECK-NEXT: [[BO:%.*]] = fdiv reassoc ninf <3 x float> <float 1.000000e+00, float poison, float 3.000000e+00>, [[X:%.*]]464; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 poison, i32 0, i32 2>465; CHECK-NEXT: ret <3 x float> [[R]]466;467 %bo = fdiv ninf reassoc <3 x float> <float 1.0, float 2.0, float 3.0>, %x468 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 0, i32 2>469 ret <3 x float> %r470}471 472define <3 x float> @shuf_fdiv_const_op1(<3 x float> %x) {473; CHECK-LABEL: @shuf_fdiv_const_op1(474; CHECK-NEXT: [[BO:%.*]] = fdiv nnan ninf <3 x float> [[X:%.*]], <float 1.000000e+00, float 2.000000e+00, float poison>475; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 poison, i32 1, i32 0>476; CHECK-NEXT: ret <3 x float> [[R]]477;478 %bo = fdiv ninf nnan <3 x float> %x, <float 1.0, float 2.0, float 3.0>479 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 1, i32 0>480 ret <3 x float> %r481}482 483define <3 x float> @shuf_frem_const_op0(<3 x float> %x) {484; CHECK-LABEL: @shuf_frem_const_op0(485; CHECK-NEXT: [[BO:%.*]] = frem nnan <3 x float> <float 1.000000e+00, float poison, float 3.000000e+00>, [[X:%.*]]486; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 poison, i32 2, i32 0>487; CHECK-NEXT: ret <3 x float> [[R]]488;489 %bo = frem nnan <3 x float> <float 1.0, float 2.0, float 3.0>, %x490 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 2, i32 0>491 ret <3 x float> %r492}493 494define <3 x float> @shuf_frem_const_op1(<3 x float> %x) {495; CHECK-LABEL: @shuf_frem_const_op1(496; CHECK-NEXT: [[BO:%.*]] = frem reassoc ninf <3 x float> [[X:%.*]], <float poison, float 2.000000e+00, float 3.000000e+00>497; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x float> [[BO]], <3 x float> poison, <3 x i32> <i32 1, i32 poison, i32 2>498; CHECK-NEXT: ret <3 x float> [[R]]499;500 %bo = frem ninf reassoc <3 x float> %x, <float 1.0, float 2.0, float 3.0>501 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 1, i32 undef, i32 2>502 ret <3 x float> %r503}504 505define ptr @gep_vbase_w_s_idx(<2 x ptr> %base, i64 %index) {506; CHECK-LABEL: @gep_vbase_w_s_idx(507; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x ptr> [[BASE:%.*]], i64 1508; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr [[TMP1]], i64 [[INDEX:%.*]]509; CHECK-NEXT: ret ptr [[EE]]510;511 %gep = getelementptr i32, <2 x ptr> %base, i64 %index512 %ee = extractelement <2 x ptr> %gep, i32 1513 ret ptr %ee514}515 516define ptr @gep_splat_base_w_s_idx(ptr %base) {517; CHECK-LABEL: @gep_splat_base_w_s_idx(518; CHECK-NEXT: [[EE:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 4519; CHECK-NEXT: ret ptr [[EE]]520;521 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0522 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer523 %gep = getelementptr i32, <2 x ptr> %basevec2, i64 1524 %ee = extractelement <2 x ptr> %gep, i32 1525 ret ptr %ee526}527 528 529define ptr @gep_splat_base_w_cv_idx(ptr %base) {530; CHECK-LABEL: @gep_splat_base_w_cv_idx(531; CHECK-NEXT: [[EE:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 4532; CHECK-NEXT: ret ptr [[EE]]533;534 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0535 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer536 %gep = getelementptr i32, <2 x ptr> %basevec2, <2 x i64> <i64 0, i64 1>537 %ee = extractelement <2 x ptr> %gep, i32 1538 ret ptr %ee539}540 541define ptr @gep_splat_base_w_vidx(ptr %base, <2 x i64> %idxvec) {542; CHECK-LABEL: @gep_splat_base_w_vidx(543; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i64> [[IDXVEC:%.*]], i64 1544; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr [[BASE:%.*]], i64 [[TMP1]]545; CHECK-NEXT: ret ptr [[EE]]546;547 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0548 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer549 %gep = getelementptr i32, <2 x ptr> %basevec2, <2 x i64> %idxvec550 %ee = extractelement <2 x ptr> %gep, i32 1551 ret ptr %ee552}553 554 555@GLOBAL = internal global i32 zeroinitializer556 557define ptr @gep_cvbase_w_s_idx(<2 x ptr> %base, i64 %raw_addr) {558; CHECK-LABEL: @gep_cvbase_w_s_idx(559; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr @GLOBAL, i64 [[RAW_ADDR:%.*]]560; CHECK-NEXT: ret ptr [[EE]]561;562 %gep = getelementptr i32, <2 x ptr> <ptr @GLOBAL, ptr @GLOBAL>, i64 %raw_addr563 %ee = extractelement <2 x ptr> %gep, i32 1564 ret ptr %ee565}566 567define ptr @gep_cvbase_w_cv_idx(<2 x ptr> %base, i64 %raw_addr) {568; CHECK-LABEL: @gep_cvbase_w_cv_idx(569; CHECK-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @GLOBAL, i64 4)570;571 %gep = getelementptr i32, <2 x ptr> <ptr @GLOBAL, ptr @GLOBAL>, <2 x i64> <i64 0, i64 1>572 %ee = extractelement <2 x ptr> %gep, i32 1573 ret ptr %ee574}575 576 577define ptr @gep_sbase_w_cv_idx(ptr %base) {578; CHECK-LABEL: @gep_sbase_w_cv_idx(579; CHECK-NEXT: [[EE:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 4580; CHECK-NEXT: ret ptr [[EE]]581;582 %gep = getelementptr i32, ptr %base, <2 x i64> <i64 0, i64 1>583 %ee = extractelement <2 x ptr> %gep, i32 1584 ret ptr %ee585}586 587define ptr @gep_sbase_w_splat_idx(ptr %base, i64 %idx) {588; CHECK-LABEL: @gep_sbase_w_splat_idx(589; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr [[BASE:%.*]], i64 [[IDX:%.*]]590; CHECK-NEXT: ret ptr [[EE]]591;592 %idxvec1 = insertelement <2 x i64> undef, i64 %idx, i32 0593 %idxvec2 = shufflevector <2 x i64> %idxvec1, <2 x i64> undef, <2 x i32> zeroinitializer594 %gep = getelementptr i32, ptr %base, <2 x i64> %idxvec2595 %ee = extractelement <2 x ptr> %gep, i32 1596 ret ptr %ee597}598define ptr @gep_splat_both(ptr %base, i64 %idx) {599; CHECK-LABEL: @gep_splat_both(600; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr [[BASE:%.*]], i64 [[IDX:%.*]]601; CHECK-NEXT: ret ptr [[EE]]602;603 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0604 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer605 %idxvec1 = insertelement <2 x i64> undef, i64 %idx, i32 0606 %idxvec2 = shufflevector <2 x i64> %idxvec1, <2 x i64> undef, <2 x i32> zeroinitializer607 %gep = getelementptr i32, <2 x ptr> %basevec2, <2 x i64> %idxvec2608 %ee = extractelement <2 x ptr> %gep, i32 1609 ret ptr %ee610}611 612define <2 x ptr> @gep_all_lanes_undef(ptr %base, i64 %idx) {;613; CHECK-LABEL: @gep_all_lanes_undef(614; CHECK-NEXT: [[BASEVEC:%.*]] = insertelement <2 x ptr> <ptr poison, ptr undef>, ptr [[BASE:%.*]], i64 0615; CHECK-NEXT: [[IDXVEC:%.*]] = insertelement <2 x i64> <i64 undef, i64 poison>, i64 [[IDX:%.*]], i64 1616; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x ptr> [[BASEVEC]], <2 x i64> [[IDXVEC]]617; CHECK-NEXT: ret <2 x ptr> [[GEP]]618;619 %basevec = insertelement <2 x ptr> undef, ptr %base, i32 0620 %idxvec = insertelement <2 x i64> undef, i64 %idx, i32 1621 %gep = getelementptr i32, <2 x ptr> %basevec, <2 x i64> %idxvec622 ret <2 x ptr> %gep623}624 625define ptr @gep_demanded_lane_undef(ptr %base, i64 %idx) {626; CHECK-LABEL: @gep_demanded_lane_undef(627; CHECK-NEXT: ret ptr undef628;629 %basevec = insertelement <2 x ptr> undef, ptr %base, i32 0630 %idxvec = insertelement <2 x i64> undef, i64 %idx, i32 1631 %gep = getelementptr i32, <2 x ptr> %basevec, <2 x i64> %idxvec632 %ee = extractelement <2 x ptr> %gep, i32 1633 ret ptr %ee634}635 636 637;; LangRef has an odd quirk around FCAs which make it illegal to use undef638;; indices.639define ptr @PR41624(<2 x ptr> %a) {640; CHECK-LABEL: @PR41624(641; CHECK-NEXT: [[R:%.*]] = extractelement <2 x ptr> [[W:%.*]], i64 0642; CHECK-NEXT: [[R1:%.*]] = getelementptr i8, ptr [[R]], i64 40643; CHECK-NEXT: ret ptr [[R1]]644;645 %w = getelementptr { i32, i32 }, <2 x ptr> %a, <2 x i64> <i64 5, i64 5>, <2 x i32> zeroinitializer646 %r = extractelement <2 x ptr> %w, i32 0647 ret ptr %r648}649 650@global = external global [0 x i32], align 4651 652; Make sure we don't get stuck in a loop turning the zeroinitializer into653; <0, undef, undef, undef> and then changing it back.654define ptr @zero_sized_type_extract(<4 x i64> %arg, i64 %arg1) {655; CHECK-LABEL: @zero_sized_type_extract(656; CHECK-NEXT: bb:657; CHECK-NEXT: [[TMP0:%.*]] = extractelement <4 x i64> [[ARG:%.*]], i64 0658; CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i32, ptr @global, i64 [[TMP0]]659; CHECK-NEXT: ret ptr [[T2]]660;661bb:662 %t = getelementptr inbounds [0 x i32], <4 x ptr> <ptr @global, ptr @global, ptr @global, ptr @global>, <4 x i64> zeroinitializer, <4 x i64> %arg663 %t2 = extractelement <4 x ptr> %t, i64 0664 ret ptr %t2665}666 667; The non-zero elements of the result are always 'y', so the splat is unnecessary.668 669define <4 x i8> @select_cond_with_eq_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) {670; CHECK-LABEL: @select_cond_with_eq_true_false_elts(671; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]]672; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[SEL]], <4 x i8> [[Y]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>673; CHECK-NEXT: ret <4 x i8> [[R]]674;675 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7>676 %splat = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> zeroinitializer677 %r = select <4 x i1> %splat, <4 x i8> %tval, <4 x i8> %y678 ret <4 x i8> %r679}680 681; First element of the result is always x[0], so first element of select condition is unnecessary.682 683define <4 x i8> @select_cond_with_eq_true_false_elts2(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) {684; CHECK-LABEL: @select_cond_with_eq_true_false_elts2(685; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 poison, i32 1, i32 0, i32 1>686; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[Y:%.*]], <4 x i8> [[X:%.*]]687; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[SEL]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>688; CHECK-NEXT: ret <4 x i8> [[R]]689;690 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7>691 %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 1>692 %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x693 ret <4 x i8> %r694}695 696; Second element of the result is always x[3], so second element of select condition is unnecessary.697; Fourth element of the result is always undef, so fourth element of select condition is unnecessary.698 699define <4 x float> @select_cond_with_eq_true_false_elts3(<4 x float> %x, <4 x float> %y, <4 x i1> %cmp) {700; CHECK-LABEL: @select_cond_with_eq_true_false_elts3(701; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> <i32 1, i32 3, i32 5, i32 poison>702; CHECK-NEXT: [[FVAL:%.*]] = shufflevector <4 x float> [[Y]], <4 x float> [[X]], <4 x i32> <i32 0, i32 7, i32 6, i32 poison>703; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 poison, i32 1, i32 2, i32 3>704; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x float> [[TVAL]], <4 x float> [[FVAL]]705; CHECK-NEXT: ret <4 x float> [[R]]706;707 %tval = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> <i32 1, i32 3, i32 5, i32 undef>708 %fval = shufflevector <4 x float> %y, <4 x float> %x, <4 x i32> <i32 0, i32 7, i32 6, i32 undef>709 %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> <i32 undef, i32 1, i32 2, i32 3>710 %r = select <4 x i1> %cond, <4 x float> %tval, <4 x float> %fval711 ret <4 x float> %r712}713 714define <4 x i8> @select_cond_with_undef_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) {715; CHECK-LABEL: @select_cond_with_undef_true_false_elts(716; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> poison, <4 x i32> <i32 poison, i32 1, i32 2, i32 3>717; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1>718; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[TVAL]], <4 x i8> [[X:%.*]]719; CHECK-NEXT: ret <4 x i8> [[R]]720;721 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 undef, i32 5, i32 6, i32 7>722 %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 1>723 %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x724 ret <4 x i8> %r725}726 727; The insert can be safely eliminated because the shuffle blocks poison from cmp[0].728 729define <4 x i8> @select_cond_(<4 x i8> %x, <4 x i8> %min, <4 x i1> %cmp, i1 %poison_blocker) {730; CHECK-LABEL: @select_cond_(731; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[MIN:%.*]], <4 x i8> [[X:%.*]]732; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[SEL]], <4 x i32> <i32 0, i32 5, i32 6, i32 7>733; CHECK-NEXT: ret <4 x i8> [[R]]734;735 %ins = insertelement <4 x i1> %cmp, i1 %poison_blocker, i32 0736 %vecins = shufflevector <4 x i8> %x, <4 x i8> %min, <4 x i32> <i32 0, i32 5, i32 6, i32 7>737 %r = select <4 x i1> %ins, <4 x i8> %vecins, <4 x i8> %x738 ret <4 x i8> %r739}740 741define <4 x float> @ins_of_ext(<4 x float> %x, float %y) {742; CHECK-LABEL: @ins_of_ext(743; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i64 1744; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i64 2745; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i64 3746; CHECK-NEXT: ret <4 x float> [[I3]]747;748 %e0 = extractelement <4 x float> %x, i32 0749 %i0 = insertelement <4 x float> undef, float %e0, i32 0750 %i1 = insertelement <4 x float> %i0, float %y, i32 1751 %i2 = insertelement <4 x float> %i1, float %y, i32 2752 %i3 = insertelement <4 x float> %i2, float %y, i32 3753 ret <4 x float> %i3754}755 756define <4 x float> @ins_of_ext_twice(<4 x float> %x, float %y) {757; CHECK-LABEL: @ins_of_ext_twice(758; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i64 2759; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i64 3760; CHECK-NEXT: ret <4 x float> [[I3]]761;762 %e0 = extractelement <4 x float> %x, i32 0763 %i0 = insertelement <4 x float> undef, float %e0, i32 0764 %e1 = extractelement <4 x float> %x, i32 1765 %i1 = insertelement <4 x float> %i0, float %e1, i32 1766 %i2 = insertelement <4 x float> %i1, float %y, i32 2767 %i3 = insertelement <4 x float> %i2, float %y, i32 3768 ret <4 x float> %i3769}770 771; Negative test - element 3 of the result must be undef to be poison safe.772; TODO: Could convert insert/extract to identity shuffle with undef mask elements.773 774define <4 x float> @ins_of_ext_wrong_demand(<4 x float> %x, float %y) {775; CHECK-LABEL: @ins_of_ext_wrong_demand(776; CHECK-NEXT: [[E0:%.*]] = extractelement <4 x float> [[X:%.*]], i64 0777; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> <float poison, float poison, float poison, float undef>, float [[E0]], i64 0778; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i64 1779; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i64 2780; CHECK-NEXT: ret <4 x float> [[I2]]781;782 %e0 = extractelement <4 x float> %x, i32 0783 %i0 = insertelement <4 x float> undef, float %e0, i32 0784 %i1 = insertelement <4 x float> %i0, float %y, i32 1785 %i2 = insertelement <4 x float> %i1, float %y, i32 2786 ret <4 x float> %i2787}788 789; Negative test - can't replace i0 with x.790; TODO: Could convert insert/extract to identity shuffle with undef mask elements.791 792define <4 x float> @ins_of_ext_wrong_type(<5 x float> %x, float %y) {793; CHECK-LABEL: @ins_of_ext_wrong_type(794; CHECK-NEXT: [[E0:%.*]] = extractelement <5 x float> [[X:%.*]], i64 0795; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> poison, float [[E0]], i64 0796; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i64 1797; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i64 2798; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i64 3799; CHECK-NEXT: ret <4 x float> [[I3]]800;801 %e0 = extractelement <5 x float> %x, i32 0802 %i0 = insertelement <4 x float> undef, float %e0, i32 0803 %i1 = insertelement <4 x float> %i0, float %y, i32 1804 %i2 = insertelement <4 x float> %i1, float %y, i32 2805 %i3 = insertelement <4 x float> %i2, float %y, i32 3806 ret <4 x float> %i3807}808 809; This should reduce, but the shuffle mask must remain as-is (no extra undef).810 811define <4 x i4> @ins_of_ext_undef_elts_propagation(<4 x i4> %v, <4 x i4> %v2, i4 %x) {812; CHECK-LABEL: @ins_of_ext_undef_elts_propagation(813; CHECK-NEXT: [[T2:%.*]] = insertelement <4 x i4> [[V:%.*]], i4 [[X:%.*]], i64 2814; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i4> [[T2]], <4 x i4> [[V2:%.*]], <4 x i32> <i32 0, i32 6, i32 2, i32 7>815; CHECK-NEXT: ret <4 x i4> [[R]]816;817 %v0 = extractelement <4 x i4> %v, i32 0818 %t0 = insertelement <4 x i4> undef, i4 %v0, i32 0819 %t2 = insertelement <4 x i4> %t0, i4 %x, i32 2820 %r = shufflevector <4 x i4> %t2, <4 x i4> %v2, <4 x i32> <i32 0, i32 6, i32 2, i32 7>821 ret <4 x i4> %r822}823 824; Similar to above, but more ops/uses to verify things work in more complicated cases.825 826define <8 x i4> @ins_of_ext_undef_elts_propagation2(<8 x i4> %v, <8 x i4> %v2, i4 %x) {827; CHECK-LABEL: @ins_of_ext_undef_elts_propagation2(828; CHECK-NEXT: [[I19:%.*]] = insertelement <8 x i4> [[V:%.*]], i4 [[X:%.*]], i64 2829; CHECK-NEXT: [[I20:%.*]] = shufflevector <8 x i4> [[I19]], <8 x i4> [[V2:%.*]], <8 x i32> <i32 0, i32 1, i32 2, i32 11, i32 10, i32 9, i32 8, i32 poison>830; CHECK-NEXT: [[I21:%.*]] = shufflevector <8 x i4> [[I20]], <8 x i4> [[V]], <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 15>831; CHECK-NEXT: ret <8 x i4> [[I21]]832;833 %i15 = extractelement <8 x i4> %v, i32 0834 %i16 = insertelement <8 x i4> undef, i4 %i15, i32 0835 %i17 = extractelement <8 x i4> %v, i32 1836 %i18 = insertelement <8 x i4> %i16, i4 %i17, i32 1837 %i19 = insertelement <8 x i4> %i18, i4 %x, i32 2838 %i20 = shufflevector <8 x i4> %i19, <8 x i4> %v2, <8 x i32> <i32 0, i32 1, i32 2, i32 11, i32 10, i32 9, i32 8, i32 undef>839 %i21 = shufflevector <8 x i4> %i20, <8 x i4> %v, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 15>840 ret <8 x i4> %i21841}842 843define void @common_binop_demand_via_splat_op0(<2 x i4> %x, <2 x i4> %y) {844; CHECK-LABEL: @common_binop_demand_via_splat_op0(845; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer846; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y:%.*]]847; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XSHUF_Y]], <2 x i4> poison, <2 x i32> zeroinitializer848; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])849; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])850; CHECK-NEXT: ret void851;852 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer853 %b_xshuf_y = mul <2 x i4> %xshuf, %y854 %b_xy = mul <2 x i4> %x, %y855 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer856 call void @use(<2 x i4> %b_xshuf_y)857 call void @use(<2 x i4> %b_xy_splat)858 ret void859}860 861define void @common_binop_demand_via_splat_op1(<2 x i4> %p, <2 x i4> %y) {862; CHECK-LABEL: @common_binop_demand_via_splat_op1(863; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 1>, [[P:%.*]]864; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x i4> [[Y:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer865; CHECK-NEXT: [[B_X_YSHUF:%.*]] = mul <2 x i4> [[X]], [[YSHUF]]866; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_X_YSHUF]], <2 x i4> poison, <2 x i32> zeroinitializer867; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])868; CHECK-NEXT: call void @use(<2 x i4> [[B_X_YSHUF]])869; CHECK-NEXT: ret void870;871 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization872 %yshuf = shufflevector <2 x i4> %y, <2 x i4> poison, <2 x i32> zeroinitializer873 %b_x_yshuf = mul <2 x i4> %x, %yshuf874 %b_xy = mul <2 x i4> %x, %y875 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer876 call void @use(<2 x i4> %b_xy_splat)877 call void @use(<2 x i4> %b_x_yshuf)878 ret void879}880 881define void @common_binop_demand_via_splat_op0_commute(<2 x i4> %p, <2 x i4> %q) {882; CHECK-LABEL: @common_binop_demand_via_splat_op0_commute(883; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 poison>, [[P:%.*]]884; CHECK-NEXT: [[Y:%.*]] = sub <2 x i4> <i4 1, i4 2>, [[Q:%.*]]885; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer886; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = mul <2 x i4> [[Y]], [[XSHUF]]887; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_Y_XSHUF]], <2 x i4> poison, <2 x i32> zeroinitializer888; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])889; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]])890; CHECK-NEXT: ret void891;892 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization893 %y = sub <2 x i4> <i4 1, i4 2>, %q ; thwart complexity-based canonicalization894 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer895 %b_y_xshuf = mul <2 x i4> %y, %xshuf896 %b_xy = mul <2 x i4> %x, %y897 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer898 call void @use(<2 x i4> %b_xy_splat)899 call void @use(<2 x i4> %b_y_xshuf)900 ret void901}902 903define void @common_binop_demand_via_splat_op1_commute(<2 x i4> %p, <2 x i4> %q) {904; CHECK-LABEL: @common_binop_demand_via_splat_op1_commute(905; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 1>, [[P:%.*]]906; CHECK-NEXT: [[Y:%.*]] = sub <2 x i4> <i4 2, i4 poison>, [[Q:%.*]]907; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x i4> [[Y]], <2 x i4> poison, <2 x i32> zeroinitializer908; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = mul <2 x i4> [[YSHUF]], [[X]]909; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_Y_XSHUF]], <2 x i4> poison, <2 x i32> zeroinitializer910; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])911; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]])912; CHECK-NEXT: ret void913;914 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization915 %y = sub <2 x i4> <i4 2, i4 3>, %q ; thwart complexity-based canonicalization916 %yshuf = shufflevector <2 x i4> %y, <2 x i4> poison, <2 x i32> zeroinitializer917 %b_y_xshuf = mul <2 x i4> %yshuf, %x918 %b_xy = mul <2 x i4> %x, %y919 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer920 call void @use(<2 x i4> %b_xy_splat)921 call void @use(<2 x i4> %b_y_xshuf)922 ret void923}924 925; negative test - wrong operands for sub926 927define void @common_binop_demand_via_splat_op0_wrong_commute(<2 x i4> %x, <2 x i4> %y) {928; CHECK-LABEL: @common_binop_demand_via_splat_op0_wrong_commute(929; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer930; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = sub <2 x i4> [[Y:%.*]], [[XSHUF]]931; CHECK-NEXT: [[B_XY:%.*]] = sub <2 x i4> [[X]], [[Y]]932; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XY]], <2 x i4> poison, <2 x i32> zeroinitializer933; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])934; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]])935; CHECK-NEXT: ret void936;937 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer938 %b_y_xshuf = sub <2 x i4> %y, %xshuf939 %b_xy = sub <2 x i4> %x, %y940 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer941 call void @use(<2 x i4> %b_xy_splat)942 call void @use(<2 x i4> %b_y_xshuf)943 ret void944}945 946; negative test - need to reorder insts?947 948define void @common_binop_demand_via_splat_op0_not_dominated1(<2 x i4> %x, <2 x i4> %y) {949; CHECK-LABEL: @common_binop_demand_via_splat_op0_not_dominated1(950; CHECK-NEXT: [[B_XY:%.*]] = mul <2 x i4> [[X:%.*]], [[Y:%.*]]951; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer952; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y]]953; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XY]], <2 x i4> poison, <2 x i32> zeroinitializer954; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])955; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])956; CHECK-NEXT: ret void957;958 %b_xy = mul <2 x i4> %x, %y959 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer960 %b_xshuf_y = mul <2 x i4> %xshuf, %y961 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer962 call void @use(<2 x i4> %b_xshuf_y)963 call void @use(<2 x i4> %b_xy_splat)964 ret void965}966 967; negative test - need to reorder insts?968 969define void @common_binop_demand_via_splat_op0_not_dominated2(<2 x i4> %x, <2 x i4> %y) {970; CHECK-LABEL: @common_binop_demand_via_splat_op0_not_dominated2(971; CHECK-NEXT: [[B_XY:%.*]] = mul <2 x i4> [[X:%.*]], [[Y:%.*]]972; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XY]], <2 x i4> poison, <2 x i32> zeroinitializer973; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer974; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y]]975; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])976; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]])977; CHECK-NEXT: ret void978;979 %b_xy = mul <2 x i4> %x, %y980 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer981 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer982 %b_xshuf_y = mul <2 x i4> %xshuf, %y983 call void @use(<2 x i4> %b_xshuf_y)984 call void @use(<2 x i4> %b_xy_splat)985 ret void986}987 988define i4 @common_binop_demand_via_extelt_op0(<2 x i4> %x, <2 x i4> %y) {989; CHECK-LABEL: @common_binop_demand_via_extelt_op0(990; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer991; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = sub <2 x i4> [[XSHUF]], [[Y:%.*]]992; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XSHUF_Y]], i64 0993; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])994; CHECK-NEXT: ret i4 [[B_XY0]]995;996 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer997 %b_xshuf_y = sub <2 x i4> %xshuf, %y998 %b_xy = sub nsw <2 x i4> %x, %y999 %b_xy0 = extractelement <2 x i4> %b_xy, i32 01000 call void @use(<2 x i4> %b_xshuf_y)1001 ret i4 %b_xy01002}1003 1004define float @common_binop_demand_via_extelt_op1(<2 x float> %p, <2 x float> %y) {1005; CHECK-LABEL: @common_binop_demand_via_extelt_op1(1006; CHECK-NEXT: [[X:%.*]] = fsub <2 x float> <float 0.000000e+00, float 1.000000e+00>, [[P:%.*]]1007; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x float> [[Y:%.*]], <2 x float> poison, <2 x i32> zeroinitializer1008; CHECK-NEXT: [[B_X_YSHUF:%.*]] = fdiv <2 x float> [[X]], [[YSHUF]]1009; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x float> [[B_X_YSHUF]], i64 01010; CHECK-NEXT: call void @use_fp(<2 x float> [[B_X_YSHUF]])1011; CHECK-NEXT: ret float [[B_XY0]]1012;1013 %x = fsub <2 x float> <float 0.0, float 1.0>, %p ; thwart complexity-based canonicalization1014 %yshuf = shufflevector <2 x float> %y, <2 x float> poison, <2 x i32> zeroinitializer1015 %b_x_yshuf = fdiv <2 x float> %x, %yshuf1016 %b_xy = fdiv <2 x float> %x, %y1017 %b_xy0 = extractelement <2 x float> %b_xy, i32 01018 call void @use_fp(<2 x float> %b_x_yshuf)1019 ret float %b_xy01020}1021 1022define float @common_binop_demand_via_extelt_op0_commute(<2 x float> %p, <2 x float> %q) {1023; CHECK-LABEL: @common_binop_demand_via_extelt_op0_commute(1024; CHECK-NEXT: [[X:%.*]] = fsub <2 x float> <float 0.000000e+00, float poison>, [[P:%.*]]1025; CHECK-NEXT: [[Y:%.*]] = fsub <2 x float> <float 3.000000e+00, float 2.000000e+00>, [[Q:%.*]]1026; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x float> [[X]], <2 x float> poison, <2 x i32> zeroinitializer1027; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = fmul nnan <2 x float> [[Y]], [[XSHUF]]1028; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x float> [[B_Y_XSHUF]], i64 01029; CHECK-NEXT: call void @use_fp(<2 x float> [[B_Y_XSHUF]])1030; CHECK-NEXT: ret float [[B_XY0]]1031;1032 %x = fsub <2 x float> <float 0.0, float 1.0>, %p ; thwart complexity-based canonicalization1033 %y = fsub <2 x float> <float 3.0, float 2.0>, %q ; thwart complexity-based canonicalization1034 %xshuf = shufflevector <2 x float> %x, <2 x float> poison, <2 x i32> zeroinitializer1035 %b_y_xshuf = fmul nnan <2 x float> %y, %xshuf1036 %b_xy = fmul ninf <2 x float> %x, %y1037 %b_xy0 = extractelement <2 x float> %b_xy, i32 01038 call void @use_fp(<2 x float> %b_y_xshuf)1039 ret float %b_xy01040}1041 1042define i4 @common_binop_demand_via_extelt_op1_commute(<2 x i4> %p, <2 x i4> %q) {1043; CHECK-LABEL: @common_binop_demand_via_extelt_op1_commute(1044; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 1>, [[P:%.*]]1045; CHECK-NEXT: [[Y:%.*]] = sub <2 x i4> <i4 2, i4 poison>, [[Q:%.*]]1046; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x i4> [[Y]], <2 x i4> poison, <2 x i32> zeroinitializer1047; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = or <2 x i4> [[YSHUF]], [[X]]1048; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_Y_XSHUF]], i64 01049; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]])1050; CHECK-NEXT: ret i4 [[B_XY0]]1051;1052 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization1053 %y = sub <2 x i4> <i4 2, i4 3>, %q ; thwart complexity-based canonicalization1054 %yshuf = shufflevector <2 x i4> %y, <2 x i4> poison, <2 x i32> zeroinitializer1055 %b_y_xshuf = or <2 x i4> %yshuf, %x1056 %b_xy = or <2 x i4> %x, %y1057 %b_xy0 = extractelement <2 x i4> %b_xy, i32 01058 call void @use(<2 x i4> %b_y_xshuf)1059 ret i4 %b_xy01060}1061 1062; negative test - wrong operands for sub1063 1064define i4 @common_binop_demand_via_extelt_op0_wrong_commute(<2 x i4> %x, <2 x i4> %y) {1065; CHECK-LABEL: @common_binop_demand_via_extelt_op0_wrong_commute(1066; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer1067; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = sub <2 x i4> [[Y:%.*]], [[XSHUF]]1068; CHECK-NEXT: [[B_XY:%.*]] = sub <2 x i4> [[X]], [[Y]]1069; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 01070; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]])1071; CHECK-NEXT: ret i4 [[B_XY0]]1072;1073 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer1074 %b_y_xshuf = sub <2 x i4> %y, %xshuf1075 %b_xy = sub <2 x i4> %x, %y1076 %b_xy0 = extractelement <2 x i4> %b_xy, i32 01077 call void @use(<2 x i4> %b_y_xshuf)1078 ret i4 %b_xy01079}1080 1081; negative test - need to reorder insts?1082 1083define i4 @common_binop_demand_via_extelt_op0_not_dominated1(<2 x i4> %x, <2 x i4> %y) {1084; CHECK-LABEL: @common_binop_demand_via_extelt_op0_not_dominated1(1085; CHECK-NEXT: [[B_XY:%.*]] = xor <2 x i4> [[X:%.*]], [[Y:%.*]]1086; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer1087; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = xor <2 x i4> [[XSHUF]], [[Y]]1088; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 01089; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])1090; CHECK-NEXT: ret i4 [[B_XY0]]1091;1092 %b_xy = xor <2 x i4> %x, %y1093 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer1094 %b_xshuf_y = xor <2 x i4> %xshuf, %y1095 %b_xy0 = extractelement <2 x i4> %b_xy, i32 01096 call void @use(<2 x i4> %b_xshuf_y)1097 ret i4 %b_xy01098}1099 1100; negative test - need to reorder insts?1101 1102define i4 @common_binop_demand_via_extelt_op0_not_dominated2(<2 x i4> %x, <2 x i4> %y) {1103; CHECK-LABEL: @common_binop_demand_via_extelt_op0_not_dominated2(1104; CHECK-NEXT: [[B_XY:%.*]] = mul <2 x i4> [[X:%.*]], [[Y:%.*]]1105; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 01106; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer1107; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y]]1108; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])1109; CHECK-NEXT: ret i4 [[B_XY0]]1110;1111 %b_xy = mul <2 x i4> %x, %y1112 %b_xy0 = extractelement <2 x i4> %b_xy, i32 01113 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer1114 %b_xshuf_y = mul <2 x i4> %xshuf, %y1115 call void @use(<2 x i4> %b_xshuf_y)1116 ret i4 %b_xy01117}1118 1119; negative test - splat doesn't match demanded element1120 1121define i4 @common_binop_demand_via_extelt_op0_mismatch_elt0(<2 x i4> %x, <2 x i4> %y) {1122; CHECK-LABEL: @common_binop_demand_via_extelt_op0_mismatch_elt0(1123; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> <i32 1, i32 1>1124; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = sub <2 x i4> [[XSHUF]], [[Y:%.*]]1125; CHECK-NEXT: [[B_XY:%.*]] = sub nsw <2 x i4> [[X]], [[Y]]1126; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 01127; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])1128; CHECK-NEXT: ret i4 [[B_XY0]]1129;1130 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> <i32 1, i32 1>1131 %b_xshuf_y = sub <2 x i4> %xshuf, %y1132 %b_xy = sub nsw <2 x i4> %x, %y1133 %b_xy0 = extractelement <2 x i4> %b_xy, i32 01134 call void @use(<2 x i4> %b_xshuf_y)1135 ret i4 %b_xy01136}1137 1138; negative test - splat doesn't match demanded element1139 1140define i4 @common_binop_demand_via_extelt_op0_mismatch_elt1(<2 x i4> %x, <2 x i4> %y) {1141; CHECK-LABEL: @common_binop_demand_via_extelt_op0_mismatch_elt1(1142; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer1143; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = sub <2 x i4> [[XSHUF]], [[Y:%.*]]1144; CHECK-NEXT: [[B_XY:%.*]] = sub nsw <2 x i4> [[X]], [[Y]]1145; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 11146; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]])1147; CHECK-NEXT: ret i4 [[B_XY0]]1148;1149 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer1150 %b_xshuf_y = sub <2 x i4> %xshuf, %y1151 %b_xy = sub nsw <2 x i4> %x, %y1152 %b_xy0 = extractelement <2 x i4> %b_xy, i32 11153 call void @use(<2 x i4> %b_xshuf_y)1154 ret i4 %b_xy01155}1156 1157define <2 x i8> @common_binop_demand_via_splat_mask_poison(<2 x i8> %x, <2 x i8> %y) {1158; CHECK-LABEL: @common_binop_demand_via_splat_mask_poison(1159; CHECK-NEXT: [[YSPLAT:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> poison, <2 x i32> <i32 0, i32 poison>1160; CHECK-NEXT: [[VV:%.*]] = add <2 x i8> [[X:%.*]], [[YSPLAT]]1161; CHECK-NEXT: [[MSPLAT:%.*]] = shufflevector <2 x i8> [[VV]], <2 x i8> poison, <2 x i32> zeroinitializer1162; CHECK-NEXT: [[RES:%.*]] = add <2 x i8> [[VV]], [[MSPLAT]]1163; CHECK-NEXT: ret <2 x i8> [[RES]]1164;1165 %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 0, i32 poison> ; <y0, poison>1166 %vv = add <2 x i8> %x, %ysplat ; <x0+y0, poison>1167 %m = add <2 x i8> %x, %y ; <x0+y0, x1+y1>1168 %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 0, i32 0> ; LeftDemanded = 1 ; <x0+y0, x0+y0>1169 %res = add <2 x i8> %vv, %msplat ; <x0+y0+x0+y0, poison>1170 ret <2 x i8> %res1171}1172 1173define <2 x i8> @common_binop_demand_via_splat_mask_poison_2(<2 x i8> %x, <2 x i8> %y) {1174; CHECK-LABEL: @common_binop_demand_via_splat_mask_poison_2(1175; CHECK-NEXT: [[YSPLAT:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> poison, <2 x i32> <i32 poison, i32 0>1176; CHECK-NEXT: [[VV:%.*]] = add <2 x i8> [[X:%.*]], [[YSPLAT]]1177; CHECK-NEXT: [[M:%.*]] = add <2 x i8> [[X]], [[Y]]1178; CHECK-NEXT: [[MSPLAT:%.*]] = shufflevector <2 x i8> [[M]], <2 x i8> [[Y]], <2 x i32> <i32 0, i32 2>1179; CHECK-NEXT: [[RES:%.*]] = add <2 x i8> [[VV]], [[MSPLAT]]1180; CHECK-NEXT: ret <2 x i8> [[RES]]1181;1182 %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>1183 %vv = add <2 x i8> %x, %ysplat1184 %m = add <2 x i8> %x, %y1185 %msplat = shufflevector <2 x i8> %m, <2 x i8> %y, <2 x i32> <i32 0, i32 2> ; LeftDemanded = 1, RightDemanded = 11186 %res = add <2 x i8> %vv, %msplat1187 ret <2 x i8> %res1188}1189 1190define <2 x i8> @common_binop_demand_via_splat_mask_poison_3(<2 x i8> %x, <2 x i8> %y) {1191; CHECK-LABEL: @common_binop_demand_via_splat_mask_poison_3(1192; CHECK-NEXT: [[YSPLAT:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> poison, <2 x i32> <i32 poison, i32 0>1193; CHECK-NEXT: [[VV:%.*]] = add <2 x i8> [[X:%.*]], [[YSPLAT]]1194; CHECK-NEXT: [[M:%.*]] = add <2 x i8> [[X]], [[Y]]1195; CHECK-NEXT: [[MSPLAT:%.*]] = shufflevector <2 x i8> [[M]], <2 x i8> poison, <2 x i32> zeroinitializer1196; CHECK-NEXT: [[RES:%.*]] = add <2 x i8> [[VV]], [[MSPLAT]]1197; CHECK-NEXT: ret <2 x i8> [[RES]]1198;1199 %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0>1200 %vv = add <2 x i8> %x, %ysplat1201 %m = add <2 x i8> %x, %y1202 %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 0, i32 0> ; LeftDemanded = 11203 %res = add <2 x i8> %vv, %msplat1204 ret <2 x i8> %res1205}1206