diff --git a/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll b/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll index 932dcf8e56271..f444404d14d0e 100644 --- a/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll +++ b/llvm/test/Transforms/InstCombine/vec_demanded_elts.ll @@ -672,3 +672,64 @@ bb: %tmp2 = extractelement <4 x i32*> %tmp, i64 0 ret i32* %tmp2 } + +; The non-zero elements of the result are always 'min', so the splat is unnecessary. + +define <4 x i8> @select_cond_with_eq_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @select_cond_with_eq_true_false_elts( +; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> undef, <4 x i32> zeroinitializer +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[SPLAT]], <4 x i8> [[TVAL]], <4 x i8> [[Y]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %splat = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> zeroinitializer + %r = select <4 x i1> %splat, <4 x i8> %tval, <4 x i8> %y + ret <4 x i8> %r +} + +; First element of the result is always x[0], so first element of select condition is unnecessary. + +define <4 x i8> @select_cond_with_eq_true_false_elts2(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @select_cond_with_eq_true_false_elts2( +; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> undef, <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[TVAL]], <4 x i8> [[X]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> + %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x + ret <4 x i8> %r +} + +; Second element of the result is always x[3], so second element of select condition is unnecessary. +; Fourth element of the result is always undef, so fourth element of select condition is unnecessary. + +define <4 x float> @select_cond_with_eq_true_false_elts3(<4 x float> %x, <4 x float> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @select_cond_with_eq_true_false_elts3( +; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[FVAL:%.*]] = shufflevector <4 x float> [[Y]], <4 x float> [[X]], <4 x i32> +; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> undef, <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x float> [[TVAL]], <4 x float> [[FVAL]] +; CHECK-NEXT: ret <4 x float> [[R]] +; + %tval = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> + %fval = shufflevector <4 x float> %y, <4 x float> %x, <4 x i32> + %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> + %r = select <4 x i1> %cond, <4 x float> %tval, <4 x float> %fval + ret <4 x float> %r +} + +define <4 x i8> @select_cond_with_undef_true_false_elts(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @select_cond_with_undef_true_false_elts( +; CHECK-NEXT: [[TVAL:%.*]] = shufflevector <4 x i8> [[Y:%.*]], <4 x i8> undef, <4 x i32> +; CHECK-NEXT: [[COND:%.*]] = shufflevector <4 x i1> [[CMP:%.*]], <4 x i1> undef, <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[COND]], <4 x i8> [[TVAL]], <4 x i8> [[X:%.*]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %tval = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %cond = shufflevector <4 x i1> %cmp, <4 x i1> undef, <4 x i32> + %r = select <4 x i1> %cond, <4 x i8> %tval, <4 x i8> %x + ret <4 x i8> %r +}