<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJytVE2P0zAQ_TXOxaJKnCZpDzl0t1rEgb2AuDvxNDE4dvBHy_LrGTttCaA9IJCiOPa8Gb-ZeZPOiJf2GS5vPz3TSbreTLNU4KgfgZ6MUuYi9UBPQfdeGk3KA8mPJD-QOl8epc7T9WibD6qjpDxS-ObBaq7ooEyHi6y3hD1SruSg6e4KT28BJ6khAij6O9sTtksbVvlpJmxPSfOwQGk87I0-l-kONyqqw4Wu0Y-0ZDew88bCzZrcoj0xOdCF6x-c0hUO2d9veC06ntkEUm60mC_v_Q0b_X8FW7gb7TX55vh6Ffzg_6oK_7cCK7Ix4m90b21fs7-qZ-RuROFI7bwNSS24GbSxUUDceyu74BGg5BfA6A02D9-RgTNUesqdC1NSHvd0yZBrQVM7eGfOQDmmA1-DPHMF2m_oQ_BRpzp6B4eu99LwRcAKuACbksRIN2jPlXL0HfL8IKdZydMLvUg_3hVFWH1rq7exsdG5CwNhxTrtj-BiLIdzYs0UC2phgNFuFnPfxyMsruYuE20p9uWeZzz40dhWB21mZWZwWbCqHb2fXZwt9oTPgGRCt8FRxE2ar2V5M1vzGXoUx5PEWoHDj6pkxS4b21Mj-mJfFU3XNIVo-qoSQnRd3UEN25qLTPEOlGtJ9UAYuw86T0PNWCwRLumy8mBmLyf5PRldtFbH7N9JypbljOVFURWsYGW96Zt9tYOGN8U-B37aYrlg4lJtYpyNsUNm2xQSa-_QqKTz7qcR9YLyAkg5IUMvvYKW4m4RJJ7R9_c_2tJiVE_8Ha0lOhkRlFkJNEu820T6B2yokAI>53218</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
             [NewGVN] Miscompile with equal instructions modulo attributes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            miscompilation,
            llvm:optimizations
      </td>
    </tr>

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

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

<pre>
    NewGVN miscompiles the following function:
```llvm
@glb = external global i64, align 8

define i64 @src(i64 %tmp) {
  %conv3 = shl nuw i64 %tmp, 32
  store i64 %conv3, i64* @glb, align 8
  %sext = shl i64 %tmp, 32
  %r = lshr exact i64 %sext, 32
  ret i64 %r
}

define i64 @tgt(i64 %tmp) {
  %conv3 = shl i64 %tmp, 32
  store i64 %conv3, i64* @glb, align 8
  ret i64 %tmp
}
```

NewGVN hashes instructions ignoring attributes like 'nuw', so it assumes that conv3 and sext above are equivalent. But then it uses %conv3 as the leader, and then it calls InstSimplify with shl nuw & lshr extract and bug!

Test case from @regehr.
cc @alinas
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVE2PmzAQ_TXmYjUCEwIcOGQ32qqH7qVV7wYGcGts6o-k21_fsUlSttUeKlVCGHs-_ObNG1rdvzTPcHn_5ZnOwnZ6XoQES90EdNBS6otQIx286pzQiuRHkp5IeiSHdH2kPM_Xo306ypaS_EThhwOjuKSj1C0u4rAn7JFyKUZFq6t7fPcwCAXBgWK8NR1hVdywws0LYTUl5cPqSsNhp9U5j3fYSVLlL3Tr_UhzdnO2Thu4WWNYsEckR7pi_QtTvMIi-vsNb2XHMxOdpJ0M1ss7d_MN8a-dDdyN5lp8eXqbBTe6f2Lh_zKwARsy_gH31vYt-qt6Jm4nFI5Q1hkf1YKbUWkTBMSdM6L1Dh2k-AaYvcTm4TsgsJoKR7m1fo7K446uFXLV09gO3uozUI7lwHcvzlyCcjv64F3QqQrR3mLonRq-ClgC78HEIjHTzbXjUlr6AXF-EvMixfBCL8JNd0URdri11ZnQ2BDc-pGwbFv2Z7Ahl8U5MXoOhBoYYTK71dx14QjJVdwmfZP3dV7zxAknoaGkeFhZI8WJfryP3YoDSwwzs-Vx1r2XesNi4o1sJucWG0aSPeEzYqxvd5gKN3Es1-XdYvRX6FBTTwIpBosfRc6yKpmatGirQ1nzospqtu_yfZu2dZYPQ1fxPBsgkbwFaRvESxi7_x94_BcwFpjFJV6WH_XixCx-RqMN1uKUiIaljKVZVmQsY_lh15V1UUHJy6xOgQ975AhmLuQuJNlpMyamiaiRcItGKayzv40oEtQUQESE-bl3kzaN8kovUi9ITKyxiQX-ArQreZo">