Is software-checked integer division actually necessary?

Exceptions are totally a valid thing for LLVM to do with an undefined behavior. In this case, I think the Intel divl operation itself throws the exception and Julia’s signal handler catches it:

But other architectures — like my Apple M1 — may not have such signals or they may not be as efficient.

It’s also worth noting that if LLVM happens to prove that you are dividing by zero, then it can aggressively exploit the fact that you’re in UB land and do all sorts of other strange things.

6 Likes