This patch changes the shufflevector's semantics to yield poison if the mask is undefined. This allows the extraction of shufflevectors while also opening the door for more optimization opportunities due to the fact that poison is more undefined than undef.
This is a continuation of the work done by @aqjune in D93818.
As described at https://github.com/llvm/llvm-project/issues/43530, here is a quick overview:
Undef in the shufflevector mask yielding undef even when the shuffled value is poison makes the following transformation invalid:
define <4 x float> @insert_not_undef_shuffle_translate_commute(float %x, <4 x float> %y, <4 x float> %q) { %xv = insertelement <4 x float> %q, float %x, i32 2 %r = shufflevector <4 x float> %y, <4 x float> %xv, <4 x i32> { 0, 6, 2, undef } ret <4 x float> %r } => define <4 x float> @insert_not_undef_shuffle_translate_commute(float %x, <4 x float> %y, <4 x float> %q) { %r = insertelement <4 x float> %y, float %x, i32 1 ret <4 x float> %r } float %x = poison <4 x float> %y = < poison, poison, poison, poison > <4 x float> %q = < poison, poison, poison, poison > Source: <4 x float> %xv = < poison, poison, poison, poison > <4 x float> %r = < poison, poison, poison, undef > Target: <4 x float> %r = < poison, poison, poison, poison > Source value: < poison, poison, poison, undef > Target value: < poison, poison, poison, poison >
The motivation for the current semantics was to be able to introduce shufflevectors when building a vector with a sequence of insertelements starting from an undef vector:
%t = insertelement <4 x float> undef, float %arg, i32 1 %t4 = insertelement <4 x float> %t, float %arg, i32 1 %t5 = insertelement <4 x float> %t4, float %arg, i32 2 %t6 = insertelement <4 x float> %t5, float %arg, i32 3 ret <4 x float> %t6 => %t = insertelement <4 x float> undef, float %arg, i32 0 %t2 = shufflevector <4 x float> %t, <4 x float> undef, <4 x i32> <i32 undef, i32 0, i32 0, i32 0> ret <4 x float> %t2
With the soft deprecation of undef these cases should become more rare. So these new semantics in combination with disabling these transformations when an undef placeholder is used should prevent miscompilations without meaningful regressions.
Theses cases are identified at https://web.ist.utl.pt/nuno.lopes/alive2/index.php?hash=a9bc405e427c007f with 'LLVM PR44185'.
I don't think this sentence really adds anything. It just introduces a new ill-defined term "don't-care vector".