[Fixed]Dangerous optimization in simplify

for this case, ((a + ia) / ib + ic) -> (a + (ia + ib*ic)) / ib

when ic is negative, ic=-1, ib=2 and a + ia = 1
before optimization,
1/ 2 - 1 = -1
after optimization
(1 - 1 × 2) / 2 = 0
comes out different result, if hardware round up differently for 1/2 and -1/2

for our hardware, round up like, 1/2=0 -1/2=0

@tqchen if needed I can send a PR

1 Like

Sure, we can send a PR to disable this optimization. The main problem is that Halide used a different semantics of div and mod(which rounds down) for negative integers as well.

thanks, will PR soon