# llvm: convert \`@divFloor\` and \`@mod\` to forms llvm will recognize · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/5cfcb015033864c769235726975ab9919c217ef9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 5cfcb015033864c769235726975ab9919c217ef9

Requested commit: 5cfcb015033864c769235726975ab9919c217ef9

Commit: 5cfcb015033864c769235726975ab9919c217ef9

Tree: 10f027ac4086056f6f422cdd4f7e52e0d2d64af3

Author: Jacob Young

Committer: Andrew Kelley

## Message

```
llvm: convert `@divFloor` and `@mod` to forms llvm will recognize

On x86_64, the `@divFloor` change is a strict improvement, and the
`@mod` change adds one zero latency instruction.  In return, once we
upgrade to LLVM 20, when the optimizer discovers one of these operations
has a power-of-two constant rhs, it will be able to optimize the entire
operation into an `ashr` or `and`, respectively.

                      #I   CPL   CPT
    old `@divFloor` |  8 | 15 | .143 |
    new `@divFloor` |  7 | 15 | .148 |
    old `@mod`      |  9 | 17 | .134 | (rip llvm
    new `@mod`      | 10 | 17 | .138 |  scheduler)

```

## Parents

- [b074fb7ddaefaa6ed9c5235d22b2f7378e3b80e8](https://git.cafe/gitcafe/zig/commit/b074fb7ddaefaa6ed9c5235d22b2f7378e3b80e8?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/5cfcb015033864c769235726975ab9919c217ef9?format=markdown)
