-
Notifications
You must be signed in to change notification settings - Fork 428
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
LICM does not detect defs from virtual method calls #7003
Comments
Here is the issue and MWE you wanted me to make. Ben said you'd be interested in this. |
I think I came across this bug before as well, it was when I reported that 'Dynamic Dispatch was causing undefined behavior' for my FIFO queue, and you said that dynamic dispatch was just exposing some race condition. Code used the exact same pattern here (code is snapshot of almost 2 months ago). I spent days trying to figure out what was wrong, at least now I know its a bug. |
For context on why this considered a "gating issue":
|
I think I have a good lead on the issue here. I'm going to be away for the next 2 weeks, but I think I can get a fix in for the release. @ben-albrecht could add a .future test for this bug and link to it in the issue description? |
Add test to show licm bug related to virtual methods. Code is from chapel-lang#7003
`astutil.cpp:isDefAndOrUse()` doesn't currently handle virtual methods, so we weren't detecting a def of a variable through a virtual method call. Workaround this limitation by checking for virtual methods defs in licm. Note that the correct solution here is to update isDefAndOrUse, but that led to regressions that I don't have time to look into yet. Closes chapel-lang#7003
Fix licm bug with dynamic dispatch [reviewed by @benharsh] `astutil.cpp:isDefAndOrUse()` doesn't currently handle virtual methods, so we weren't detecting a def of a variable through a virtual method call. Workaround this limitation by checking for virtual methods defs in licm. Note that the correct solution here is to update isDefAndOrUse, but that led to regressions that I don't have time to look into yet. Closes #7003
@ben-albrecht and/or @LouisJenkinsCS #7315 should resolve this. Can you confirm that this resolves the issue you were running into and if so remove the bug-note in Collection.chpl |
I'll make it a priority to get around to testing it myself (rerunning all tests without |
All tests succeed, I'll make a new PR soon. |
Cool! Thanks for checking |
I spoke too soon. I went back and made a few minor changes to the unit tests (refactored as originally it was written to 'step around' the whole LICM bug), and now I get this:
I'll make a PR soon, and @ mention you on it. |
Posting this here: Its link to my comment in case not notified |
Summary of Problem
Loop Invariant Code Motion (LICM) seems to cause some sort of 'undefined behavior' in that it causes some things to be compiled away entirely. Like how the tuple variable seems to be given undefined/uninitialized values. Furthermore, how the entire loop gets optimized away if we do not add that extra 'writeln' (of which is not needed with the
--no-loop-invariant-code-motion
flag).As well, this is another opportunity to bring another issue that @e-kayrakli had made in my place, #6542 , which can also be reproduced here by calling
fn()
without capturing it in the the tuples(a,b)
will produce a segfault (with and without--no-loop-invariant-code-motion
flag).The amount of time I've spent double, triple, and quadruple checking my data structure thinking that I corrupted my data structure or something was exhausting.
Steps to Reproduce
Source Code:
TIO (Online Compiler)
With
--no-loop-invariant-code-motion
TIO (Online Compiler)
Output:
Output (With '--no-loop-invariant-code-motion'):
The text was updated successfully, but these errors were encountered: