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

    <tr>
        <th>Summary</th>
        <td>
            NVPTX cannot select dynamic_stackalloc with OpenMP and Eigen
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Compiling Eigen with OpenMP offload gives the following error
```
LLVM ERROR: Cannot select: t13: i64,ch = dynamic_stackalloc t4:1, t23, Constant:i64<0>
  t23: i64 = shl t4, Constant:i32<3>
    t4: i64,ch = load<(dereferenceable load (s64) from %ir.105)> t0, FrameIndex:i64<99>, undef:i64
      t1: i64 = FrameIndex<99>
      t3: i64 = undef
    t24: i32 = Constant<3>
 t2: i64 = Constant<0>
In function: _ZN5Eigen8internal23triangular_solve_matrixIdlLi1ELi2ELb0ELi0ELi0ELi1EE3runEllPKdlPdllRNS0_15level3_blockingIddEE
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/mdewing/prev/software/llvm/usr_main/bin/clang-linker-wrapper --cuda-path=/usr/local/cuda --host-triple=x86_64-unknown-linux-gnu --linker-path=/usr/bin/ld -- -pie -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/home/mdewing/prev/software/llvm/usr_main/bin/../lib/x86_64-unknown-linux-gnu -L/home/mdewing/prev/software/llvm/usr_main/lib/clang/17/lib/x86_64-unknown-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/lib -L/usr/lib /tmp/testEigenNoFit_cpu-ec64de.o -lstdc++ -lm -lomp -lomptarget -lomptarget.devicertl -L/home/mdewing/prev/software/llvm/usr_main/lib -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o /lib/x86_64-linux-gnu/crtn.o
1.      Running pass 'Function Pass Manager' on module 'ld-temp.o'.
2.      Running pass 'NVPTX DAG->DAG Pattern Instruction Selection' on function '@_ZN5Eigen8internal23triangular_solve_matrixIdlLi1ELi2ELb0ELi0ELi0ELi1EE3runEllPKdlPdllRNS0_15level3_blockingIddEE'
```

The full stack trace is in the attached file (out.txt), along with a reproducer and a compile script.
[eigen_alloc_select.tar.gz](https://github.com/llvm/llvm-project/files/12133771/eigen_alloc_select.tar.gz)

If EIGEN_ALLOCA is forcibly disabled (`#undef EIGEN_ALLOCA` after it is defined in Eigen/src/Core/Memory.h), the compilation gets further but  has a different 'cannot select' error.


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vs1u4zgSfhr6UpAgUbZlH3xwO1IjWHc6SAaDxV4MiixJ3FCkQFL5madfkHI6TpDdnZ4GBrBJm6z66odF1seck51G3JHVF7K6WrDJ98buBmYfBD5J3S0aI152BzOMUkndQSU71PAkfQ_fR9TfbsG0rTJMQCcf0YHvEVqjlAnKgNYaS7Irku3JOjt_4t_j8fdvUN3dfb8jxR4OTGvjwaFC7sOCz4swyfWS0APvgRRXIF40GyQ_Oc_4A1PKcPBLUuxzQg_gaRGmg9HOMx0wgm5xyEhRzRYhysygEc_1KgB80CooKQ7FhRbMVt77EiImxYHQjUCLLVrUHFmjMO4AoRsXxLfQWjMAoStp0zxbEbolRQU-C1Zrywa81gKff3i7Ddthb9IC2_PyDz8AfH4ZwCXAWfVS9l2wM-BbSHSOqaBx9y0Bl6F7eolwIfOW1G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