<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114482>114482</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SPIR-V] Reg2Mem producing unwanted bitcast
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
spall
</td>
</tr>
</table>
<pre>
It seems enabling reg2mem here ( #111026 ) has introduced what looks like a bug, when doing SPIRV codegen. What looks like an unnecessary bitcast is generated. See %9:
```llvm
%1 = OpTypeFloat 32
%2 = OpTypeFunction %1 %1
%3 = OpTypeInt 32 0
%4 = OpConstant %3 0
%5 = OpConstant %1 0
%6 = OpConstant %1 1
%8 = OpFunction %1 None %2 ; -- Begin function saturate_float
%7 = OpFunctionParameter %1
%12 = OpLabel
%9 = OpBitcast %3 %4
%10 = OpExtInst %1 %11 FClamp %7 %5 %6
OpReturnValue %10
OpFunctionEnd
```
saturate-repro.ll :
```llvm
; this was just taken from the
; llvm/CodeGen/SPIRV/hlsl-intrinsics/saturate.ll test cases.
define noundef float @saturate_float(float noundef %a) {
entry:
%hlsl.saturate = call float @llvm.spv.saturate.f32(float %a)
ret float %hlsl.saturate
}
```
To reproduce this issue:
- build main branch llvm
- cmake command used:
```
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -C <your-path>/llvm-project/clang/cmake/caches/HLSL.cmake -DLLVM_ENABLE_ASSERTIONS=On -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DLLVM_USE_LINKER=lld ../llvm
```
- run test provided above.
```
llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown saturate-repro.ll -o -
```
note: this bitcast seemingly appears in all the CodeGen/SPIRV/hlsl-intrinsics tests.
note: Also see comment I left on #111026
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVltv4joX_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