1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instcombine -S | FileCheck %s 3target 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 i32 12; CHECK-NEXT: ret i32 [[T21]] 13; 14 %t5 = fmul float %f, %f 15 %t9 = insertelement <4 x float> undef, float %t5, i32 0 16 %t10 = insertelement <4 x float> %t9, float 0.000000e+00, i32 1 17 %t11 = insertelement <4 x float> %t10, float 0.000000e+00, i32 2 18 %t12 = insertelement <4 x float> %t11, float 0.000000e+00, i32 3 19 %t19 = bitcast <4 x float> %t12 to <4 x i32> 20 %t21 = extractelement <4 x i32> %t19, i32 0 21 ret i32 %t21 22} 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: unreachable 33; 34entry: 35 %0 = call i32 @fgetc(ptr null) nounwind 36 %1 = trunc i32 %0 to i8 37 %t2 = insertelement <100 x i8> zeroinitializer, i8 %1, i32 1 38 %t1 = extractelement <100 x i8> %t2, i32 0 39 %2 = icmp eq i8 %t1, 80 40 br i1 %2, label %bb2, label %bb3 41 42bb2: ; preds = %entry 43 br label %bb3 44 45bb3: ; preds = %bb2, %entry 46 unreachable 47} 48 49; PR4340 50define 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 16 54; CHECK-NEXT: ret void 55; 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 %a 63 ret void 64} 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.i 77} 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 0 82; 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 0 86 %t10 = insertelement <4 x double> %t9, double 0.000000e+00, i32 1 87 %t11 = insertelement <4 x double> %t10, double 0.000000e+00, i32 2 88 %t12 = insertelement <4 x double> %t11, double 0.000000e+00, i32 3 89 %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> %ret 92} 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 0 97; 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 0 101 %t10 = insertelement <4 x float> %t9, float 0.000000e+00, i32 1 102 %t11 = insertelement <4 x float> %t10, float 0.000000e+00, i32 2 103 %t12 = insertelement <4 x float> %t11, float 0.000000e+00, i32 3 104 %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> %ret 107} 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 3 112; 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> %ret 116} 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 0 121; 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 0 125 %a1 = insertelement <4 x float> %a0, float 1.000000e+00, i32 1 126 %a2 = insertelement <4 x float> %a1, float 2.000000e+00, i32 2 127 %a3 = insertelement <4 x float> %a2, float 3.000000e+00, i32 3 128 %b0 = insertelement <4 x float> undef, float %g, i32 0 129 %b1 = insertelement <4 x float> %b0, float 4.000000e+00, i32 1 130 %b2 = insertelement <4 x float> %b1, float 5.000000e+00, i32 2 131 %b3 = insertelement <4 x float> %b2, float 6.000000e+00, i32 3 132 %ret = select <4 x i1> <i1 true, i1 false, i1 false, i1 true>, <4 x float> %a3, <4 x float> %b3 133 ret <4 x float> %ret 134} 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> zeroinitializer 144 ret <2 x i64> %result 145} 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 1 154 %out12 = insertelement <4 x float> %out1, float %a2, i32 2 155 %out123 = insertelement <4 x float> %out12, float %a3, i32 3 156 %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> %shuffle 158} 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 1 167 %out12 = insertelement <4 x float> %out1, float %a2, i32 2 168 %out123 = insertelement <4 x float> %out12, float %a3, i32 3 169 %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> %shuffle 171} 172 173; The add uses 'out012' giving it multiple uses after the shuffle is transformed to also 174; 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 0 179; CHECK-NEXT: [[OUT01:%.*]] = insertelement <4 x i32> [[OUT0]], i32 [[A1:%.*]], i64 1 180; 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 0 185 %out01 = insertelement <4 x i32> %out0, i32 %a1, i32 1 186 %out012 = insertelement <4 x i32> %out01, i32 %a0, i32 2 187 %foo = add <4 x i32> %out012, %b 188 %out0123 = insertelement <4 x i32> %foo, i32 %a1, i32 3 189 %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> %shuffle 191} 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 1 200 %out12 = insertelement <4 x float> %out1, float %a2, i32 %variable_index ; something unexpected 201 %out123 = insertelement <4 x float> %out12, float %a3, i32 3 202 %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> %shuffle 204} 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> %r 217} 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>, %x 226 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 poison, i32 2> 227 ret <3 x i8> %r 228} 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> %r 239} 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> %r 250} 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> %r 261} 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> %r 272} 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>, %x 281 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 1, i32 undef> 282 ret <3 x i8> %r 283} 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> %r 294} 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>, %x 303 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 undef, i32 1> 304 ret <3 x i8> %r 305} 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> %r 316} 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>, %x 325 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0> 326 ret <3 x i8> %r 327} 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> %r 338} 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>, %x 347 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 0, i32 undef, i32 1> 348 ret <3 x i8> %r 349} 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> %r 360} 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>, %x 369 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 1, i32 undef, i32 2> 370 ret <3 x i8> %r 371} 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> %r 382} 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>, %x 391 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 undef, i32 0> 392 ret <3 x i8> %r 393} 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> %r 404} 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>, %x 413 %r = shufflevector <3 x i8> %bo, <3 x i8> undef, <3 x i32> <i32 2, i32 1, i32 undef> 414 ret <3 x i8> %r 415} 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> %r 426} 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> %r 437} 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>, %x 446 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 0, i32 2> 447 ret <3 x float> %r 448} 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> %r 459} 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>, %x 468 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 0, i32 2> 469 ret <3 x float> %r 470} 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> %r 481} 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>, %x 490 %r = shufflevector <3 x float> %bo, <3 x float> undef, <3 x i32> <i32 undef, i32 2, i32 0> 491 ret <3 x float> %r 492} 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> %r 503} 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 1 508; 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 %index 512 %ee = extractelement <2 x ptr> %gep, i32 1 513 ret ptr %ee 514} 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 4 519; CHECK-NEXT: ret ptr [[EE]] 520; 521 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0 522 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer 523 %gep = getelementptr i32, <2 x ptr> %basevec2, i64 1 524 %ee = extractelement <2 x ptr> %gep, i32 1 525 ret ptr %ee 526} 527 528 529define ptr @gep_splat_base_w_cv_idx(ptr %base) { 530; CHECK-LABEL: @gep_splat_base_w_cv_idx( 531; CHECK-NEXT: [[BASEVEC2:%.*]] = insertelement <2 x ptr> poison, ptr [[BASE:%.*]], i64 1 532; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x ptr> [[BASEVEC2]], <2 x i64> <i64 poison, i64 1> 533; CHECK-NEXT: [[EE:%.*]] = extractelement <2 x ptr> [[GEP]], i64 1 534; CHECK-NEXT: ret ptr [[EE]] 535; 536 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0 537 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer 538 %gep = getelementptr i32, <2 x ptr> %basevec2, <2 x i64> <i64 0, i64 1> 539 %ee = extractelement <2 x ptr> %gep, i32 1 540 ret ptr %ee 541} 542 543define ptr @gep_splat_base_w_vidx(ptr %base, <2 x i64> %idxvec) { 544; CHECK-LABEL: @gep_splat_base_w_vidx( 545; CHECK-NEXT: [[BASEVEC2:%.*]] = insertelement <2 x ptr> poison, ptr [[BASE:%.*]], i64 1 546; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x ptr> [[BASEVEC2]], <2 x i64> [[IDXVEC:%.*]] 547; CHECK-NEXT: [[EE:%.*]] = extractelement <2 x ptr> [[GEP]], i64 1 548; CHECK-NEXT: ret ptr [[EE]] 549; 550 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0 551 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer 552 %gep = getelementptr i32, <2 x ptr> %basevec2, <2 x i64> %idxvec 553 %ee = extractelement <2 x ptr> %gep, i32 1 554 ret ptr %ee 555} 556 557 558@GLOBAL = internal global i32 zeroinitializer 559 560define ptr @gep_cvbase_w_s_idx(<2 x ptr> %base, i64 %raw_addr) { 561; CHECK-LABEL: @gep_cvbase_w_s_idx( 562; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr @GLOBAL, i64 [[RAW_ADDR:%.*]] 563; CHECK-NEXT: ret ptr [[EE]] 564; 565 %gep = getelementptr i32, <2 x ptr> <ptr @GLOBAL, ptr @GLOBAL>, i64 %raw_addr 566 %ee = extractelement <2 x ptr> %gep, i32 1 567 ret ptr %ee 568} 569 570define ptr @gep_cvbase_w_cv_idx(<2 x ptr> %base, i64 %raw_addr) { 571; CHECK-LABEL: @gep_cvbase_w_cv_idx( 572; CHECK-NEXT: ret ptr getelementptr inbounds nuw (i8, ptr @GLOBAL, i64 4) 573; 574 %gep = getelementptr i32, <2 x ptr> <ptr @GLOBAL, ptr @GLOBAL>, <2 x i64> <i64 0, i64 1> 575 %ee = extractelement <2 x ptr> %gep, i32 1 576 ret ptr %ee 577} 578 579 580define ptr @gep_sbase_w_cv_idx(ptr %base) { 581; CHECK-LABEL: @gep_sbase_w_cv_idx( 582; CHECK-NEXT: [[EE:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 4 583; CHECK-NEXT: ret ptr [[EE]] 584; 585 %gep = getelementptr i32, ptr %base, <2 x i64> <i64 0, i64 1> 586 %ee = extractelement <2 x ptr> %gep, i32 1 587 ret ptr %ee 588} 589 590define ptr @gep_sbase_w_splat_idx(ptr %base, i64 %idx) { 591; CHECK-LABEL: @gep_sbase_w_splat_idx( 592; CHECK-NEXT: [[EE:%.*]] = getelementptr i32, ptr [[BASE:%.*]], i64 [[IDX:%.*]] 593; CHECK-NEXT: ret ptr [[EE]] 594; 595 %idxvec1 = insertelement <2 x i64> undef, i64 %idx, i32 0 596 %idxvec2 = shufflevector <2 x i64> %idxvec1, <2 x i64> undef, <2 x i32> zeroinitializer 597 %gep = getelementptr i32, ptr %base, <2 x i64> %idxvec2 598 %ee = extractelement <2 x ptr> %gep, i32 1 599 ret ptr %ee 600} 601define ptr @gep_splat_both(ptr %base, i64 %idx) { 602; CHECK-LABEL: @gep_splat_both( 603; CHECK-NEXT: [[BASEVEC2:%.*]] = insertelement <2 x ptr> poison, ptr [[BASE:%.*]], i64 1 604; CHECK-NEXT: [[IDXVEC2:%.*]] = insertelement <2 x i64> poison, i64 [[IDX:%.*]], i64 1 605; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x ptr> [[BASEVEC2]], <2 x i64> [[IDXVEC2]] 606; CHECK-NEXT: [[EE:%.*]] = extractelement <2 x ptr> [[GEP]], i64 1 607; CHECK-NEXT: ret ptr [[EE]] 608; 609 %basevec1 = insertelement <2 x ptr> undef, ptr %base, i32 0 610 %basevec2 = shufflevector <2 x ptr> %basevec1, <2 x ptr> undef, <2 x i32> zeroinitializer 611 %idxvec1 = insertelement <2 x i64> undef, i64 %idx, i32 0 612 %idxvec2 = shufflevector <2 x i64> %idxvec1, <2 x i64> undef, <2 x i32> zeroinitializer 613 %gep = getelementptr i32, <2 x ptr> %basevec2, <2 x i64> %idxvec2 614 %ee = extractelement <2 x ptr> %gep, i32 1 615 ret ptr %ee 616} 617 618define <2 x ptr> @gep_all_lanes_undef(ptr %base, i64 %idx) {; 619; CHECK-LABEL: @gep_all_lanes_undef( 620; CHECK-NEXT: [[BASEVEC:%.*]] = insertelement <2 x ptr> <ptr poison, ptr undef>, ptr [[BASE:%.*]], i64 0 621; CHECK-NEXT: [[IDXVEC:%.*]] = insertelement <2 x i64> <i64 undef, i64 poison>, i64 [[IDX:%.*]], i64 1 622; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, <2 x ptr> [[BASEVEC]], <2 x i64> [[IDXVEC]] 623; CHECK-NEXT: ret <2 x ptr> [[GEP]] 624; 625 %basevec = insertelement <2 x ptr> undef, ptr %base, i32 0 626 %idxvec = insertelement <2 x i64> undef, i64 %idx, i32 1 627 %gep = getelementptr i32, <2 x ptr> %basevec, <2 x i64> %idxvec 628 ret <2 x ptr> %gep 629} 630 631define ptr @gep_demanded_lane_undef(ptr %base, i64 %idx) { 632; CHECK-LABEL: @gep_demanded_lane_undef( 633; CHECK-NEXT: ret ptr undef 634; 635 %basevec = insertelement <2 x ptr> undef, ptr %base, i32 0 636 %idxvec = insertelement <2 x i64> undef, i64 %idx, i32 1 637 %gep = getelementptr i32, <2 x ptr> %basevec, <2 x i64> %idxvec 638 %ee = extractelement <2 x ptr> %gep, i32 1 639 ret ptr %ee 640} 641 642 643;; LangRef has an odd quirk around FCAs which make it illegal to use undef 644;; indices. 645define ptr @PR41624(<2 x ptr> %a) { 646; CHECK-LABEL: @PR41624( 647; CHECK-NEXT: [[W:%.*]] = getelementptr { i32, i32 }, <2 x ptr> [[A:%.*]], <2 x i64> splat (i64 5), <2 x i32> zeroinitializer 648; CHECK-NEXT: [[R:%.*]] = extractelement <2 x ptr> [[W]], i64 0 649; CHECK-NEXT: ret ptr [[R]] 650; 651 %w = getelementptr { i32, i32 }, <2 x ptr> %a, <2 x i64> <i64 5, i64 5>, <2 x i32> zeroinitializer 652 %r = extractelement <2 x ptr> %w, i32 0 653 ret ptr %r 654} 655 656@global = external global [0 x i32], align 4 657 658; Make sure we don't get stuck in a loop turning the zeroinitializer into 659; <0, undef, undef, undef> and then changing it back. 660define ptr @zero_sized_type_extract(<4 x i64> %arg, i64 %arg1) { 661; CHECK-LABEL: @zero_sized_type_extract( 662; CHECK-NEXT: bb: 663; CHECK-NEXT: [[T:%.*]] = getelementptr inbounds [0 x i32], <4 x ptr> <ptr @global, ptr poison, ptr poison, ptr poison>, <4 x i64> <i64 0, i64 poison, i64 poison, i64 poison>, <4 x i64> [[ARG:%.*]] 664; CHECK-NEXT: [[T2:%.*]] = extractelement <4 x ptr> [[T]], i64 0 665; CHECK-NEXT: ret ptr [[T2]] 666; 667bb: 668 %t = getelementptr inbounds [0 x i32], <4 x ptr> <ptr @global, ptr @global, ptr @global, ptr @global>, <4 x i64> zeroinitializer, <4 x i64> %arg 669 %t2 = extractelement <4 x ptr> %t, i64 0 670 ret ptr %t2 671} 672 673; The non-zero elements of the result are always 'y', so the splat is unnecessary. 674 675define <4 x i8> @select_cond_with_eq_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { 676; CHECK-LABEL: @select_cond_with_eq_true_false_elts( 677; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]] 678; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[SEL]], <4 x i8> [[Y]], <4 x i32> <i32 0, i32 5, i32 6, i32 7> 679; CHECK-NEXT: ret <4 x i8> [[R]] 680; 681 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7> 682 %splat = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> zeroinitializer 683 %r = select <4 x i1> %splat, <4 x i8> %tval, <4 x i8> %y 684 ret <4 x i8> %r 685} 686 687; First element of the result is always x[0], so first element of select condition is unnecessary. 688 689define <4 x i8> @select_cond_with_eq_true_false_elts2(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { 690; CHECK-LABEL: @select_cond_with_eq_true_false_elts2( 691; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 poison, i32 1, i32 0, i32 1> 692; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[Y:%.*]], <4 x i8> [[X:%.*]] 693; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[SEL]], <4 x i32> <i32 0, i32 5, i32 6, i32 7> 694; CHECK-NEXT: ret <4 x i8> [[R]] 695; 696 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 0, i32 5, i32 6, i32 7> 697 %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 1> 698 %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x 699 ret <4 x i8> %r 700} 701 702; Second element of the result is always x[3], so second element of select condition is unnecessary. 703; Fourth element of the result is always undef, so fourth element of select condition is unnecessary. 704 705define <4 x float> @select_cond_with_eq_true_false_elts3(<4 x float> %x, <4 x float> %y, <4 x i1> %cmp) { 706; CHECK-LABEL: @select_cond_with_eq_true_false_elts3( 707; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> <i32 1, i32 3, i32 5, i32 poison> 708; CHECK-NEXT: [[FVAL:%.*]] = shufflevector <4 x float> [[Y]], <4 x float> [[X]], <4 x i32> <i32 0, i32 7, i32 6, i32 poison> 709; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 poison, i32 1, i32 2, i32 3> 710; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x float> [[TVAL]], <4 x float> [[FVAL]] 711; CHECK-NEXT: ret <4 x float> [[R]] 712; 713 %tval = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> <i32 1, i32 3, i32 5, i32 undef> 714 %fval = shufflevector <4 x float> %y, <4 x float> %x, <4 x i32> <i32 0, i32 7, i32 6, i32 undef> 715 %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> <i32 undef, i32 1, i32 2, i32 3> 716 %r = select <4 x i1> %cond, <4 x float> %tval, <4 x float> %fval 717 ret <4 x float> %r 718} 719 720define <4 x i8> @select_cond_with_undef_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { 721; CHECK-LABEL: @select_cond_with_undef_true_false_elts( 722; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> poison, <4 x i32> <i32 poison, i32 1, i32 2, i32 3> 723; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> poison, <4 x i32> <i32 0, i32 1, i32 0, i32 1> 724; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[TVAL]], <4 x i8> [[X:%.*]] 725; CHECK-NEXT: ret <4 x i8> [[R]] 726; 727 %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> <i32 undef, i32 5, i32 6, i32 7> 728 %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> <i32 0, i32 1, i32 0, i32 1> 729 %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x 730 ret <4 x i8> %r 731} 732 733; The insert can be safely eliminated because the shuffle blocks poison from cmp[0]. 734 735define <4 x i8> @select_cond_(<4 x i8> %x, <4 x i8> %min, <4 x i1> %cmp, i1 %poison_blocker) { 736; CHECK-LABEL: @select_cond_( 737; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[MIN:%.*]], <4 x i8> [[X:%.*]] 738; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i8> [[X]], <4 x i8> [[SEL]], <4 x i32> <i32 0, i32 5, i32 6, i32 7> 739; CHECK-NEXT: ret <4 x i8> [[R]] 740; 741 %ins = insertelement <4 x i1> %cmp, i1 %poison_blocker, i32 0 742 %vecins = shufflevector <4 x i8> %x, <4 x i8> %min, <4 x i32> <i32 0, i32 5, i32 6, i32 7> 743 %r = select <4 x i1> %ins, <4 x i8> %vecins, <4 x i8> %x 744 ret <4 x i8> %r 745} 746 747define <4 x float> @ins_of_ext(<4 x float> %x, float %y) { 748; CHECK-LABEL: @ins_of_ext( 749; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i64 1 750; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i64 2 751; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i64 3 752; CHECK-NEXT: ret <4 x float> [[I3]] 753; 754 %e0 = extractelement <4 x float> %x, i32 0 755 %i0 = insertelement <4 x float> undef, float %e0, i32 0 756 %i1 = insertelement <4 x float> %i0, float %y, i32 1 757 %i2 = insertelement <4 x float> %i1, float %y, i32 2 758 %i3 = insertelement <4 x float> %i2, float %y, i32 3 759 ret <4 x float> %i3 760} 761 762define <4 x float> @ins_of_ext_twice(<4 x float> %x, float %y) { 763; CHECK-LABEL: @ins_of_ext_twice( 764; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[X:%.*]], float [[Y:%.*]], i64 2 765; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i64 3 766; CHECK-NEXT: ret <4 x float> [[I3]] 767; 768 %e0 = extractelement <4 x float> %x, i32 0 769 %i0 = insertelement <4 x float> undef, float %e0, i32 0 770 %e1 = extractelement <4 x float> %x, i32 1 771 %i1 = insertelement <4 x float> %i0, float %e1, i32 1 772 %i2 = insertelement <4 x float> %i1, float %y, i32 2 773 %i3 = insertelement <4 x float> %i2, float %y, i32 3 774 ret <4 x float> %i3 775} 776 777; Negative test - element 3 of the result must be undef to be poison safe. 778; TODO: Could convert insert/extract to identity shuffle with undef mask elements. 779 780define <4 x float> @ins_of_ext_wrong_demand(<4 x float> %x, float %y) { 781; CHECK-LABEL: @ins_of_ext_wrong_demand( 782; CHECK-NEXT: [[E0:%.*]] = extractelement <4 x float> [[X:%.*]], i64 0 783; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> <float poison, float poison, float poison, float undef>, float [[E0]], i64 0 784; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i64 1 785; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i64 2 786; CHECK-NEXT: ret <4 x float> [[I2]] 787; 788 %e0 = extractelement <4 x float> %x, i32 0 789 %i0 = insertelement <4 x float> undef, float %e0, i32 0 790 %i1 = insertelement <4 x float> %i0, float %y, i32 1 791 %i2 = insertelement <4 x float> %i1, float %y, i32 2 792 ret <4 x float> %i2 793} 794 795; Negative test - can't replace i0 with x. 796; TODO: Could convert insert/extract to identity shuffle with undef mask elements. 797 798define <4 x float> @ins_of_ext_wrong_type(<5 x float> %x, float %y) { 799; CHECK-LABEL: @ins_of_ext_wrong_type( 800; CHECK-NEXT: [[E0:%.*]] = extractelement <5 x float> [[X:%.*]], i64 0 801; CHECK-NEXT: [[I0:%.*]] = insertelement <4 x float> poison, float [[E0]], i64 0 802; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x float> [[I0]], float [[Y:%.*]], i64 1 803; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x float> [[I1]], float [[Y]], i64 2 804; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x float> [[I2]], float [[Y]], i64 3 805; CHECK-NEXT: ret <4 x float> [[I3]] 806; 807 %e0 = extractelement <5 x float> %x, i32 0 808 %i0 = insertelement <4 x float> undef, float %e0, i32 0 809 %i1 = insertelement <4 x float> %i0, float %y, i32 1 810 %i2 = insertelement <4 x float> %i1, float %y, i32 2 811 %i3 = insertelement <4 x float> %i2, float %y, i32 3 812 ret <4 x float> %i3 813} 814 815; This should reduce, but the shuffle mask must remain as-is (no extra undef). 816 817define <4 x i4> @ins_of_ext_undef_elts_propagation(<4 x i4> %v, <4 x i4> %v2, i4 %x) { 818; CHECK-LABEL: @ins_of_ext_undef_elts_propagation( 819; CHECK-NEXT: [[T2:%.*]] = insertelement <4 x i4> [[V:%.*]], i4 [[X:%.*]], i64 2 820; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x i4> [[T2]], <4 x i4> [[V2:%.*]], <4 x i32> <i32 0, i32 6, i32 2, i32 7> 821; CHECK-NEXT: ret <4 x i4> [[R]] 822; 823 %v0 = extractelement <4 x i4> %v, i32 0 824 %t0 = insertelement <4 x i4> undef, i4 %v0, i32 0 825 %t2 = insertelement <4 x i4> %t0, i4 %x, i32 2 826 %r = shufflevector <4 x i4> %t2, <4 x i4> %v2, <4 x i32> <i32 0, i32 6, i32 2, i32 7> 827 ret <4 x i4> %r 828} 829 830; Similar to above, but more ops/uses to verify things work in more complicated cases. 831 832define <8 x i4> @ins_of_ext_undef_elts_propagation2(<8 x i4> %v, <8 x i4> %v2, i4 %x) { 833; CHECK-LABEL: @ins_of_ext_undef_elts_propagation2( 834; CHECK-NEXT: [[I19:%.*]] = insertelement <8 x i4> [[V:%.*]], i4 [[X:%.*]], i64 2 835; 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> 836; 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> 837; CHECK-NEXT: ret <8 x i4> [[I21]] 838; 839 %i15 = extractelement <8 x i4> %v, i32 0 840 %i16 = insertelement <8 x i4> undef, i4 %i15, i32 0 841 %i17 = extractelement <8 x i4> %v, i32 1 842 %i18 = insertelement <8 x i4> %i16, i4 %i17, i32 1 843 %i19 = insertelement <8 x i4> %i18, i4 %x, i32 2 844 %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> 845 %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> 846 ret <8 x i4> %i21 847} 848 849define void @common_binop_demand_via_splat_op0(<2 x i4> %x, <2 x i4> %y) { 850; CHECK-LABEL: @common_binop_demand_via_splat_op0( 851; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer 852; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y:%.*]] 853; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XSHUF_Y]], <2 x i4> poison, <2 x i32> zeroinitializer 854; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 855; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 856; CHECK-NEXT: ret void 857; 858 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 859 %b_xshuf_y = mul <2 x i4> %xshuf, %y 860 %b_xy = mul <2 x i4> %x, %y 861 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 862 call void @use(<2 x i4> %b_xshuf_y) 863 call void @use(<2 x i4> %b_xy_splat) 864 ret void 865} 866 867define void @common_binop_demand_via_splat_op1(<2 x i4> %p, <2 x i4> %y) { 868; CHECK-LABEL: @common_binop_demand_via_splat_op1( 869; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 1>, [[P:%.*]] 870; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x i4> [[Y:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer 871; CHECK-NEXT: [[B_X_YSHUF:%.*]] = mul <2 x i4> [[X]], [[YSHUF]] 872; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_X_YSHUF]], <2 x i4> poison, <2 x i32> zeroinitializer 873; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 874; CHECK-NEXT: call void @use(<2 x i4> [[B_X_YSHUF]]) 875; CHECK-NEXT: ret void 876; 877 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization 878 %yshuf = shufflevector <2 x i4> %y, <2 x i4> poison, <2 x i32> zeroinitializer 879 %b_x_yshuf = mul <2 x i4> %x, %yshuf 880 %b_xy = mul <2 x i4> %x, %y 881 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 882 call void @use(<2 x i4> %b_xy_splat) 883 call void @use(<2 x i4> %b_x_yshuf) 884 ret void 885} 886 887define void @common_binop_demand_via_splat_op0_commute(<2 x i4> %p, <2 x i4> %q) { 888; CHECK-LABEL: @common_binop_demand_via_splat_op0_commute( 889; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 poison>, [[P:%.*]] 890; CHECK-NEXT: [[Y:%.*]] = sub <2 x i4> <i4 1, i4 2>, [[Q:%.*]] 891; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer 892; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = mul <2 x i4> [[Y]], [[XSHUF]] 893; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_Y_XSHUF]], <2 x i4> poison, <2 x i32> zeroinitializer 894; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 895; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]]) 896; CHECK-NEXT: ret void 897; 898 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization 899 %y = sub <2 x i4> <i4 1, i4 2>, %q ; thwart complexity-based canonicalization 900 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 901 %b_y_xshuf = mul <2 x i4> %y, %xshuf 902 %b_xy = mul <2 x i4> %x, %y 903 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 904 call void @use(<2 x i4> %b_xy_splat) 905 call void @use(<2 x i4> %b_y_xshuf) 906 ret void 907} 908 909define void @common_binop_demand_via_splat_op1_commute(<2 x i4> %p, <2 x i4> %q) { 910; CHECK-LABEL: @common_binop_demand_via_splat_op1_commute( 911; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 1>, [[P:%.*]] 912; CHECK-NEXT: [[Y:%.*]] = sub <2 x i4> <i4 2, i4 poison>, [[Q:%.*]] 913; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x i4> [[Y]], <2 x i4> poison, <2 x i32> zeroinitializer 914; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = mul <2 x i4> [[YSHUF]], [[X]] 915; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_Y_XSHUF]], <2 x i4> poison, <2 x i32> zeroinitializer 916; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 917; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]]) 918; CHECK-NEXT: ret void 919; 920 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization 921 %y = sub <2 x i4> <i4 2, i4 3>, %q ; thwart complexity-based canonicalization 922 %yshuf = shufflevector <2 x i4> %y, <2 x i4> poison, <2 x i32> zeroinitializer 923 %b_y_xshuf = mul <2 x i4> %yshuf, %x 924 %b_xy = mul <2 x i4> %x, %y 925 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 926 call void @use(<2 x i4> %b_xy_splat) 927 call void @use(<2 x i4> %b_y_xshuf) 928 ret void 929} 930 931; negative test - wrong operands for sub 932 933define void @common_binop_demand_via_splat_op0_wrong_commute(<2 x i4> %x, <2 x i4> %y) { 934; CHECK-LABEL: @common_binop_demand_via_splat_op0_wrong_commute( 935; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer 936; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = sub <2 x i4> [[Y:%.*]], [[XSHUF]] 937; CHECK-NEXT: [[B_XY:%.*]] = sub <2 x i4> [[X]], [[Y]] 938; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XY]], <2 x i4> poison, <2 x i32> zeroinitializer 939; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 940; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]]) 941; CHECK-NEXT: ret void 942; 943 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 944 %b_y_xshuf = sub <2 x i4> %y, %xshuf 945 %b_xy = sub <2 x i4> %x, %y 946 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 947 call void @use(<2 x i4> %b_xy_splat) 948 call void @use(<2 x i4> %b_y_xshuf) 949 ret void 950} 951 952; negative test - need to reorder insts? 953 954define void @common_binop_demand_via_splat_op0_not_dominated1(<2 x i4> %x, <2 x i4> %y) { 955; CHECK-LABEL: @common_binop_demand_via_splat_op0_not_dominated1( 956; CHECK-NEXT: [[B_XY:%.*]] = mul <2 x i4> [[X:%.*]], [[Y:%.*]] 957; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer 958; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y]] 959; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XY]], <2 x i4> poison, <2 x i32> zeroinitializer 960; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 961; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 962; CHECK-NEXT: ret void 963; 964 %b_xy = mul <2 x i4> %x, %y 965 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 966 %b_xshuf_y = mul <2 x i4> %xshuf, %y 967 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 968 call void @use(<2 x i4> %b_xshuf_y) 969 call void @use(<2 x i4> %b_xy_splat) 970 ret void 971} 972 973; negative test - need to reorder insts? 974 975define void @common_binop_demand_via_splat_op0_not_dominated2(<2 x i4> %x, <2 x i4> %y) { 976; CHECK-LABEL: @common_binop_demand_via_splat_op0_not_dominated2( 977; CHECK-NEXT: [[B_XY:%.*]] = mul <2 x i4> [[X:%.*]], [[Y:%.*]] 978; CHECK-NEXT: [[B_XY_SPLAT:%.*]] = shufflevector <2 x i4> [[B_XY]], <2 x i4> poison, <2 x i32> zeroinitializer 979; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer 980; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y]] 981; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 982; CHECK-NEXT: call void @use(<2 x i4> [[B_XY_SPLAT]]) 983; CHECK-NEXT: ret void 984; 985 %b_xy = mul <2 x i4> %x, %y 986 %b_xy_splat = shufflevector <2 x i4> %b_xy, <2 x i4> poison, <2 x i32> zeroinitializer 987 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 988 %b_xshuf_y = mul <2 x i4> %xshuf, %y 989 call void @use(<2 x i4> %b_xshuf_y) 990 call void @use(<2 x i4> %b_xy_splat) 991 ret void 992} 993 994define i4 @common_binop_demand_via_extelt_op0(<2 x i4> %x, <2 x i4> %y) { 995; CHECK-LABEL: @common_binop_demand_via_extelt_op0( 996; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer 997; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = sub <2 x i4> [[XSHUF]], [[Y:%.*]] 998; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XSHUF_Y]], i64 0 999; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 1000; CHECK-NEXT: ret i4 [[B_XY0]] 1001; 1002 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 1003 %b_xshuf_y = sub <2 x i4> %xshuf, %y 1004 %b_xy = sub nsw <2 x i4> %x, %y 1005 %b_xy0 = extractelement <2 x i4> %b_xy, i32 0 1006 call void @use(<2 x i4> %b_xshuf_y) 1007 ret i4 %b_xy0 1008} 1009 1010define float @common_binop_demand_via_extelt_op1(<2 x float> %p, <2 x float> %y) { 1011; CHECK-LABEL: @common_binop_demand_via_extelt_op1( 1012; CHECK-NEXT: [[X:%.*]] = fsub <2 x float> <float 0.000000e+00, float 1.000000e+00>, [[P:%.*]] 1013; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x float> [[Y:%.*]], <2 x float> poison, <2 x i32> zeroinitializer 1014; CHECK-NEXT: [[B_X_YSHUF:%.*]] = fdiv <2 x float> [[X]], [[YSHUF]] 1015; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x float> [[B_X_YSHUF]], i64 0 1016; CHECK-NEXT: call void @use_fp(<2 x float> [[B_X_YSHUF]]) 1017; CHECK-NEXT: ret float [[B_XY0]] 1018; 1019 %x = fsub <2 x float> <float 0.0, float 1.0>, %p ; thwart complexity-based canonicalization 1020 %yshuf = shufflevector <2 x float> %y, <2 x float> poison, <2 x i32> zeroinitializer 1021 %b_x_yshuf = fdiv <2 x float> %x, %yshuf 1022 %b_xy = fdiv <2 x float> %x, %y 1023 %b_xy0 = extractelement <2 x float> %b_xy, i32 0 1024 call void @use_fp(<2 x float> %b_x_yshuf) 1025 ret float %b_xy0 1026} 1027 1028define float @common_binop_demand_via_extelt_op0_commute(<2 x float> %p, <2 x float> %q) { 1029; CHECK-LABEL: @common_binop_demand_via_extelt_op0_commute( 1030; CHECK-NEXT: [[X:%.*]] = fsub <2 x float> <float 0.000000e+00, float poison>, [[P:%.*]] 1031; CHECK-NEXT: [[Y:%.*]] = fsub <2 x float> <float 3.000000e+00, float 2.000000e+00>, [[Q:%.*]] 1032; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x float> [[X]], <2 x float> poison, <2 x i32> zeroinitializer 1033; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = fmul nnan <2 x float> [[Y]], [[XSHUF]] 1034; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x float> [[B_Y_XSHUF]], i64 0 1035; CHECK-NEXT: call void @use_fp(<2 x float> [[B_Y_XSHUF]]) 1036; CHECK-NEXT: ret float [[B_XY0]] 1037; 1038 %x = fsub <2 x float> <float 0.0, float 1.0>, %p ; thwart complexity-based canonicalization 1039 %y = fsub <2 x float> <float 3.0, float 2.0>, %q ; thwart complexity-based canonicalization 1040 %xshuf = shufflevector <2 x float> %x, <2 x float> poison, <2 x i32> zeroinitializer 1041 %b_y_xshuf = fmul nnan <2 x float> %y, %xshuf 1042 %b_xy = fmul ninf <2 x float> %x, %y 1043 %b_xy0 = extractelement <2 x float> %b_xy, i32 0 1044 call void @use_fp(<2 x float> %b_y_xshuf) 1045 ret float %b_xy0 1046} 1047 1048define i4 @common_binop_demand_via_extelt_op1_commute(<2 x i4> %p, <2 x i4> %q) { 1049; CHECK-LABEL: @common_binop_demand_via_extelt_op1_commute( 1050; CHECK-NEXT: [[X:%.*]] = sub <2 x i4> <i4 0, i4 1>, [[P:%.*]] 1051; CHECK-NEXT: [[Y:%.*]] = sub <2 x i4> <i4 2, i4 poison>, [[Q:%.*]] 1052; CHECK-NEXT: [[YSHUF:%.*]] = shufflevector <2 x i4> [[Y]], <2 x i4> poison, <2 x i32> zeroinitializer 1053; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = or <2 x i4> [[YSHUF]], [[X]] 1054; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_Y_XSHUF]], i64 0 1055; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]]) 1056; CHECK-NEXT: ret i4 [[B_XY0]] 1057; 1058 %x = sub <2 x i4> <i4 0, i4 1>, %p ; thwart complexity-based canonicalization 1059 %y = sub <2 x i4> <i4 2, i4 3>, %q ; thwart complexity-based canonicalization 1060 %yshuf = shufflevector <2 x i4> %y, <2 x i4> poison, <2 x i32> zeroinitializer 1061 %b_y_xshuf = or <2 x i4> %yshuf, %x 1062 %b_xy = or <2 x i4> %x, %y 1063 %b_xy0 = extractelement <2 x i4> %b_xy, i32 0 1064 call void @use(<2 x i4> %b_y_xshuf) 1065 ret i4 %b_xy0 1066} 1067 1068; negative test - wrong operands for sub 1069 1070define i4 @common_binop_demand_via_extelt_op0_wrong_commute(<2 x i4> %x, <2 x i4> %y) { 1071; CHECK-LABEL: @common_binop_demand_via_extelt_op0_wrong_commute( 1072; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer 1073; CHECK-NEXT: [[B_Y_XSHUF:%.*]] = sub <2 x i4> [[Y:%.*]], [[XSHUF]] 1074; CHECK-NEXT: [[B_XY:%.*]] = sub <2 x i4> [[X]], [[Y]] 1075; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 0 1076; CHECK-NEXT: call void @use(<2 x i4> [[B_Y_XSHUF]]) 1077; CHECK-NEXT: ret i4 [[B_XY0]] 1078; 1079 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 1080 %b_y_xshuf = sub <2 x i4> %y, %xshuf 1081 %b_xy = sub <2 x i4> %x, %y 1082 %b_xy0 = extractelement <2 x i4> %b_xy, i32 0 1083 call void @use(<2 x i4> %b_y_xshuf) 1084 ret i4 %b_xy0 1085} 1086 1087; negative test - need to reorder insts? 1088 1089define i4 @common_binop_demand_via_extelt_op0_not_dominated1(<2 x i4> %x, <2 x i4> %y) { 1090; CHECK-LABEL: @common_binop_demand_via_extelt_op0_not_dominated1( 1091; CHECK-NEXT: [[B_XY:%.*]] = xor <2 x i4> [[X:%.*]], [[Y:%.*]] 1092; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer 1093; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = xor <2 x i4> [[XSHUF]], [[Y]] 1094; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 0 1095; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 1096; CHECK-NEXT: ret i4 [[B_XY0]] 1097; 1098 %b_xy = xor <2 x i4> %x, %y 1099 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 1100 %b_xshuf_y = xor <2 x i4> %xshuf, %y 1101 %b_xy0 = extractelement <2 x i4> %b_xy, i32 0 1102 call void @use(<2 x i4> %b_xshuf_y) 1103 ret i4 %b_xy0 1104} 1105 1106; negative test - need to reorder insts? 1107 1108define i4 @common_binop_demand_via_extelt_op0_not_dominated2(<2 x i4> %x, <2 x i4> %y) { 1109; CHECK-LABEL: @common_binop_demand_via_extelt_op0_not_dominated2( 1110; CHECK-NEXT: [[B_XY:%.*]] = mul <2 x i4> [[X:%.*]], [[Y:%.*]] 1111; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 0 1112; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X]], <2 x i4> poison, <2 x i32> zeroinitializer 1113; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = mul <2 x i4> [[XSHUF]], [[Y]] 1114; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 1115; CHECK-NEXT: ret i4 [[B_XY0]] 1116; 1117 %b_xy = mul <2 x i4> %x, %y 1118 %b_xy0 = extractelement <2 x i4> %b_xy, i32 0 1119 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 1120 %b_xshuf_y = mul <2 x i4> %xshuf, %y 1121 call void @use(<2 x i4> %b_xshuf_y) 1122 ret i4 %b_xy0 1123} 1124 1125; negative test - splat doesn't match demanded element 1126 1127define i4 @common_binop_demand_via_extelt_op0_mismatch_elt0(<2 x i4> %x, <2 x i4> %y) { 1128; CHECK-LABEL: @common_binop_demand_via_extelt_op0_mismatch_elt0( 1129; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> <i32 1, i32 1> 1130; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = sub <2 x i4> [[XSHUF]], [[Y:%.*]] 1131; CHECK-NEXT: [[B_XY:%.*]] = sub nsw <2 x i4> [[X]], [[Y]] 1132; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 0 1133; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 1134; CHECK-NEXT: ret i4 [[B_XY0]] 1135; 1136 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> <i32 1, i32 1> 1137 %b_xshuf_y = sub <2 x i4> %xshuf, %y 1138 %b_xy = sub nsw <2 x i4> %x, %y 1139 %b_xy0 = extractelement <2 x i4> %b_xy, i32 0 1140 call void @use(<2 x i4> %b_xshuf_y) 1141 ret i4 %b_xy0 1142} 1143 1144; negative test - splat doesn't match demanded element 1145 1146define i4 @common_binop_demand_via_extelt_op0_mismatch_elt1(<2 x i4> %x, <2 x i4> %y) { 1147; CHECK-LABEL: @common_binop_demand_via_extelt_op0_mismatch_elt1( 1148; CHECK-NEXT: [[XSHUF:%.*]] = shufflevector <2 x i4> [[X:%.*]], <2 x i4> poison, <2 x i32> zeroinitializer 1149; CHECK-NEXT: [[B_XSHUF_Y:%.*]] = sub <2 x i4> [[XSHUF]], [[Y:%.*]] 1150; CHECK-NEXT: [[B_XY:%.*]] = sub nsw <2 x i4> [[X]], [[Y]] 1151; CHECK-NEXT: [[B_XY0:%.*]] = extractelement <2 x i4> [[B_XY]], i64 1 1152; CHECK-NEXT: call void @use(<2 x i4> [[B_XSHUF_Y]]) 1153; CHECK-NEXT: ret i4 [[B_XY0]] 1154; 1155 %xshuf = shufflevector <2 x i4> %x, <2 x i4> poison, <2 x i32> zeroinitializer 1156 %b_xshuf_y = sub <2 x i4> %xshuf, %y 1157 %b_xy = sub nsw <2 x i4> %x, %y 1158 %b_xy0 = extractelement <2 x i4> %b_xy, i32 1 1159 call void @use(<2 x i4> %b_xshuf_y) 1160 ret i4 %b_xy0 1161} 1162 1163define <2 x i8> @common_binop_demand_via_splat_mask_poison(<2 x i8> %x, <2 x i8> %y) { 1164; CHECK-LABEL: @common_binop_demand_via_splat_mask_poison( 1165; CHECK-NEXT: [[YSPLAT:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> poison, <2 x i32> <i32 0, i32 poison> 1166; CHECK-NEXT: [[VV:%.*]] = add <2 x i8> [[X:%.*]], [[YSPLAT]] 1167; CHECK-NEXT: [[MSPLAT:%.*]] = shufflevector <2 x i8> [[VV]], <2 x i8> poison, <2 x i32> zeroinitializer 1168; CHECK-NEXT: [[RES:%.*]] = add <2 x i8> [[VV]], [[MSPLAT]] 1169; CHECK-NEXT: ret <2 x i8> [[RES]] 1170; 1171 %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 0, i32 poison> ; <y0, poison> 1172 %vv = add <2 x i8> %x, %ysplat ; <x0+y0, poison> 1173 %m = add <2 x i8> %x, %y ; <x0+y0, x1+y1> 1174 %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 0, i32 0> ; LeftDemanded = 1 ; <x0+y0, x0+y0> 1175 %res = add <2 x i8> %vv, %msplat ; <x0+y0+x0+y0, poison> 1176 ret <2 x i8> %res 1177} 1178 1179define <2 x i8> @common_binop_demand_via_splat_mask_poison_2(<2 x i8> %x, <2 x i8> %y) { 1180; CHECK-LABEL: @common_binop_demand_via_splat_mask_poison_2( 1181; CHECK-NEXT: [[YSPLAT:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> poison, <2 x i32> <i32 poison, i32 0> 1182; CHECK-NEXT: [[VV:%.*]] = add <2 x i8> [[X:%.*]], [[YSPLAT]] 1183; CHECK-NEXT: [[M:%.*]] = add <2 x i8> [[X]], [[Y]] 1184; CHECK-NEXT: [[MSPLAT:%.*]] = shufflevector <2 x i8> [[M]], <2 x i8> [[Y]], <2 x i32> <i32 0, i32 2> 1185; CHECK-NEXT: [[RES:%.*]] = add <2 x i8> [[VV]], [[MSPLAT]] 1186; CHECK-NEXT: ret <2 x i8> [[RES]] 1187; 1188 %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0> 1189 %vv = add <2 x i8> %x, %ysplat 1190 %m = add <2 x i8> %x, %y 1191 %msplat = shufflevector <2 x i8> %m, <2 x i8> %y, <2 x i32> <i32 0, i32 2> ; LeftDemanded = 1, RightDemanded = 1 1192 %res = add <2 x i8> %vv, %msplat 1193 ret <2 x i8> %res 1194} 1195 1196define <2 x i8> @common_binop_demand_via_splat_mask_poison_3(<2 x i8> %x, <2 x i8> %y) { 1197; CHECK-LABEL: @common_binop_demand_via_splat_mask_poison_3( 1198; CHECK-NEXT: [[YSPLAT:%.*]] = shufflevector <2 x i8> [[Y:%.*]], <2 x i8> poison, <2 x i32> <i32 poison, i32 0> 1199; CHECK-NEXT: [[VV:%.*]] = add <2 x i8> [[X:%.*]], [[YSPLAT]] 1200; CHECK-NEXT: [[M:%.*]] = add <2 x i8> [[X]], [[Y]] 1201; CHECK-NEXT: [[MSPLAT:%.*]] = shufflevector <2 x i8> [[M]], <2 x i8> poison, <2 x i32> zeroinitializer 1202; CHECK-NEXT: [[RES:%.*]] = add <2 x i8> [[VV]], [[MSPLAT]] 1203; CHECK-NEXT: ret <2 x i8> [[RES]] 1204; 1205 %ysplat = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 poison, i32 0> 1206 %vv = add <2 x i8> %x, %ysplat 1207 %m = add <2 x i8> %x, %y 1208 %msplat = shufflevector <2 x i8> %m, <2 x i8> poison, <2 x i32> <i32 0, i32 0> ; LeftDemanded = 1 1209 %res = add <2 x i8> %vv, %msplat 1210 ret <2 x i8> %res 1211} 1212