C++: special case GVN for std::vector::size#9812
C++: special case GVN for std::vector::size#9812rdmarsh2 wants to merge 1 commit intogithub:mainfrom
std::vector::size#9812Conversation
| int a = v.size(); | ||
| int b = v.size(); | ||
| v.set(10); | ||
| int c = v.size(); |
There was a problem hiding this comment.
I'm not exactly sure how it works, but I'm impressed we match the result of size() on line 178 to line 179, but not 181.
How easy would it be to fool it, by doing something subtler that changes the number of elements in v?
There was a problem hiding this comment.
This currently relies on the fact that size is declared as a const member function, so we don't generate a call side-effect that writes to v. We could potentially do a deeper analysis to discover that functions don't mutate their arguments, but I'm not sure it's necessary. Right now we'd be sound if something subtler changes the result, but if size weren't declared as const we'd have those side-effects and would value-number the call on 179 differently.
There was a problem hiding this comment.
Sounds like the right call to me.
This PR adds value numbering for the
std::vector::sizefunction, based on the value of thethispointer and object. This fixes some false positives in an experimental range analysis query.Opened as draft for discussion - I intend to generalize this with either a model or some heuristics before merging.