Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix horrifying bug in lossless_cast of a subtract #8155

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

abadams
Copy link
Member

@abadams abadams commented Mar 14, 2024

This is one thing breaking the SVE2 pr.

Copy link
Member

@vksnk vksnk left a comment

Choose a reason for hiding this comment

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

Oof.

Copy link
Contributor

@steven-johnson steven-johnson left a comment

Choose a reason for hiding this comment

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

owww

@zvookin
Copy link
Member

zvookin commented Mar 14, 2024

Please sir, may I have a test?

@mcourteaux
Copy link
Contributor

Hahahaha, I'm giggling for minutes now... 😆

@steven-johnson
Copy link
Contributor

Is this a recent injection? If not, might want to backport to 17...

@steven-johnson steven-johnson added the backport me This change should be backported to release versions label Mar 15, 2024
@mcourteaux
Copy link
Contributor

Is this a recent injection? If not, might want to backport to 17...

No, 4 years ago:
394536f

@abadams
Copy link
Member Author

abadams commented Mar 15, 2024

I added a fuzz test, and there are more bugs :(

I'm pretty ready to state that all new features or algorithms must come with a fuzz tester.

@zvookin
Copy link
Member

zvookin commented Mar 15, 2024

This is why people measure test coverage. It's kinda annoying, but probably a thing to consider.

TODO:

- Dedup the constant integer code with the same code in the simplifier.
- Move constant interval arithmetic operations out of the class.
- Make the ConstantInterval part of the return type of lossless_cast
(and turn it into an inner helper) so that it isn't constantly
recomputed.
@steven-johnson
Copy link
Contributor

where do we stand on this -- do we need to do more work (tests, etc) before landing?

@abadams
Copy link
Member Author

abadams commented Mar 18, 2024

Still working on it. I couldn't figure out how to fix the remaining bugs using top-down reasoning about the types like what was there already, so I rewrote it to use bottom-up constant-integer bounds analysis, using code lifted out of the simplifier. It's working but there are inefficiencies to fix and some code deduplication to do.

@abadams
Copy link
Member Author

abadams commented Apr 2, 2024

lossless_negate has a similar bug. The mul visitor just tries to negate each arg, but if you have e.g. an int8 type, and the product is exactly -128 (e.g. -64 * 2), then a lossless negate just returns -128 again, which hasn't negated anything.

abadams added a commit that referenced this pull request Apr 3, 2024
Also explicit ignore lossless_cast bugs that will be fixed in #8155
abadams added a commit that referenced this pull request Apr 25, 2024
* Make ConstantInterval more of a first-class thing

and use it in Monotonic.cpp

* Restore bound_correlated_differences calls

* Elaborate on TODO

* Handle some TODOs

Also explicit ignore lossless_cast bugs that will be fixed in #8155

* Fix constant interval mod, clean up constant interval saturating cast

* Improve comment

* Avoid unsigned overflow

* Fix the most obvious bug in lossless_cast, to make the fuzzer pass more

* Skip over pipelines that fail the lossless_cast check

* Drop iteration count on lossless_cast test

* Add test to CMakeLists.txt

* Avoid UB in constant_interval test (signed integer overflow of the scalars)

* Restore accidentally-deleted line from CMakeLists.txt

* Print on success

* Handle Lets in constant_integer_bounds

Also, plumb the cache through the recursive calls

* Delete duplicate operator<<

* Just always cast the bounds back to the range of the op type

* Address review comments

* Redo operator<< for ConstantIntervals

* Improve comment; disable buggy code for now
@steven-johnson
Copy link
Contributor

Status Update? I know this had a lot of other stuff to fix first, just not sure where this stands.

@abadams
Copy link
Member Author

abadams commented Apr 30, 2024

The next PR is going to be reworking the simplifier to use the recently-merged ConstantInterval (pulling that out of this PR), and then after that's in this PR will be updated and hopefully made much smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport me This change should be backported to release versions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants