Skip to content

[SPIR-V] Reg2Mem producing unwanted bitcast #114482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spall opened this issue Oct 31, 2024 · 1 comment · Fixed by #114877
Closed

[SPIR-V] Reg2Mem producing unwanted bitcast #114482

spall opened this issue Oct 31, 2024 · 1 comment · Fixed by #114877
Assignees

Comments

@spall
Copy link
Contributor

spall commented Oct 31, 2024

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

@Keenuts
Copy link
Contributor

Keenuts commented Nov 4, 2024

Thanks for the issue & repro!
Looking into what @VyacheslavLevytskyy suggested

@VyacheslavLevytskyy VyacheslavLevytskyy self-assigned this Nov 4, 2024
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this issue Nov 6, 2024
…pes (llvm#114877)

The goal of the PR is to ensure that no OpBitcast is generated for a
bitcast between identical types.

This PR resolves llvm#114482
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants