Skip to content

Store scalar pair bools as i8 in memory#51583

Merged
bors merged 2 commits into
rust-lang:masterfrom
cuviper:packed_pair-bool
Jul 10, 2018
Merged

Store scalar pair bools as i8 in memory#51583
bors merged 2 commits into
rust-lang:masterfrom
cuviper:packed_pair-bool

Conversation

@cuviper

@cuviper cuviper commented Jun 15, 2018

Copy link
Copy Markdown
Member

We represent bool as i1 in a ScalarPair, unlike other aggregates,
to optimize IR for checked operators and the like. With this patch, we
still do so when the pair is an immediate value, but we use the i8
memory type when the value is loaded or stored as an LLVM aggregate.

So (bool, bool) looks like an { i1, i1 } immediate, but { i8, i8 }
in memory. When a pair is a direct function argument, PassMode::Pair,
it is still passed using the immediate i1 type, but as a return value
it will use the i8 memory type. Also, bool-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.

Fixes #51516.
Closes #51566.

r? @eddyb
cc @nox

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 15, 2018
@eddyb

eddyb commented Jun 16, 2018

Copy link
Copy Markdown
Contributor

{ i1, i1 } immediate

Note that we keep the two components separate and outside a LLVM aggregate when immediate, so that type should not exist.

Comment thread src/librustc_codegen_llvm/mir/place.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just remove this check and the comment above it.

Comment thread src/librustc_codegen_llvm/type_of.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type {i1, i1} is never created, so maybe say "two i1s" instead?

Comment thread src/test/codegen/scalar-pair-bool.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is another unfortunate consequence, I forgot about return values. I wonder if they should be using the pair "passing mode" that arguments do, and create a LLVM aggregate type on the fly, using the immediate types for the pair components. That way we'd get {i1, i1} for returns, but everything else would see {i8, i8}.

Not sure it's worth the complexity though. When inlining, LLVM should collapse the zext followed by trunc, just like it gets rid of packing into a pair and unpacking it.

Comment thread src/test/codegen/scalar-pair-bool.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to see this with branches, since they only ever take i1.

@emilyalbini emilyalbini added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2018
@TimNN

TimNN commented Jul 3, 2018

Copy link
Copy Markdown
Contributor

Ping from triage, @cuviper: It looks like there are some comments on your PR, do you think you'll be able to address those?

@cuviper

cuviper commented Jul 3, 2018

Copy link
Copy Markdown
Member Author

Sorry I forgot about this. Yes, I'll update for those comments.

cuviper added 2 commits July 5, 2018 09:59
We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like.  With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.

So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory.  When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type.  Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.
@cuviper cuviper force-pushed the packed_pair-bool branch from 08cfb58 to 557736b Compare July 5, 2018 21:23
@cuviper

cuviper commented Jul 5, 2018

Copy link
Copy Markdown
Member Author

@eddyb - I've addressed your review comments, except for what you said about return values. Would you like a FIXME comment and/or an issue filed about that?

@cuviper cuviper added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 5, 2018
@emilyalbini

Copy link
Copy Markdown
Member

Ping from triage @eddyb! This PR needs your review.

@eddyb

eddyb commented Jul 9, 2018

Copy link
Copy Markdown
Contributor

@cuviper r=me with maybe an issue filed about that, but I wouldn't worry too much. Thanks!

@cuviper

cuviper commented Jul 10, 2018

Copy link
Copy Markdown
Member Author

OK, filed #52198. Not sure if I have bors access, but let's try:

@bors r=eddyb

@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

@cuviper: 🔑 Insufficient privileges: Not in reviewers

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r=eddyb delegate+

@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

✌️ @cuviper can now approve this pull request

@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 557736b has been approved by eddyb

@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 Jul 10, 2018
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+ p=5 (rollup fairness)

@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

💡 This pull request was already approved, no need to approve it again.

@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 557736b has been approved by Mark-Simulacrum

@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 557736b with merge b3e7d70...

bors added a commit that referenced this pull request Jul 10, 2018
Store scalar pair bools as i8 in memory

We represent `bool` as `i1` in a `ScalarPair`, unlike other aggregates,
to optimize IR for checked operators and the like.  With this patch, we
still do so when the pair is an immediate value, but we use the `i8`
memory type when the value is loaded or stored as an LLVM aggregate.

So `(bool, bool)` looks like an `{ i1, i1 }` immediate, but `{ i8, i8 }`
in memory.  When a pair is a direct function argument, `PassMode::Pair`,
it is still passed using the immediate `i1` type, but as a return value
it will use the `i8` memory type.  Also, `bool`-like` enum tags will now
use scalar pairs when possible, where they were previously excluded due
to optimization issues.

Fixes #51516.
Closes #51566.

r? @eddyb
cc @nox
@bors

bors commented Jul 10, 2018

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: Mark-Simulacrum
Pushing b3e7d70 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants