cmd/compile: teach prove about incrementing, len, and overflow #36346
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
I have some hot code that looks approximately like this:
The generated code has a bounds check on every iteration. This is because
i
might be negative. We can rule that out up front:This could should be able to go without a bounds check.
i
cannot be negative at the beginning. In order to become negative, it must overflow. However, it cannot overflow: It is being incremented, so it must reachlen(a)
before overflowing, in which case we exit the loop before evaluatinga[i]
.(I actually know a priori in my code that
i
is not negative; I'd be tempted to use #30582 here. I could also switch toi
being a uint, which does remove the bounds check, but it makes other things in the real code a bit awkward.)I don't know how hard it is to teach prove about this case.
cc @zdjones @rasky @randall77
The text was updated successfully, but these errors were encountered: