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

    <tr>
        <th>Summary</th>
        <td>
            opt crashes on ghc-generated IR
        </td>
    </tr>

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

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

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

<pre>
    Compiling the following Haskell from the [Happy](https://www.haskell.org/happy/) test suite using GHC 9.0.2:   [issue93.a.hs.gz](https://github.com/llvm/llvm-project/files/9436231/issue93.a.hs.gz)

using the command line:  `ghc -fllvm -Wall -Werror -fforce-recomp issue93.a.hs -o issue93.a.bin`

generates the following IR:  [ghc_4.ll.gz](https://github.com/llvm/llvm-project/files/9436237/ghc_4.ll.gz)

GHC then invokes `opt`, with the following command line:  `opt -mem2reg -globalopt -lower-expect -enable-tbaa -tbaa -relocation-model=pic ghc_4.ll -o ghc_6.bc`

which crashes when processing the IR with the following traceback:   [3TTJHXQYK.txt](https://github.com/llvm/llvm-project/files/9436246/3TTJHXQYK.txt)
 
 Tested using `opt` from LLVM 13.0.1, 14.0.6, and git master, on amd64, arm64, and ppc64le.  Same traceback on all versions and arches.  The specific traceback above is from git master.  Fully reproducible from what I can tell.

I tried to minimize the IR, first using `bugpoint`.  Unfortunately `bugpoint` itself segfaults, with the exact same traceback as `opt`.  I then tried using `llvm-reduce`, but it also segfaults after three passes, and the slightly reduced IR it leaves behind is not valid, and can't be processed by `opt`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytlU2TmzgQhn8NvqigMBhsHzgkM5WMd7OHJLObzSklRAPaEYiShD2TX7-vwJ9Tc0lVqlygr-5-9XQ3LnX1UtzpbpBK9g1zLbFaK6UPfvbA7RMpxWqju2kryN4_8GF4CbL7INm0zg02SN8FyQf8DodD1M4GkTYNVtrpqN_cMkfWMTtKR2y03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