[llvm] [IR] Specify that overflow is poison, not UB in {s,u}{mul,div}.fix (PR #141748)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Wed May 28 14:24:34 PDT 2025


================
@@ -19075,8 +19075,10 @@ If the result value cannot be precisely represented in the given scale, the
 value is rounded up or down to the closest representable value. The rounding
 direction is unspecified.
 
-It is undefined behavior if the result value does not fit within the range of
-the fixed point type, or if the second argument is zero.
+If the result value does not fit within the range of the fixed point type, the
+result is poison.
+
+It is undefined behavior if the second argument is zero.
----------------
efriedma-quic wrote:

The primary reason `INT_MIN / -1` is UB in LLVM IR is because of the way the x86 "idiv" instruction behaves: it generates a trap on on overflow.

Maybe the lowering for sdiv.fix could work around this, but currently it doesn't, so it does in fact trap.

https://github.com/llvm/llvm-project/pull/141748


More information about the llvm-commits mailing list