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

Add a MIR pass to lower 128-bit operators to lang item calls #46093

Merged
merged 4 commits into from
Nov 24, 2017

Conversation

scottmcm
Copy link
Member

Runs only with -Z lower_128bit_ops since it's not hooked into targets yet.

This isn't really useful on its own, but the declarations for the lang items need to be in the compiler before compiler-builtins can be updated to define them, so this is part 1 of at least 3.

cc #45676 @est31 @nagisa

Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.
@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 19, 2017
// END RUST SOURCE

// START rustc.test_signed.Lower128Bit.after.mir
// _2 = const i128_addo(_1, const 1i128) -> bb10;
Copy link
Member

Choose a reason for hiding this comment

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

This test should include the statements dealing with the tuple projections (i.e. the branch on _2.1 and the _1 = _2.0).

let ty = lhs.ty(local_decls, tcx);
if let Some(is_signed) = sign_of_128bit(&ty) {
if let Some(item) = item_for_op(bin_op, is_signed) {
return Some(tcx.require_lang_item(item))
Copy link
Member

Choose a reason for hiding this comment

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

Since lang-items aren’t yet type-checked, could you add an assertion of some sort that checks whether the function really has the expected type?

#9307 is a long standing issue regarding that, and I would rather have an assertion in an easy to track location rather than right before trans.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, the next update generates an error like

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `[i128, i128, (i128, u32)]`,
 right: `[i128, i128, (i128, bool)]`: lang item _ZN23lower_128bit_debug_test9i128_addo', src\librustc_mir\transform\lower_128bit.rs:115:4

@nagisa
Copy link
Member

nagisa commented Nov 19, 2017

This looks okay to me, although yet again I’m slightly disappointed the Patch is not yet reusable in the other passes. It would make the manual fiddling with the MIR as done in this pass unnecessary.

I feel that -Z flag is a good idea (how else would one test this feature on targets that don’t lower automatically?).

r? @nagisa

@nagisa nagisa 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 Nov 19, 2017
As part of doing so, add more lang items instead of passing u128 to the i128 ones where it doesn't matter in twos-complement.
* The overflow-checking shift items need to take a full 128-bit type, since they need to be able to detect idiocy like `1i128 << (1u128 << 127)`
* The unchecked ones just take u32, like the `*_sh?` methods in core
* Because shift-by-anything is allowed, cast into a new local for every shift
Copy link
Member

@nagisa nagisa left a comment

Choose a reason for hiding this comment

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

This looks great to me. Can’t wait for the 2nd part!

(BinOp::Sub, false) => (LangItem::U128SuboFnLangItem, RhsKind::Unchanged),
(BinOp::Mul, true) => (LangItem::I128MuloFnLangItem, RhsKind::Unchanged),
(BinOp::Mul, false) => (LangItem::U128MuloFnLangItem, RhsKind::Unchanged),
(BinOp::Shl, true) => (LangItem::I128ShloFnLangItem, RhsKind::ForceU128),
Copy link
Member

Choose a reason for hiding this comment

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

Why specifically u128 for overflowing shifts? Is there an already-existing implementation that takes u128 as a shift count (I couldn’t find it in compiler-builtins)?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's unfortunately necessary to preserve the current behaviour of

1i128 << (1u128 << 127)

https://play.rust-lang.org/?gist=78f8381aac3ef89febcb48e56194e948&version=nightly

Any smaller type and the fact the shift is out of range would be lost.

@nagisa
Copy link
Member

nagisa commented Nov 21, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Nov 21, 2017

📌 Commit 42208c1 has been approved by nagisa

@kennytm kennytm 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 21, 2017
@bors
Copy link
Contributor

bors commented Nov 24, 2017

⌛ Testing commit 42208c1 with merge 5f44c65...

bors added a commit that referenced this pull request Nov 24, 2017
Add a MIR pass to lower 128-bit operators to lang item calls

Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.

This isn't really useful on its own, but the declarations for the lang items need to be in the compiler before compiler-builtins can be updated to define them, so this is part 1 of at least 3.

cc #45676 @est31 @nagisa
@bors
Copy link
Contributor

bors commented Nov 24, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nagisa
Pushing 5f44c65 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.

4 participants