Commit b18cbef5 authored by Sanjoy Das's avatar Sanjoy Das Committed by TensorFlower Gardener
Browse files

[XLA] Define integer division overflow

This CL implements the following semantics for integer division overflow in the
HLO evaluator:

  X / 0 == -1
  X % 0 == X
  INT_SMIN / -1 = INT_SMIN
  INT_SMIN % -1 = 0

With these semantics we still preserve the properties:

 - (A/B)*B + A%B == A
 - 0/X == 0

but we no longer have X/X == 1.

This CL is mainly intended to start a discussion.  Once we're sure we want this
I'll implement the same semantics on CPU and GPU.

We can probably make our implementation faster at the cost of more complicated
semantics.  E.g. we could define X / 0 to be X, and then "A /u B" could lower to
"A /u Max(B, 1)".  But my current understanding is that optimizing integer
division is not super important.

I plan to spec this as "produces a well founded implementation-defined value".
So while user code won't be able to rely on the result being any particular
value (and we'll have some leeway in the future to change the result and/or make
it backend-dependent), it won't be something like LLVM's undef either.

PiperOrigin-RevId: 209704042
parent ba9501e0
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment