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

    <tr>
        <th>Summary</th>
        <td>
            Missed rewrite for comparisons against results of division
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Comparing `x / y` against `z` can be transformed to comparisons of `x / z` against `y`, which can be beneficial when `z` is a constant.

# Examples
Unsigned division, unsigned `<` ([godbolt](https://godbolt.org/z/d91v9Ph4P), [alive](https://alive2.llvm.org/ce/z/vZ5tkP))
```c
bool src(uint8_t x, uint8_t y, uint8_t z) {
    return x / y < z;
}

bool tgt(uint8_t x, uint8_t y, uint8_t z) {
    return (z == 0) ? false : y > x / z;
}
```

Unsigned division, unsigned `>` ([godbolt](https://godbolt.org/z/sGWKbaMr8), [alive](https://godbolt.org/z/sGWKbaMr8))
```c
bool src(uint8_t x, uint8_t y, uint8_t z) { 
    return x / y > z;
}

bool tgt(uint8_t x, uint8_t y, uint8_t z) {
    return (z == (uint8_t)-1) ? false : y <= x / (z + 1);
}
```

Unsigned division, unsigned `<=` ([godbolt](https://godbolt.org/z/6jzhqGsdW), [alive](https://alive2.llvm.org/ce/z/jEauYA))
```c
bool src(uint8_t x, uint8_t y, uint8_t z) {
    return x / y <= z;
}

bool tgt(uint8_t x, uint8_t y, uint8_t z) {
    return (z == (uint8_t)-1) ? true : y > x / (z + 1);
}
```

Unsigned division, unsigned `>=` ([godbolt](https://godbolt.org/z/h9493Pj5G), [alive](https://alive2.llvm.org/ce/z/Tp6cRX))
```c
bool src(uint8_t x, uint8_t y, uint8_t z) {
    return x / y >= z;
}

bool tgt(uint8_t x, uint8_t y, uint8_t z) {
    return (z == 0) ? true : y <= x / z;
}
```

Unsigned division, `==` ([godbolt](https://godbolt.org/z/685avqxhr), [alive](https://alive2.llvm.org/ce/z/7x4YV0))
```c
bool src(uint8_t x, uint8_t y, uint8_t z) { 
    return x / y == z;
}

bool tgt(uint8_t x, uint8_t y, uint8_t z) {
    if (z == 0) {
        return y > x;
    } else if (z == (uint8_t)-1) {
        return x == (uint8_t)-1 && y == 1;
    } else {
        return y > x / (z + 1) && y <= x / z;
    }
}
```

Unsigned division, `!=` ([godbolt](https://godbolt.org/z/adje8jPTW), [alive](https://alive2.llvm.org/ce/z/WcC4zM))
```c
bool src(uint8_t x, uint8_t y, uint8_t z) { 
    return x / y != z;
}

bool tgt(uint8_t x, uint8_t y, uint8_t z) {
    if (z == 0) {
        return y <= x;
    } else if (z == (uint8_t)-1) {
        return x != (uint8_t)-1 || y != 1;
    } else {
        return y <= x / (z + 1) || y > x / z;
    }
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzNV9ty2jAQ_Rr7RRPGyPcHPyRg8pDJDNNJm6QvHVkWWMTYRJIJ4eu7vhDc4DQZnNAy4rKS9uxK56ywojx-Dkb5ckUEz-ZIc4wN0vAEPcMvROaEZ1KVvdvSpiRDEUNKkEzOcrFkMVI5orW3zDOJ8tkeYvsKooTU8Ag9JZwmO6yIZWzGKScp9LPsJRSXiAAyuJJMDTRjrBnnzSc2Ubghy1XKZN3zPZN8nkEyMV9zyfOsjFLsOsuo5qjE1LCn2RfzPI7yVGn2GOxEqZXUTACdQGuGBrmYg7WFd-wP1_40saYa9ktU8CcpX7Mu72oAD9J0vWwQKGtg1j9t9VBj-M0qIKuq0dqO8jxFUlBALXimvF8KbaplNMZz2wBIH2nuRe2K4CWYKkSGGu4QLBgmmc0EzR23N7AKpeaqXyjw3kKcMTRkVJPMCZqRVDL4dV7lEKKdEA4z2S2_ndgHeAyP5FFe3l5F5Fp4H-DxPe_PZBD9hcLwlBTukWD22bCb0FE5s06w9sUXqJz6efyWEY6k2Flsk8dLGd_2K9VFSIr785OWarmr_55qJYrD0v0imsPjaU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