-
Notifications
You must be signed in to change notification settings - Fork 12.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
Combining inline and target_feature attributes with recursive functions causing incorrect results. #53117
Comments
@alexcrichton could this be related to llvm bug here: https://bugs.llvm.org/show_bug.cgi?id=37358 |
Glancing at the IR, yeah, it looks like that bug unfortunately |
any tricks one can use to work around that, until LLVM fixes it? |
If |
Yeah for my use case I could just copypasta whenever I have a recursive simd function, which isn't often! |
In my experience so far LLVM bugs tend to fall in one of two buckets: fixed within a week or never fixed. Unfortunately that bug's been open for more than a week :( In that sense my historical experience is that it'll be awhile before the bug is fixed, but we haven't done much work on our part to try to bug those who may know how to fix it (or know who may be able to fix it, and we could always more aggressively do that!) |
I'll see if I can get an account on the bugzilla and chime in. |
Previous comments, now deleted, were using nightly 1 day too soon! #55073 fixes this issue, thanks @alexcrichton |
reopening as the workaround was reverted. LLVM fix seems to be in the works so I will test when that lands. I think the fix in 55073 was causing some bugs anyway so glad to see LLVM fix is near. |
@jackmott did you ever get around to testing this again? :) |
@steveklabnik yes, this is fixed now! |
add_stuff
is a function with AVX2 simd intrinsics, set to inline always.add_stuff_helper
is a function with the target_feature set to enable AVX2 instructions.If you run this in a release build, you will get an incorrect result, the return values from the recursive function do not add up. I believe this is because there is code being generated around the recursion that is not getting the avx2 target_feature applied.
If you make add_stuff not recursive, this all works fine.
The code below obviously does not make sense to use by itself, it works for instance if you put the target_feature on the add_stuff function directly, but this technique is useful for doing some nice SIMD metaprogramming with traits, and this bug makes that not work.
Is this a bug that can be fixed? Or an innate limitation of the inlining, target_features, and recursion? Is there a workaround?
Environment:
This happens with rustc 1.27 stable through 1.31.0 nightly (at least)
All tested on linux, on a cpu that supports AVX2 instructions. Intel core i7 6700
The text was updated successfully, but these errors were encountered: