Skip to content
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

rustc_codegen_llvm: don't overalign loads of pair operands. #56329

Merged
merged 1 commit into from
Nov 29, 2018

Conversation

eddyb
Copy link
Member

@eddyb eddyb commented Nov 28, 2018

Counterpart to #56300, but for loads instead of stores.

@eddyb eddyb added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Nov 28, 2018
@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 28, 2018
@eddyb eddyb added beta-nominated Nominated for backporting to the compiler in the beta channel. and removed beta-accepted Accepted for backporting to the compiler in the beta channel. labels Nov 28, 2018
@eddyb
Copy link
Member Author

eddyb commented Nov 28, 2018

Why is accepted before nominated in the alphabet...

@nikomatsakis
Copy link
Contributor

@bors r+ p=10

@bors
Copy link
Contributor

bors commented Nov 28, 2018

📌 Commit 51cf4e9 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 28, 2018
@nikomatsakis nikomatsakis added beta-accepted Accepted for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2018
@nikomatsakis
Copy link
Contributor

cc @rust-lang/compiler

Marking as beta-accepted because small and tight time constraints.

@bors
Copy link
Contributor

bors commented Nov 29, 2018

⌛ Testing commit 51cf4e9 with merge a49316d...

bors added a commit that referenced this pull request Nov 29, 2018
rustc_codegen_llvm: don't overalign loads of pair operands.

Counterpart to #56300, but for loads instead of stores.
@bors
Copy link
Contributor

bors commented Nov 29, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing a49316d to master...

@bors bors merged commit 51cf4e9 into rust-lang:master Nov 29, 2018
@eddyb eddyb deleted the load-operand-overaligned branch November 29, 2018 07:04
@nikomatsakis nikomatsakis removed the beta-accepted Accepted for backporting to the compiler in the beta channel. label Nov 29, 2018
@nikomatsakis
Copy link
Contributor

Removing beta-accepted so we can discuss in today's @rust-lang/compiler meeting.

@nikic
Copy link
Contributor

nikic commented Nov 29, 2018

I was somewhat skeptical about whether the incorrect alignments could result in actual miscompilations, as usually LLVM cannot do a whole lot with alignments that are larger than the load/store size from a codegen perspective.

I've been able to come up with the following case, which segfaults prior to the alignment fixes:

#[repr(align(16))]
pub struct Foo<T> {
    bar: T,
    baz: T,
}

#[inline(never)]
pub fn test(x: Foo<(i64, i64)>) -> Foo<(i64, i64)> {
    let bar = x.bar;
    let baz = x.baz;
    Foo { bar: (bar.1, baz.0), baz: (0, 0) }
}

fn main() {
    test(Foo { bar: (0, 0), baz: (0, 0) });
}

The trick is to make sure the load of the first pair element is optimized away, while the load for the second pair element is coalesced with adjacent loads into a larger size. This results in codegen emitting movaps instead of movups instructions.

@eddyb
Copy link
Member Author

eddyb commented Nov 29, 2018

FWIW this bug already existed AFAICT, I don't know how we hadn't hit it before...

@nikic
Copy link
Contributor

nikic commented Nov 29, 2018

@eddyb Probably due to this code on stable:

let effective_field_align = self.align
This reduces the alignment based on the field alignment, so the alignment of the first pair element ends up being small enough to accomodate both.

@pnkfelix
Copy link
Member

discussed in T-compiler meeting. beta-accepting.

@pnkfelix pnkfelix added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Nov 29, 2018
@alexcrichton
Copy link
Member

@eddyb and/or @nikic, would y'all be able to help out in a backport to beta for this? It appears the patch to src/librustc_codegen_llvm/builder.rs doesn't cleanly apply to beta because the function being patched may not exist? I'm not sure if this affects the beta branch and/or where to apply the fix

@eddyb
Copy link
Member Author

eddyb commented Nov 29, 2018

It's PlaceRef::load in mir/place.rs.

@alexcrichton
Copy link
Member

Ok thanks! I think this is running into the same errors found on #56300 (comment), can you help out with those?

@alexcrichton
Copy link
Member

Ok I think I've figured it out with some help at #56352

@alexcrichton alexcrichton removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Nov 29, 2018
bors added a commit that referenced this pull request Nov 30, 2018
Rollup beta backports

* #56264
* #56300
* #56322
* #56329

Neither #56300 nor #56329 applied cleanly, but I think I've gotten it working with @nikic's [help](#56300 (comment)) (thanks!)

Closes #56311
Closes #56263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants