<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJylVV2vozYQ_TXkZRQEBhJ4yMP96FZ5aFV1V3039hDca2yEzWVvf33Hhpub7K7UVpVIgLF95szMmaG18u2k9esAwg6D8knxACUvmUBWZXWdZM9J9vA7jpOVs0BYlO9py2oGO3rYj9w5dEnxnLCjsMb5iSvj96jVoAz3yhpagP1n2FvYQ9uq_aE8lHmq9YqSVI-3xvTyV1IRVt17P7rgi32i60KO5zYlkvQS-G63PTH7E4Wn105p4sE-HeuybJqMnr7FZc3mcovKzdpfo_nSI7QTN6LfoqM3UDkkrBLDmOcJewLNW9TB0rZp8a2BreeUA9Fzc0EJ3t5DdVw7_Nc4hpKV5rD0SvRwBt8r8xL-HdC1TNZc0ttwzsClJKfODhiLicbTVkNHkG7j7CFkCFxvF2Uu0fzK9YwObLeeUqF6swg1c5vfxc5awsBfMB7oZhOXAY2EeQTuA8kihUeC553HKW6bcJmUxwDsr2mFBe-PsegQubyL40uI0Hk-EfuejyOawDYID-4lMeGrwsWlQQapnS7B9HPe5V1WHFEWeZbLIjuW3aHquEDB65zltahrXmWV2DwesqsIn67a_elGutUznAfS2GvIjsSvRMnIQEjOU7h9KB7aWemw9H00I_cUvlpx3FaQADZwwy8YKvXPeL-FeO3s9FsQTMAQVoZUB_lT3T9OvtdudmTeSux7yvmCE4KxfgUcKcWhQn-EHewcCAXk9lpJElGrzLtWhMWuU0JFWW2FNbi8i1UqQW6ih4yEXKsOPvdBPA9SwsIdUEM294IN0rSOkHkYIOTa2IAI72AGYw9Bi6u0UzivegnuyRKZbS12EwRINVFK1jzRtjtMggvEf8XlvFkGPqYQml9wrXFa4QSPfWOolVG8AAWjfOQTEQIoN2-3wN8XHQ1vaSCtCPeldaAVNRSnPD3CV0iKJxqf26sJDq42mp1PKya-EhsV004pJnxK1o1YOjsRwHvk6VXeO3kqZFM0fMdnyvZ0GtQLR91bTarbzZM-_ec5q5yb46CtipwVu_7E2LE75lVdH2WBJR7o1xyPWcO5FEXTtLs43dyJmixhLCYtQNAztdfu_zNQJ5YxluV5ntVlUx3SI5eVKFkja97lR1YkZYYDV_o6KnZT_Obt2_niaFEr5z_myI4-aOpCxY6EiaFXXuPpF-WI0xhGaBxG8eP34w_eLhI8RXZ_Az6iZnw>53123</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Miscompile with opt -constraint-elimination
        </td>
    </tr>

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

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

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

<pre>
    llvm commit: 4a42ce25088
Reproduce with:
 opt -passes='constraint-elimination' -S -o - bbi-64641.ll
[bbi-64641.ll.gz](https://github.com/llvm/llvm-project/files/7844990/bbi-64641.ll.gz)

Result:
The branch
  br i1 %cmp11, label %bb.3, label %bb.2
is changed to
  br i1 false, label %bb.3, label %bb.2
in bb.1 which I think this is wrong.

I added some comments in the input file showing the values of some instructions which would make the function end up at bb.3. But after the rewrite of the branch we end up at bb.2 instead.

This starts happening with https://reviews.llvm.org/rG1f1f037ed3101d3074f65faceca81218c88a505c
`
[ConstraintElimination] Improve index handing during constraint building.

This patch improves the index management during constraint building.
Previously, the code rejected constraints which used values that were not
part of Value2Index, but after combining the coefficients of the new
indices were 0 (if ShouldAdd was 0).

In those cases, no new indices need to be added. Instead of adding to
Value2Index directly, add new indices to the NewIndices map. The caller
can then check if it needs to add any new indices.

This enables checking constraints like a + x <= a + n to x <= n,
even if there is no constraint for a directly.
`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyVVV2vozYQ_TXkZRQEBhLykIf7sVvloVXVXfXd2EPwXmMjbMLe_vqODclNdiu1laKAx_aZj3NmaKx8P2p96UHYvlc-KZ6g5CUTyKqsrpPsNcme_sBhtHISCLPyHR1ZzGAHD9uBO4cuKV4TthfWOD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