[Bugfix] Fixed div by zero core dump. Fixed rounding intrinsics on int crash #5026
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Div by zero crash
I found and fixed 2 instances where a divide by zero could be evaluated in
const_fold
causing a Python core dump. For exampletir.const(2) % 0
.Rounding intrinsics
When I tried to use llvm intrinsics on integers I found all of them but
popcount
result in an error analogous to:To fix this for
trunc,floor,ceil,nearbyint,round
it is sufficient to return the int expr and avoid the call altogether.Other intrinsics
I was looking at fixing the above crash for other intrinsics (
sin,cos,atan,tan,tanh,sigmoid,log,erf,exp,sqrt,rsqrt
) by restricting their usage to floating point numbers. However applyingexp
andsqrt
tobool
type seems to be relied on in this test:https://github.com/apache/incubator-tvm/blob/master/topi/tests/python/test_topi_reduce.py#L51
Evaluating this line for a bool is equivalent to a tautology which makes me suspect it is not intended. If the reviewer(s) agree that these intrinsics should not be applied to ints, then I can add a front-end checks on the instrinsics to this PR and fix the tests.
I would appreciate a review!
@tqchen