diff --git a/llvm/test/Transforms/InstCombine/select-select.ll b/llvm/test/Transforms/InstCombine/select-select.ll index ad7b5dbd4e25..bbe6b767ae9a 100644 --- a/llvm/test/Transforms/InstCombine/select-select.ll +++ b/llvm/test/Transforms/InstCombine/select-select.ll @@ -43,3 +43,95 @@ define <2 x i32> @foo3(<2 x i1> %vec_bool, i1 %bool, <2 x i32> %V) { %sel1 = select i1 %bool, <2 x i32> %sel0, <2 x i32> %V ret <2 x i32> %sel1 } + +define <4 x i8> @sel_shuf_commute0(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @sel_shuf_commute0( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[BLEND]], <4 x i8> [[X]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %blend = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %r = select <4 x i1> %cmp, <4 x i8> %blend, <4 x i8> %x + ret <4 x i8> %r +} + +define <5 x i9> @sel_shuf_commute1(<5 x i9> %x, <5 x i9> %y, <5 x i1> %cmp) { +; CHECK-LABEL: @sel_shuf_commute1( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <5 x i9> [[X:%.*]], <5 x i9> [[Y:%.*]], <5 x i32> +; CHECK-NEXT: [[R:%.*]] = select <5 x i1> [[CMP:%.*]], <5 x i9> [[BLEND]], <5 x i9> [[Y]] +; CHECK-NEXT: ret <5 x i9> [[R]] +; + %blend = shufflevector <5 x i9> %x, <5 x i9> %y, <5 x i32> + %r = select <5 x i1> %cmp, <5 x i9> %blend, <5 x i9> %y + ret <5 x i9> %r +} + +define <4 x float> @sel_shuf_commute2(<4 x float> %x, <4 x float> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @sel_shuf_commute2( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <4 x float> [[X:%.*]], <4 x float> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x float> [[X]], <4 x float> [[BLEND]] +; CHECK-NEXT: ret <4 x float> [[R]] +; + %blend = shufflevector <4 x float> %x, <4 x float> %y, <4 x i32> + %r = select <4 x i1> %cmp, <4 x float> %x, <4 x float> %blend + ret <4 x float> %r +} + +define <4 x i8> @sel_shuf_commute3(<4 x i8> %x, <4 x i8> %y, i1 %cmp) { +; CHECK-LABEL: @sel_shuf_commute3( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select i1 [[CMP:%.*]], <4 x i8> [[Y]], <4 x i8> [[BLEND]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %blend = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %r = select i1 %cmp, <4 x i8> %y, <4 x i8> %blend + ret <4 x i8> %r +} + +declare void @use(<4 x i8>) + +define <4 x i8> @sel_shuf_use(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @sel_shuf_use( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: call void @use(<4 x i8> [[BLEND]]) +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[BLEND]], <4 x i8> [[X]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %blend = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + call void @use(<4 x i8> %blend) + %r = select <4 x i1> %cmp, <4 x i8> %blend, <4 x i8> %x + ret <4 x i8> %r +} + +define <4 x i8> @sel_shuf_undef(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @sel_shuf_undef( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[BLEND]], <4 x i8> [[Y]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %blend = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %r = select <4 x i1> %cmp, <4 x i8> %blend, <4 x i8> %y + ret <4 x i8> %r +} + +define <4 x i8> @sel_shuf_not(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp) { +; CHECK-LABEL: @sel_shuf_not( +; CHECK-NEXT: [[NOTBLEND:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[NOTBLEND]], <4 x i8> [[Y]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %notblend = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %r = select <4 x i1> %cmp, <4 x i8> %notblend, <4 x i8> %y + ret <4 x i8> %r +} + +define <4 x i8> @sel_shuf_no_common_operand(<4 x i8> %x, <4 x i8> %y, <4 x i1> %cmp, <4 x i8> %z) { +; CHECK-LABEL: @sel_shuf_no_common_operand( +; CHECK-NEXT: [[BLEND:%.*]] = shufflevector <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i32> +; CHECK-NEXT: [[R:%.*]] = select <4 x i1> [[CMP:%.*]], <4 x i8> [[Z:%.*]], <4 x i8> [[BLEND]] +; CHECK-NEXT: ret <4 x i8> [[R]] +; + %blend = shufflevector <4 x i8> %x, <4 x i8> %y, <4 x i32> + %r = select <4 x i1> %cmp, <4 x i8> %z, <4 x i8> %blend + ret <4 x i8> %r +}