-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Duplicated loop body #52586
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
The nested loop doesn't know that |
I guess you mean "CodeGen doesn't know". From this I conclude this comes from the fact CodeGen generates the code based only on static analysis. But at runtime we can check "j = i is less arr.Length" before the cycle. |
#8558 Covers this somewhat: loop cloning kicks in for the inner loop, eliminates the "fast path" bounds check. But later on, assertion prop gets rid of the array null check it inserted, and range prop gets rid of the "slow path" bounds check, so the loops are the same. Assertion prop doesn't get rid of the extra "i < 0" check that gets inserted (which it should). If that was eliminated, we're left with #5820. |
Follow pattern results in a duplicated loop body:
See https://sharplab.io/#v2:EYLgtghglgdgNAFxBAzmAPgAQEwEYCwAUJgMwAEOZAwmQN5FmMXmYAsZAsgBSwJkwBKOgyaiAbhABOZKdIC8/AKYB3MrwDaMALoBuEaMYAzAPbSeMPlDIKADDrVkAPDMmSAdABlFMAOYIAFvZQANTBAvoG9IQGMWQmZrxkAFbWavYpzrKe3n6ByaHh0bGiUcXFAPTlEtIQqbLqULoRZUyVmLgAnFwQAnpFLeJSZMB1rupJTf0DjO1dwL3NsQC+i4wrU+tLQA
category:cq
theme:loop-opt
skill-level:expert
cost:medium
impact:small
The text was updated successfully, but these errors were encountered: