Skip to content

[TIR][Arith] Avoid assigning range of possible values to integers#11859

Merged
vinx13 merged 1 commit into
apache:mainfrom
Lunderberg:no_integer_bounds_of_integer
Jun 24, 2022
Merged

[TIR][Arith] Avoid assigning range of possible values to integers#11859
vinx13 merged 1 commit into
apache:mainfrom
Lunderberg:no_integer_bounds_of_integer

Conversation

@Lunderberg

Copy link
Copy Markdown
Contributor

Previously, in ConstIntBoundAnalyzer, entering a conditional such as if 2==0 could result in the expression 2 being treated as having a known value of zero within the body of the conditional. Evaluating the range of expressions using 2 in the body of the conditional could result in exceptions being thrown, such as evaluating expr / 2 while setting 2 to its maximum value of zero.

This issue was present for conditions with inequalities for some time, but was introduced for conditions with equalities in #11524. Both types are resolved in this PR.

Previously, in `ConstIntBoundAnalyzer`, entering a conditional such as
`if 2==0` could result in the expression `2` being treated as having a
known value of zero within the body of the conditional.  Evaluating
the range of expressions using `2` in the body of the conditional
could result in exceptions being thrown, such as evaluating `expr / 2`
while setting `2` to its maximum value of zero.

This issue was present for conditions with inequalities for some time,
but was introduced for conditions with equalities in
apache#11524.  Both types are resolved in
this PR.
@Lunderberg

Copy link
Copy Markdown
Contributor Author

@echuraev

@junrushao

Copy link
Copy Markdown
Member

Also CC: @vinx13

Comment on lines +663 to +667
// If the conditional is comparing two integers, do not assign a
// value to them.
if (x.Eval().as<IntImmNode>()) {
return {};
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this check be done first? If it's true, none of the "make bound" code above has any effect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would, except that the value of x isn't set until Match returns true. So it was a choice between copy/paste of the check for IntImmNode within each conditional or potentially throwing out the result of MakeBound. Since MakeBound is a rather short constructor, I preferred keeping the condition in one spot.

@vinx13 vinx13 merged commit ed638ef into apache:main Jun 24, 2022
zxybazh pushed a commit to zxybazh/tvm that referenced this pull request Jun 26, 2022
…ache#11859)

Previously, in `ConstIntBoundAnalyzer`, entering a conditional such as
`if 2==0` could result in the expression `2` being treated as having a
known value of zero within the body of the conditional.  Evaluating
the range of expressions using `2` in the body of the conditional
could result in exceptions being thrown, such as evaluating `expr / 2`
while setting `2` to its maximum value of zero.

This issue was present for conditions with inequalities for some time,
but was introduced for conditions with equalities in
apache#11524.  Both types are resolved in
this PR.
@Lunderberg Lunderberg deleted the no_integer_bounds_of_integer branch June 27, 2022 14:24
blackkker pushed a commit to blackkker/tvm that referenced this pull request Jul 7, 2022
…ache#11859)

Previously, in `ConstIntBoundAnalyzer`, entering a conditional such as
`if 2==0` could result in the expression `2` being treated as having a
known value of zero within the body of the conditional.  Evaluating
the range of expressions using `2` in the body of the conditional
could result in exceptions being thrown, such as evaluating `expr / 2`
while setting `2` to its maximum value of zero.

This issue was present for conditions with inequalities for some time,
but was introduced for conditions with equalities in
apache#11524.  Both types are resolved in
this PR.
mikeseven pushed a commit to mikeseven/tvm that referenced this pull request Sep 27, 2023
…ache#11859)

Previously, in `ConstIntBoundAnalyzer`, entering a conditional such as
`if 2==0` could result in the expression `2` being treated as having a
known value of zero within the body of the conditional.  Evaluating
the range of expressions using `2` in the body of the conditional
could result in exceptions being thrown, such as evaluating `expr / 2`
while setting `2` to its maximum value of zero.

This issue was present for conditions with inequalities for some time,
but was introduced for conditions with equalities in
apache#11524.  Both types are resolved in
this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants