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

    <tr>
        <th>Summary</th>
        <td>
            [InstrCombine] visitGetElementPtrInst can cause InstrCombine
        </td>
    </tr>

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

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

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

<pre>
    `InstCombinerImpl::visitGetElementPtrInst()` constructs phi-node and GEP in attempt to combine the new GEP with the old one, however, this GEP is not removed on fail. Turns out, that this behavior can cause `InstCombine` to run arbitrary many times.
```c
//increment addresses + load
#define iter l = l+d;\
                 v += *l;\

#define TEN(x) x x x x x x x x x x

float foo(float *l, int d, int a) {
  float v = 0.0;

// Address operations will generate a chain of GEPs
 TEN(TEN(iter));

  if (a) {
    // This will also create a GEP
    iter;
  }

  // visitGetElementPtrInstr will try to move the GEPs to this BB, moving one GEP at a single InstrCombine::run().
  iter;

  return v;
}
```
By adding `TEN()` to the above code, one can force `InstCombine` to run arbitrary large number of times, thus crashing the compiler on hitting `InstCombineDefaultIniniteLoopThreshold`.

This example may seem artificial, however we've faced this situation in our (Huawei) downstream target as a result of `LoopFullUnrollPass`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVN1u8zYMfRrlhmjgyvmxL3LRNG1XYBh60T0ALdOxNlkKJDpp3n6gnLRptwFfGySyfHR4KB4SU7J7T7RRy61a7mY4ch_ihgPbv8Mwa0J73qhV8eoTP4ahsZ7i63BwqnxQ5cPRJssvxE-OBvL8xlFwSldK12pVgAk-cRwNJzj09s6HlgB9Cy9Pb2A9IDMNBwYOYCZu4J7A0ykjTpb7vBFcC8GT0o_QhxMdKcqSe5smpgQ-MEQawpEECR1aN4f3MfoEYeQJjTwdaajHow0RDHowOCaC7wmKcg4QRw8YG8sR4xkG9GdgO1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