<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/151691>151691</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIR-V][HLSL] Fix lowering of poison in shufflevector when swizzle are used
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:SPIR-V
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
Keenuts
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Keenuts
</td>
</tr>
</table>
<pre>
Given the following sample
```hlsl
// RUN: %clang --driver-mode=dxc %s -T ps_6_8 -E main -O3 -spirv
/* Copyright (c) 2025, Sascha Willems
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 the "License";
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
struct VSOutput
{
float4 Position : SV_POSITION;
[[vk::location(0)]] float3 Color : COLOR0;
};
float4 main(VSOutput input) : SV_TARGET
{
return float4(input.Color, 1.0);
}
```
The generated IR is:
```llvm
%0 = load <3 x float>, ptr addrspace(7) @COLOR0, align 16
%1 = shufflevector <3 x float> %0, <3 x float> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 poison>
%vecinit78.i = insertelement <4 x float> %1, float 1.000000e+00, i64 3
store <4 x float> %vecinit78.i, ptr addrspace(8) @SV_TARGET0, align 16
```
Issue is the poison being used in the shufflevector index.
This is lowered as a `-1` in the backend, which causes a validation error.
Emitting any other valid index like `0` should be fine since the value is overriden just after.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVl9z4r4O_TTmRQOTOPx94IEC_S2zndIBtnv3acckCtGusXNtB9r99Hdkkt62v2U6g5tI50hHsoTynk4GcS5Gd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