Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upWorkaround LLVM optimizer bug by not marking &mut pointers as noalias #31545
Conversation
rust-highfive
assigned
jroesch
Feb 10, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rust-highfive
Feb 10, 2016
Collaborator
r? @jroesch
(rust_highfive has picked a reviewer for you, use r? to override)
|
r? @jroesch (rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
reviewed
Feb 10, 2016
| @@ -265,7 +265,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx | ||
| // on memory dependencies rather than pointer equality | ||
| let interior_unsafe = mt.ty.type_contents(ccx.tcx()).interior_unsafe(); | ||
| if mt.mutbl == hir::MutMutable || !interior_unsafe { | ||
| if mt.mutbl != hir::MutMutable && !interior_unsafe { |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
alexcrichton
Feb 10, 2016
Member
I may not quite be understanding what's going on here, but doesn't this mean that &usize will have the noalias attribute applied?
alexcrichton
Feb 10, 2016
Member
I may not quite be understanding what's going on here, but doesn't this mean that &usize will have the noalias attribute applied?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
dotdash
Feb 10, 2016
Contributor
Yes, and that's intentional. The change is supposed to only affect &mut references (and '&' ones with unsafe interiors), because those are the ones that could have stores that would expose this bug.
dotdash
Feb 10, 2016
Contributor
Yes, and that's intentional. The change is supposed to only affect &mut references (and '&' ones with unsafe interiors), because those are the ones that could have stores that would expose this bug.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
dotdash
Feb 10, 2016
Contributor
Oh, also note that WRT &usize this is not a change, those pointers got the noalias attribute before as well (the || got changed into a &&). As the comment above this change says, noalias is about memory dependencies rather than plain pointer equality.
dotdash
Feb 10, 2016
Contributor
Oh, also note that WRT &usize this is not a change, those pointers got the noalias attribute before as well (the || got changed into a &&). As the comment above this change says, noalias is about memory dependencies rather than plain pointer equality.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
alexcrichton
Feb 10, 2016
Member
Looks like the travis failure is legit in that a codegen test needs to be udpated.
|
Looks like the travis failure is legit in that a codegen test needs to be udpated. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
dotdash
Feb 10, 2016
Contributor
Updated the codegen test, completely forgot about those and only ran the new test before opening the PR
|
Updated the codegen test, completely forgot about those and only ran the new test before opening the PR |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
added a commit
that referenced
this pull request
Feb 11, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bors
Feb 12, 2016
Contributor
bors
merged commit a17fb64
into
rust-lang:master
Feb 12, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ticki
Feb 15, 2016
Contributor
This seems like a horrible performance loss. Can you post the benchmarks?
|
This seems like a horrible performance loss. Can you post the benchmarks? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
ticki
Feb 15, 2016
Contributor
Well, I haven't benchmarked this change, but in my experience, disabling noalias in GCC gave bad performance.
|
Well, I haven't benchmarked this change, but in my experience, disabling noalias in GCC gave bad performance. |
bstrie
referenced this pull request
Feb 15, 2016
Closed
Mark &mut pointers as noalias once LLVM no longer miscompiles them #31681
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
dotdash
Feb 15, 2016
Contributor
@ticki what exactly do you mean by "disabling noalias in GCC"? Making it ignore the restrict keyword? Because when comparing to C, that's basically the only change we made here.
|
@ticki what exactly do you mean by "disabling noalias in GCC"? Making it ignore the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
dotdash
Feb 15, 2016
Contributor
That option disables TBAA, which rust does not use at all. The scope of
this change is smaller than that of that option.
-fno-strict-aliasing, that is.
—
Reply to this email directly or view it on GitHub
#31545 (comment).
|
That option disables TBAA, which rust does not use at all. The scope of -fno-strict-aliasing, that is. — |
dotdash commentedFeb 10, 2016
LLVM's memory dependence analysis doesn't properly account for calls
that could unwind and thus effectively act as a branching point. This
can lead to stores that are only visible when the call unwinds being
removed, possibly leading to calls to drop() functions with b0rked
memory contents.
As there is no fix for this in LLVM yet and we want to keep
compatibility to current LLVM versions anyways, we have to workaround
this bug by omitting the noalias attribute on &mut function arguments.
Benchmarks suggest that the performance loss by this change is very
small.
Thanks to @RalfJung for pushing me towards not removing too many
noalias annotations and @alexcrichton for helping out with the test for
this bug.
Fixes #29485