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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] miscompilation offload to amdgpu
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          ye-luo
      </td>
    </tr>
</table>

<pre>
    On gfx90a and with rocm 5.4.0 device lib
Using https://github.com/ye-luo/miniqmc testing commit 6f526b6062682ec892fb02d2919484c8b4db0875

```
mkdir build_llvm_offload_cuda2hip_real; cd build_llvm_offload_cuda2hip_real
cmake -DCMAKE_CXX_COMPILER=clang++ -DENABLE_OFFLOAD=ON -DOFFLOAD_TARGET=amdgcn-amdhsa -DOFFLOAD_ARCH=gfx90a ..
make -j32 test_omptarget_blas
./src/Platforms/tests/OMPTarget/test_omptarget_blas
```
failure is sporadic. the result should be integer stored in floats but it is not.
```
-------------------------------------------------------------------------------
OmpBLAS gemv
-------------------------------------------------------------------------------
/ccs/home/yeluo/test/miniqmc/src/Platforms/tests/OMPTarget/test_omp_BLAS.cpp:179
...............................................................................

/ccs/home/yeluo/test/miniqmc/src/Platforms/tests/OMPTarget/test_omp_BLAS.cpp:175: FAILED:
  CHECK( Cs[batch][index] == Ds[batch][index] )
with expansion:
  586417.0317596535 == 586417.0

/ccs/home/yeluo/test/miniqmc/src/Platforms/tests/OMPTarget/test_omp_BLAS.cpp:175: FAILED:
  CHECK( Cs[batch][index] == Ds[batch][index] )
with expansion:
  728143.0635398587 == 728143.0

===============================================================================
test cases:    1 |    0 passed | 1 failed
assertions: 6576 | 6574 passed | 2 failed
```
Interestingly, if I edit
```
diff --git a/src/Platforms/OMPTarget/ompBLAS.cpp b/src/Platforms/OMPTarget/ompBLAS.cpp
index ce895f0..ca9d395 100644
--- a/src/Platforms/OMPTarget/ompBLAS.cpp
+++ b/src/Platforms/OMPTarget/ompBLAS.cpp
@@ -93,7 +93,6 @@ ompBLAS_status gemv(ompBLAS_handle&     handle,
   return gemv_impl(handle, trans, m, n, alpha, A, lda, x, incx, beta, y, incy);
 }
 
-#if !defined(OPENMP_NO_COMPLEX)
 ompBLAS_status gemv(ompBLAS_handle& handle,
                     const char trans,
                     const int                        m,
@@ -125,7 +124,6 @@ ompBLAS_status gemv(ompBLAS_handle& handle,
 {
   return gemv_impl(handle, trans, m, n, alpha, A, lda, x, incx, beta, y, incy);
 }
-#endif
```
which basically compiles a few more unused offload regions. test_omptarget_blas passes reliably.

Even with the above workaround, if I add -DCMAKE_CXX_FLAGS=-foffload-lto in cmake, the test returns to failure mode.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkF0lv2zr619CXDxYkaj_4YFv2e8FL4qDtAL0ZFElZbClSQ1JZ_v2AtJwmbWY6LTrzDhUEicu3b_xIrBUnxfkK5RuE8Semuem4cQhjlDcLMrlem9UTX8pJL1rNnlYHBafusY4JEMXgQbgejKYD5FEWxcD4vaAcpGhR3KB4_Q8r1Al650aL0jXCe4T3J-H6qY2oHhDen0kjvB-EEv8cKDhuncehehiEg6LLcdEWcYGLCnNa1bhrY8xwndRZldGqzVgbV2V-Zjd_i3h-w3T4zISBdhKSHaW8H46666Qm7EgnRnAvxqPhRKJ0A5R9HyyQpAP5zGHZbG_Wf-2O248fj9vDzd3V9e4dShsqiTohvEF4A8tmd7veXO-Oh_3--rBuUNocbmHZzNPjh_W7P3YfUNqQgZ2oWpKB9Za8AFi_2_6J0mY2eRTNKgX2n1IczHXUw-iIOXF3bCWxZ5AI4b01FOH9nSSu02awCO89uP8fbu4-BIx57U0SX9mxI0JOhoOwYEdtCBM0AtdzMNxO0oHt9SQZtByEcvzEDVinDWcgFHhLOgvt5EA4T0FpF73JZflrnzPRwzBurtfv4cSH-_8hG4T3lHrz9nrgIbjPse0t_CXEf9gxRy97RMcRpeukrG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