[all-commits] [llvm/llvm-project] 9de497: [SPIRV] Preserve implicit bitcast (#151041)

Farzon Lotfi via All-commits all-commits at lists.llvm.org
Wed Jul 30 11:38:56 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9de49703b82e8e3d45d2e1ceb2626f5bb920ee12
      https://github.com/llvm/llvm-project/commit/9de49703b82e8e3d45d2e1ceb2626f5bb920ee12
  Author: Farzon Lotfi <farzonlotfi at microsoft.com>
  Date:   2025-07-30 (Wed, 30 Jul 2025)

  Changed paths:
    M llvm/lib/Target/SPIRV/SPIRVLegalizePointerCast.cpp
    A llvm/test/CodeGen/SPIRV/hlsl-resources/issue-146942-ptr-cast.ll

  Log Message:
  -----------
  [SPIRV] Preserve implicit bitcast (#151041)

fixes #146942 

## Issue
The cause of the bug is in InstCombine which is converting our load of
float vec4 and bitcast to i32 vec4 into one load of i32 vec4. That means
wr have to do a legalization in the spirv backend to convert back
```diff
 -  %3 = load <4 x i32>, ptr addrspace(11) %2, align 16
 +  %3 = load <4 x float>, ptr addrspace(11) %2, align 16
 +  %4 = bitcast <4 x float> %3 to <4 x i32>
```
<img width="2566" height="548" alt="Image"
src="https://github.com/user-attachments/assets/0bf8813c-70f8-47df-8207-ab7da54f5382"
/>

https://godbolt.org/z/K4GeM4fKT

## The Fix
Just removing the assert isn't enough to fix this bug. If we do so we
get an assert later
`Assertion failed: (!storageClassRequiresExplictLayout(SC)), function
getOrCreateSPIRVPointerType, file SPIRVGlobalRegistry.cpp, line 1806.`

If we just remove the assert the `CreateShuffleVector` uses the source
type via the `NewLoad` when the `Output` type needs to be the
`TargetType`.

We also can't use`CreateBitCast` That will feed the right types for the
`ShuffleVector` but it doesn't emit OpBitcast. the llvmIR isn't
translated over to MIR.

The fix then is to emit `spv_bitcast` just like what
`SPIRVEmitIntrinsics::visitBitCastInst` does.

---------

Co-authored-by: Chris B <beanz at abolishcrlf.org>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list