-
Notifications
You must be signed in to change notification settings - Fork 29
powi only: don't override arm calling convention #26
Conversation
Thanks! With this strategy, though, I feel like we still may have not settled this ABI issue. Clearly the compiler and compiler-rt are disagreeing about the ABI of these intrinsics, but we should figure out how to get them to agree on all of them because in theory clang does something here that's correct which we should be mirroring. So previously the compiler and compiler-rt disagreed about the ABI of powi, so we assumed they disagreed about all of them. It looks like some assembly at least is the aapcs ABI which the compiler now would not be expecting. In summary this PR is assuming that powi is the only intrinsic that we disagreed on ABI with, right? Do we have any information leading us to that conclusion? Or are we basically just in "fix regressions as we see them" mode? (just trying to get a handle on the current state of affairs) |
This is the >>"fix regressions as we see them" mode<< right now. As I see the situation, this affects beta and is about to hit stable. A complete fix would probably be more difficult and involve patching llvm, which would take a much longer time. Although it would of course be interesting to know, what the exceptional situation is: "Everything is HF except [...]" or "everything is SF except [...]". An alternative fix would probably be to revert the previous patch and just don't link agains |
Hm so the timeliness here may not be too much of a factor. Stable builds are already branched and underway, so we're not going to fix that with the 1.13.0 release (I believe). In that sense I wouldn't mind taking some more time to investigate what's going on here and dig into the disagreement. |
Sure, that's fine with me, although the new regression (failure to parse floats properly) seems much worse to me than the old regression (failure of |
cc @brson, thoughts about the regression status? summary:
We could either backport this PR and make a new stable build, or punt and fix this problem in beta. I'm tempted to fix this problem in beta (a non-tier-1 platform is not worth the amount of trouble to delay everything, just a very good thing to fix) |
I think we have to accept rust-lang/rust#37630 as a known regression for 1.13. There's a lot of risk making any changes now, and as you say, it's a tier 2 platform. |
I suspect all of the rust-declared float intrinsics will have this problem, not just Even though it's Tier 2, I'll be blocked from shipping this to Fedora until there's a fix. I've been trying to enable all archs for the eventual Firefox oxidation, so Tier 1 x86-only is too restrictive. But, if we do get a proper fix for this in the next beta, I can definitely backport that for our 1.13 build. |
On a nightly before my original fix ( I tested (for
This was using cross-compiling + qemu on Ubuntu. |
Interesting! Maybe the ABI gets lost/corrupted when inlining that wrapper? And how about the same test on a nightly that does have your fix -- then are the direct and wrapper versions both ok? I'd still feel more comfortable if we knew why the other calls are ok -- are they perhaps inlining direct instructions instead of making a real function call? |
There is not yet a nightly with my fix, however I did test on the latest beta: On the latest beta things worked fine for the above mentioned functions -- both with and without a wrapper function. I also added tests for That failed for |
@TimNN the functions you mentioned here all come from libc, right? not compiler-rt? (except for powi). In that sense I wouldn't expect a calling convention mismatch as we're calling those functions ourselves and LLVM isn't lowering intrinsics. |
@alexcrichton: I used the intrinsics from |
Wow good point. I don't really know what LLVM is doing with intrinsics. Surely there's someone from LLVM who either knows what's up here or could help us... |
One thing that I've been thinking about is that the now failing function ( This generates ir like this: The This was tested on beta, test code, ir and asm. |
@TimNN I'm looking disassembly of your test's With optimized code, they all disappear, whether wrapped or direct, so I guess LLVM is const-folding those intrinsics entirely away. |
@cuviper: Yeah, I just noticed the powi behaviour as well (for the smaller test from my previous comment). This could probably be fixed by using some blackboxes in the old test case as well. |
I added blackbox calls to the old test as well and now |
Note that the |
@TimNN so I think the next step here is to answer the question of what LLVM expects each ABI to be and why. LLVM seems to be clearly expecting not aapcs for powi, but it does aapcs for casts. It seems to not be clear why, and could perhaps indicate some deeper problems? Would you be up for investigating that? (I also can do so) |
@alexcrichton: I already looked a bit at llvm, but I find the llvm source to be... not easily approachable. I'll try to look some more, but don't know how much time to do so I will have in the near future. An interesting place to look at seems to be Edit: more specifically, these lines. |
Ok, I've done a bit of investigation, and here's what I've come up with. Following @TimNN's lead the relevant set of declarations seems fairly small and targeted. Furthermore, it basically seems to follow the pattern that anything with the Next up, it turns out that a lot of intrinsics in compiler-rt have aliases defined for them through the Finally, if we take a look at all intrinsics that are interested in floats, ignore all those with aliases, and ignore all those related to 128-bit floats, we're only left with two we're interested in: So to sum that up:
tl;dr; @TimNN this patch I now believe to be correct. Odd though it may be! |
This update of compiler-rt includes rust-lang/compiler-rt#26 which provides a targeted fix to the powisf2 intrinsics to keep rust-lang#37559 fixed but also address the new issue of rust-lang#37630. I've also [written up my thoughts][1] on why it appears that this is the correct fix for now (hoepfully at least). Closes rust-lang#37630 [1]: rust-lang/compiler-rt#26 (comment)
std: Update compiler-rt for more ABI fixes This update of compiler-rt includes rust-lang/compiler-rt#26 which provides a targeted fix to the powisf2 intrinsics to keep #37559 fixed but also address the new issue of #37630. I've also [written up my thoughts][1] on why it appears that this is the correct fix for now (hoepfully at least). Closes #37630 [1]: rust-lang/compiler-rt#26 (comment)
@alexcrichton Yes this looks correct for now, but note that upstream LLVM now uses AAPCS for all arm intrinsics llvm-mirror/llvm@c4c2318 Although that seems to conflict with what GCC does https://gcc.gnu.org/ml/gcc/2016-09/msg00162.html where they use AAPCS for all |
Note the linked bug report: https://llvm.org/bugs/show_bug.cgi?id=30543. |
Ok, sounds like we should perhaps go back to AAPCS everywhere when updating to LLVM 4.0? Seems like something good to watch out for! |
That will have to be conditional, so long as we support pre-4.0 external LLVM. |
Or maybe powi should be a priority for the project to rewrite builtins in Rust. It's a small pure-C implementation -- should be easy to translate. |
@cuviper: The |
Ah, great! Hopefully that integration can beat LLVM 4.0's release, and we won't have to worry about it. |
This update of compiler-rt includes rust-lang/compiler-rt#26 which provides a targeted fix to the powisf2 intrinsics to keep rust-lang#37559 fixed but also address the new issue of rust-lang#37630. I've also [written up my thoughts][1] on why it appears that this is the correct fix for now (hoepfully at least). Closes rust-lang#37630 [1]: rust-lang/compiler-rt#26 (comment)
powi only: don't override arm calling convention
powi only: don't override arm calling convention
This should be a short term fix for rust-lang/rust#37630, while not regressing rust-lang/rust#37559.
cc @alexcrichton, @japaric, #25