Introduction
You probably want to mention INT_MIN/-1 overflow here? ---- The alternative here is to refine the definition of “sdiv” in LangRef; other arithmetic operations LLVM IR don’t have undefined behavior, and the primary reason “sdiv” has undefined behavior is the unfortunate behavior of the x86 “IDIV” instruction. For example, we could add a “nooverflow” bit to “sdiv”, and say that divide-by-zero has undefined behavior if the “nooverflow” bit is present, and produces poison otherwise. -Eli
Adding Sander and Florian, as this will certainly apply to SVE.
cheers,
--renato
This seems like a good idea. It will also provide us with a well-defined way to speculate/hoist divisions. I presume that we’d want to have Clang (etc.) generate all divisions with this bit set, but we could clear the bit when vectorizing (or hoisting, if we wanted to do that). On x86, we’d need to lower the form without the nooverflow bit present using a test-and-branch sequence, but on other architectures, we could use the poison-generating form directly. -Hal