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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP][libomptarget] Error with OpenMPOpt / Attributor for Kokkos library
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            openmp
      </td>
    </tr>

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

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

<pre>
    I ran into a failing assertion when compiling the Kokkos library release-candidate branch for their upcoming release 4.0 with trunk.
The Kokkos library is configured with CMake and the following flags (though the `Kokkos_ARCH_` flag is changed manually in `ccmake` thereafter to GFX1030). The problem goes away if I set the `openmp-opt-max-iterations` to 1.
```
-D CMAKE_BUILD_TYPE=Release
    -D CMAKE_CXX_STANDARD=17
 -D CMAKE_CXX_EXTENSIONS=OFF
    -D CMAKE_INSTALL_PREFIX=$KOKKOS_INSTALL_DIR
    -D CMAKE_CXX_COMPILER=/path/to/llvm/clang++
    -D CMAKE_CXX_FLAGS="-mllvm -time-passes -mllvm -openmp-opt-max-iterations=20"
    -D CMAKE_VERBOSE_MAKEFILE=ON
    -D Kokkos_ARCH_NATIVE=ON
    -D Kokkos_ARCH_VEGA90A=ON
    -D Kokkos_ENABLE_OPENMP=ON
    -D Kokkos_ENABLE_OPENMPTARGET=ON
    -D Kokkos_ENABLE_COMPILER_WARNINGS=ON
    -D Kokkos_ENABLE_TESTS=ON
```
The assertion error I'm getting is
```
static llvm::Constant* llvm::ConstantInt::get(llvm::Type*, const llvm::APInt&): Assertion `C->getType() == Ty->getScalarType() && "ConstantInt type doesn't match the type implied by its value!"' failed.
```

I have attached an llvm-reduce'd `.ll` file that reproduces the error as well as the complete stack trace.
Let me know if more information is needed.

[20230215-Kokkos-BuildError-trunk-stacktrace.txt](https://github.com/llvm/llvm-project/files/10747595/20230215-Kokkos-BuildError-trunk-stacktrace.txt)
[reduced.ll.txt](https://github.com/llvm/llvm-project/files/10747777/reduced.ll.txt)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVV2PozoS_TXOS4kITBOShzyQAL2o00mUZGd7nyIDFfDEYGSb6cm_Xxn6a2Z77tyRroRA2KeqTh1XlZnWvGoRlyRYkSCesN7UUi2_dgJrNclleVtmoFgLvDUSGFwYF7ytgGmNynDZwnONLRSy6cYNUyM8yOtVahA8V0zdQKFAptEpWFvykhmEXLG2qOEilcVzBX1XyMaav2DhburCMzc1GNW31ylxY-JGp__3zTUUsr3wqldYjhbrR3ZFYG05cLlIIeSzdX0RrNJA6NzUsq_qYZfM3NHhOTqs_3UmM3eADW5r1lZYQsPanglxA95aeFE07IoWaGpUyC4GFRgJ9-mT5_ouoYspWJ6dkrnABiqJGtgzuwG_QAYazWtg2WHbdI7sjNOw7w43qJhVVA_OJXgvWZOZ-_IMv04M68foITmv_p1t4vPpv_uE-PFh1G2EAAC8wdZPT-fjKdrG0SEmfuyFL5gfAMnTKdkes932SPx4l6af-Mm2x1O02Zz3hyTNnogfE3r3sHt42B3ftuLs8AsC693jPtskh8Es7ZipCU2NJDQV4ltDaFoI1laEruzzuYt0E90fB3vqNNYKHMMbdDpbihpe136tqh9Tl1D6ifsvyWG1OyZn-5NmG6vnbvsD7mORbKNT9uU3mC_JfbRwo1-Ckm202iTn3T7ZPu7_HuoUHe6T0--wr0Kf_xMdttl2UOwvDU7J8fQR9FO12VJ-73VUSirICA0bqNAY21Zcf2qoDTO8gOF4_Yj40Vq22rDWEBp9spq1Zlyo0BA6fwecbh0SGhG6to2uzQfbaG-t6IzQBfEjiN5okpm7doifVGhG8zmhC7C148dwur1sHQsmmPoIsK5mQCj9wArMrUMoJeqW0NBAw0wxzo5hgzed4FhCfgNuNHxjokdCPVtnNBymJZaf9_H4zqBm3xCYMayosQTWDgk6Csu-QELD0mYzFWIYTVwgmJoZUNgpaRF6oDKeC9PwjELYr120M1mgQdCGFVcwihX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