Closed
Description
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:
%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 :
; 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