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

    <tr>
        <th>Summary</th>
        <td>
            [IndVarSimplify] Doesn't simplify induction variables stuck in vector operations
        </td>
    </tr>

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

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

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

<pre>
    Consider the test case below: 

```#include <stdbool.h>
typedef int ivec2 __attribute__((ext_vector_type(2)));
int data0;
void fn()
{
  int u_xlati59 = 1;
  while (true)
    {
      bool u_xlatb12 = u_xlati59 >= 3;
      if (u_xlatb12)
        {
          break;
        }
 ivec2 u_xlati12 = (ivec2){u_xlati59, u_xlati59} + (ivec2){-1, 1};
 data0 += u_xlati12.x;
      u_xlati59 = u_xlati12.y;
    }
}
```
LLVM will fail to unroll the above loop as IndVarSimplify pass is unable to detect a scalar induction variable stuck in vector operation. I have traced through the current implementation which bails out as SCEV fails on the vector operation. Although these patterns are prevalent in some GPU shaders; the above is a C variant that mimics the same. I'd like to know if support for such cases can be added to IndVarSimplify pass in which case I have a patch that helps the pass to identify such patterns and unroll loop. 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VM1u4zgTfBr60ohBUbZlH3Rw_j4EmA9YYLC5Gi2xHXFDkwLZVJK3X5CSk8zOrkAkMFVVXV1sEWM0L46oFdtbsb1fYeLBhxadsTjha3I6SdmsOq8_2jvvotEUgAcCpsjQYyToyPo3UR9ByGNeO7ksVRvX26QJRH0XWXfe2_Ug6gchj_wxkqYzGMdgJuoVnE7IHEyXmE4nofZC7emdTxP17MMp44XaK6EOy6pvhTxmukZGOf-cvNFwdoV9yF6avAulSjq9W2SzPYCo76GaCQBvg7EEQu05JJpZAABXZn6y74XeVarQv4s95I36qpcfc86Cn4zFizzMokIeALpA-Dpz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