# Sema: enhance \`div\` instruction analysis · gitcafe/zig

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

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

Visibility: public

Requested revision: 1fc24e8d807a489254be46c9fcb951617a04f3b1

Requested commit: 1fc24e8d807a489254be46c9fcb951617a04f3b1

Commit: 1fc24e8d807a489254be46c9fcb951617a04f3b1

Tree: 48ffbbb3cc12c3234e1c242f146dd2c9ecb5eca7

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
Sema: enhance `div` instruction analysis

Concrete improvements:
 * Added safety for integer overflow (-MAX_INT/-1)
 * Omit division by zero safety check when RHS is comptime known to
   be non-zero.
 * Avoid emitting `_optimized` variants of AIR instructions for integers
   (this suffix is intended to be used for floats only).

Subjective changes: I extracted the div logic out from analyzeArithmetic
in order to reduce the amount of branches - not for performance reasons
but for code clarity. It is more lines of code however, and some logic
is duplicated.

```

## Parents

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

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