iree-org / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.
http://iree.dev/
Apache License 2.0
2.86k stars 622 forks source link

[Util] Fix AssumeIntOp::inferResultRanges bug #19195

Closed JamesMBartlett closed 6 days ago

JamesMBartlett commented 1 week ago

I noticed that the util-optimize-int-arithmetic pass, sometimes was incorrectly optimizing away operations. I tracked the issue down to the fact that AssumeIntOp::inferResultRanges doesn't always call setResultRange. Looking at the docs for InferIntRangeInterface in LLVM, it suggests that setResultRange must be called for each result, and looking further it's clear that some of the arith op folders rely on the fact that the range is always set (eg. arith.select).

This PR updates AssumeIntOp::inferResultRanges to call setResultRange even when umin or umax are not set.

I added a test case that used to be optimized to an incorrect constant, and now is not optimized out.

JamesMBartlett commented 1 week ago

LGTM

Thanks. Could you re-approve the actions? I had return instead of util.return.