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

    <tr>
        <th>Summary</th>
        <td>
            [InstCombine] (a+a+a+a)/(a+a) is not optimized
        </td>
    </tr>

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

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

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

<pre>
    Test case: https://godbolt.org/z/7caGb3avf
```c
int n1;
void func1(int a){

    if(a>0&&a<10){
        n1=(a+a+a+a)/(a+a);
 }
}
```
It appears that `InstCombine` is missing this pattern `(a+a+a+a)/(a+a) => 2`
clang -O3:
```llvm
if.then:
  %a.tr = trunc i32 %a to i8
  %div.lhs.trunc = shl nuw nsw i8 %a.tr, 2
 %div.rhs.trunc = shl nuw nsw i8 %a.tr, 1
  %div12 = udiv i8 %div.lhs.trunc, %div.rhs.trunc
  %div.zext = zext i8 %div12 to i32
 store i32 %div.zext, ptr @n1, align 4
  br label %if.end
```
```asm
func1(int):                              # @func1(int)
        lea     eax, [rdi - 1]
        cmp     eax, 8
 ja      .LBB0_2
        lea     eax, [4*rdi]
        add     dil, dil
        movzx   eax, al
        div     dil
        movzx   eax, al
        mov     dword ptr [rip + n1], eax
.LBB0_2: # %if.end
        ret
```

proof: https://alive2.llvm.org/ce/z/5UXwMN
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVV2PqzYQ_TXmZbQIxnwkDzwkm5vqSv14aaW2L5XBJvgKbGSbZJtfX9lAbpJdaXtRgpn4nJnjmWHCrJUnJURF8j3JDxGbXKdN9fdfeVZEteb_Vr8L66BhVhC6g8650RK6I3gkeDxpXuvexdqcCB6vBI9lw36qKTu3JDmQZEeKZP40sy2VA5USup_Ns5Yc2kk1KcGN32MEt6Rcduc7AIBsCW4YoV8SggXBghH6mib3WFgu7_wQwLi_-26D3s3NWgUAKQ9LsNvDKnk2vzpg4yiYseA65oAUyVdl3aseaqkEKRKQFgZprVQncJ20MDLnhFEe-akQ8GrpF8BbvKZn6gQvv1Gf5EdBfX8eljS2seuEukEACOYsdsb7A2cm1YCkGH4Fp0Fu7nBcnuO-s_EM8wTb9aCmCyh7AblZfRF8BVzTNNPM_6Slj-FSDPiJy_MCfNDgGc8BnvRexZsLPsLDzUeK4XR0lWmdNmI9-crz7kefmixRqTdYL08KsjVEbaBnteg9R7axUPzDRriZzC5VuGvc0FO3Jvz4Iki9hifWQ_f2goVVsLeQlHxvuIQXSEl-eEQ2w3iPXOv7beZD_PN-n_yDn3nPCO4Ml--8M87DymXvkX552B_0-fr23RN72vZ1Xuk_whv0wrtow-ea5XsjRyC49292fvAsTw609ZB0N-f2sXyrUyPcx_UM99Fo3b4fbKyXZ4Gxf-OW4daIZcLlf_x5-eXXiFeUb-mWRaJKi22ZbOmmwKiripwlRV42W9amZcmaukTGi5rycstZilkkK0yQpkmKHpdhzOo2pzlLsC0ybDglWSIGJvtb9EhaO4mq2GzyMgqtasO0RlTiAmGTIPrhbSrPeamnkyVZ0kvr7HcvTro-jPn7-ZUf4PMhJS0o7UCPTg7yKng0mb56-ieQrpvquNEDwWMYVPPyMhr9TTSO4DEItQSP4SD_BQAA___jR72U">