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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] Missing fold for (a >> 1) / (1 % a) --> (a >> 1)
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    https://alive2.llvm.org/ce/z/-9TW-b
```llvm
define i32 @src(i32 %0) {
%1:
  %2 = ashr i32 %0, 1
  %3 = srem i32 1, %0
  %4 = sdiv i32 %2, %3
  ret i32 %4
}
=>
define i32 @tgt(i32 %0) {
%1:
  %2 = ashr i32 %0, 1
  ret i32 %2
}
Transformation seems to be correct!
```

Original source code:
https://godbolt.org/z/rMxG46onY
```c
int foo(int a)
{
 return (a >> 1) / (1 % a);
}

int bar(int a)
{
  return (a >> 1);
}
```

Gcc folds `foo` to `bar`, and Clang can fold (only) the following `unsigned int` case:
https://godbolt.org/z/oqcaTzzKf
```c
unsigned int baz(unsigned int a)
{
  return (a >> 1) / (1 % a);
}

unsigned int qux(unsigned int a)
{
  return (a >> 1);
}
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE1v2zAM_TX0RUggU44aH3xom7oYhmKXAsOOsi072mSpleR-5NcPUpx-BNnWYQOCJBIf-cj3bArv1WCkrGB1AatNJqawta76sRDO2UefNbZ7rrYh3Hlg54A1YC20epC41PphXFo3ANatBKx3gPWivP26aIBugJ4Dp_tPBO6vOtkrI4liSKCg3rWA63TAFQUsCZxdzLm4yiNfOpAYRwJsQ4TfOvKacUnyNxCWIN7JMUHyGE-4V0ixh3Tq4VAFZxQ7oJwMh1gxN3O2mf-wDbCrU6OEIfy_Ud50gEcd3DphfG_dKIKyhngpR0-CJY0krXVOtgEwP5J_PqbvL04NyghNvJ1cG5M6-dLce5cH2zVWh9nhaK67ebouuDXfjgja_VmZQHprow4mEAFYHpqflYiDTc4QwLUgUUh2FU0qCWAdL_M48T6RXRxL_0LRCPcbil9xnKh4Sp_rtiW91Z0nwGkchtMoL3AaaXnySZiOXGphBtIKk9CRzRr9HGcJWxnvtH1UZoiJk0kvWEeUCbFcK_zHJbf3rbjd7T73pyV_W5s0Yge4fnf1Nwp93IV3FPfT07-w_tGXrKtYV7JSZLLK-TrnOTKO2bYqacMkzWnfdblEzigi9msp-rbpmCxopiqkyGiRc4oMC1yyZt335brk8qwvilUJBZWjUPplk2XK-0lWHHPOMi0aqX1ai4hGPpIUBMS4JV0VcxbNNHgoqFY--NcqQQWd9ukn48OlHRtlJKw25EZ5Hx-K9Mj01n3AArJYxOAxMJucPlrKgwrbqVm2dgSs08bd_yzunP2e9kKdBvCAdRrwZwAAAP__VfiZKQ">