<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/87843>87843</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SPIRV]  crash on alloca\store for i8  while emitting function
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:SPIR-V,
            SPIR-V
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          farzonl
      </td>
    </tr>
</table>

<pre>
    This is a minified example I came across from testing hlsl's all intrinsic in preperation for lowering
https://github.com/llvm/llvm-project/blob/main/clang/test/CodeGenHLSL/builtins/all.hlsl#L259C1-L259C48

The example below is the spirv func without the all intrinsic on a bool scalar.


; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s

```python
define spir_func noundef i1 @test_bool_ret(i1 noundef %p0) {
entry:
  %p0.addr = alloca i8, align 1
  %frombool = zext i1 %p0 to i8
  store i8 %frombool, ptr %p0.addr, align 1
  %0 = load i8, ptr %p0.addr, align 1
  %tobool = trunc i8 %0 to i1
  ret i1 %tobool
}
```
If I instead change the function up to be an int16 instead of an int8 everything works fine
```python
define spir_func noundef i1 @test_bool_ret(i1 noundef %p0) {
entry:
  %p0.addr = alloca i16, align 2
  %frombool = zext i1 %p0 to i16
  store i16 %frombool, ptr %p0.addr, align 2
  %0 = load i16, ptr %p0.addr, align 2
  %tobool = trunc i16 %0 to i1
  ret i1 %tobool
}
```

```python
        OpCapability Shader
 OpCapability Linkage
        OpCapability Int16
        OpMemoryModel Logical GLSL450
        OpSource Unknown 0
        OpName %7 "p0"
 OpName %8 "test_bool_ret"
        OpName %9 "p0.addr"
 OpName %10 "frombool"
        OpName %13 "tobool"
 OpDecorate %8 LinkageAttributes "test_bool_ret" Export
        %1 = OpTypeBool
        %2 = OpTypeFunction %1 %1
        %3 = OpTypeInt 16 0
        %4 = OpConstant %3 0
        %5 = OpConstant %3 1
 %6 = OpTypePointer Function %3
        %8 = OpFunction %1 None %2 ; -- Begin function test_bool_ret
        %7 = OpFunctionParameter %1
        %14 = OpLabel
        %9 = OpVariable %6 Function 
 %10 = OpSelect %3 %7 %5 %4
        OpStore %9 %10 Aligned 2
 %11 = OpLoad %3 %9 Aligned 2
        %12 = OpBitwiseAnd %3 %11 %5
 %13 = OpINotEqual %1 %12 %4
        OpReturnValue %13
 OpFunctionEnd
```

Crash Stack
```
LLVM ERROR: Unable to meet SPIR-V requirements for this target.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /mnt/DevDrive/projects/spirv-debug-build/bin/llc -O0 -mtriple=spirv-unknown-unknown /mnt/DevDrive/projects/llvm-project/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/all_test.ll -o -
1.      Running pass 'Function Pass Manager' on module '/mnt/DevDrive/projects/llvm-project/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/all_test.ll'.
2. Running pass 'SPIRV Assembly Printer' on function '@test_bool_ret'
 #0 0x00005654a4b163cd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /mnt/DevDrive/projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x00005654a4b168bb PrintStackTraceSignalHandler(void*) /mnt/DevDrive/projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x00005654a4b14926 llvm::sys::RunSignalHandlers() /mnt/DevDrive/projects/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #3 0x00005654a4b17075 SignalHandler(int) /mnt/DevDrive/projects/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x000078a21ba42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x000078a21ba969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #6 0x000078a21ba42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x000078a21ba287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x00005654a4a2e9c4 llvm::report_fatal_error(llvm::Twine const&, bool) /mnt/DevDrive/projects/llvm-project/llvm/lib/Support/ErrorHandling.cpp:125:5
 #9 0x00005654a4a2e832 /mnt/DevDrive/projects/llvm-project/llvm/lib/Support/ErrorHandling.cpp:83:3
#10 0x00005654a27ed330 llvm::SPIRV::RequirementHandler::checkSatisfiable(llvm::SPIRVSubtarget const&) const /mnt/DevDrive/projects/llvm-project/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp:577:1
#11 0x00005654a27e0d8d (anonymous namespace)::SPIRVAsmPrinter::outputGlobalRequirements() /mnt/DevDrive/projects/llvm-project/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp:346:13
#12 0x00005654a27e0cd3 (anonymous namespace)::SPIRVAsmPrinter::outputModuleSections() /mnt/DevDrive/projects/llvm-project/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp:561:3
#13 0x00005654a27e0ab1 (anonymous namespace)::SPIRVAsmPrinter::emitFunctionHeader() /mnt/DevDrive/projects/llvm-project/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp:126:5
#14 0x00005654a30dda03 llvm::AsmPrinter::emitFunctionBody() /mnt/DevDrive/projects/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1715:3
#15 0x00005654a176c96e llvm::AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) /mnt/DevDrive/projects/llvm-project/llvm/include/llvm/CodeGen/AsmPrinter.h:398:5
#16 0x00005654a3557246 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /mnt/DevDrive/projects/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:93:8
#17 0x00005654a3cb81aa llvm::FPPassManager::runOnFunction(llvm::Function&) /mnt/DevDrive/projects/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1441:23
#18 0x00005654a3cbd002 llvm::FPPassManager::runOnModule(llvm::Module&) /mnt/DevDrive/projects/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1487:16
#19 0x00005654a3cb8a9b (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /mnt/DevDrive/projects/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1556:23
#20 0x00005654a3cb8611 llvm::legacy::PassManagerImpl::run(llvm::Module&) /mnt/DevDrive/projects/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:541:16
#21 0x00005654a3cbd2e1 llvm::legacy::PassManager::run(llvm::Module&) /mnt/DevDrive/projects/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1683:3
#22 0x00005654a06c3207 compileModule(char**, llvm::LLVMContext&) /mnt/DevDrive/projects/llvm-project/llvm/tools/llc/llc.cpp:741:9
#23 0x00005654a06c13b5 main /mnt/DevDrive/projects/llvm-project/llvm/tools/llc/llc.cpp:408:13
#24 0x000078a21ba29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x000078a21ba29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00005654a06c0b25 _start (/mnt/DevDrive/projects/spirv-debug-build/bin/llc+0x5687b25)
Aborted (core dumped)
```
@sudonatalie  @Keenuts  for awareness.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWdty27rOfhrmhmOPRJ0vcuEcvJr5nTaTtLn1UBJs8w9FapFUE6-n30NKtg5Ou5v0sFenY8cUCHwfAIIgRbVmWwFwjqILFF2d0cbspDrfUPWPFPwsl-X-_POOacw0prhigm0YlBheaFVzwDe4oBVgWiipNd4oWWED2jCxxTuuOSKJxpRzzIRRTGhWYCZwraAGRQ2TAm-kwlw-g2Jii7wr5C12xtQaBQtElogst8zsmnxeyAqRJedfD1-zWsn_h8Igssy5zBFZVpQJRJYFp2KLyNLCQGR5KUv4C8SH1cPKijaMGyY0IkvK-byFGKxIlF36M_cVpi2K9vPzDo5Uc-Dy2brB7ADrmqmveNOIAj8zs5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