profile
viewpoint
Simon Vandel Sillesen simonvandel Copenhagen, Denmark

Pull request review commentrust-lang/rust

MIR-OPT: Less conservative `EarlyOtherwiseBranch`

 impl<'a, 'tcx> Helper<'a, 'tcx> {         if is_switch(terminator) {             let this_bb_discr_info = self.find_switch_discriminant_info(bb, terminator)?; -            // the types of the two adts matched on have to be equalfor this optimization to apply-            if discr_info.type_adt_matched_on != this_bb_discr_info.type_adt_matched_on {-                trace!(-                    "NO: types do not match. LHS: {:?}, RHS: {:?}",-                    discr_info.type_adt_matched_on,-                    this_bb_discr_info.type_adt_matched_on-                );+            // The layouts of the two ADTs have to be equal for this optimization to apply

I'm a bit unsure what part of Layout (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/abi/struct.Layout.html) actually needs to match between the two types for us to say that this optimization is valid.

simonvandel

comment created time in 11 hours

PullRequestReviewEvent

Pull request review commentrust-lang/rust

MIR pass to remove unneeded drops on types not needing drop

+//! This pass replaces a drop of a type that does not need dropping, with a goto++use crate::transform::{MirPass, MirSource};+use rustc_hir::def_id::LocalDefId;+use rustc_middle::mir::visit::Visitor;+use rustc_middle::mir::*;+use rustc_middle::ty::TyCtxt;++use super::simplify::simplify_cfg;++pub struct RemoveUnneededDrops;++impl<'tcx> MirPass<'tcx> for RemoveUnneededDrops {+    fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {+        trace!("Running RemoveUnneededDrops on {:?}", source);+        let mut opt_finder = RemoveUnneededDropsOptimizationFinder {+            tcx,+            body,+            optimizations: vec![],+            def_id: source.def_id().expect_local(),+        };+        opt_finder.visit_body(body);+        let should_simplify = !opt_finder.optimizations.is_empty();+        for (loc, target) in opt_finder.optimizations {+            let terminator = body.basic_blocks_mut()[loc.block].terminator_mut();+            debug!("SUCCESS: replacing `drop` with goto({:?})", target);+            terminator.kind = TerminatorKind::Goto { target };+        }++        // if we applied optimizations, we potentially have some cfg to cleanup to+        // make it easier for further passes+        if should_simplify {+            simplify_cfg(body);+        }+    }+}++impl<'a, 'tcx> Visitor<'tcx> for RemoveUnneededDropsOptimizationFinder<'a, 'tcx> {+    fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {+        match terminator.kind {+            TerminatorKind::Drop { place, target, .. }+            | TerminatorKind::DropAndReplace { place, target, .. } => {

Hi @tmiasko, thanks! See PR #77165

simonvandel

comment created time in 3 days

PullRequestReviewEvent

PR opened rust-lang/rust

Followup to #76673

Resolves https://github.com/rust-lang/rust/pull/76673#discussion_r494426303 r? @tmiasko

+3 -2

0 comment

2 changed files

pr created time in 3 days

create barnchsimonvandel/rust

branch : do-not-fire-on-drop-and-replace

created branch time in 3 days

PR opened rust-lang/rust

MIR-OPT: Less conservative `EarlyOtherwiseBranch`

It is not important that the types match in this optimization. Instead, we can apply the optimization more liberally if the layouts match.

Locally when compiling stage 1 std, stage2 and stage 2 std this increases the times the optimization fires from 543 to 573. A ~5% increase.

Also reorders checks so we check the cheapest first.

+124 -24

0 comment

4 changed files

pr created time in 3 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha d7aaafe8c6cd7c9039e58d41fb49ff2bf6f64405

Make the EarlyOtherwiseBranch optimization less conservative It is not important that the types match in this optimization. Instead, we can apply the optimization more liberally if the layouts match. Locally when compiling stage 1 std, stage2 and stage 2 std this increases the times the optimization fires from 543 to 573. A ~5% increase.

view details

Simon Vandel Sillesen

commit sha 77352bf9ec6dae277686c77060ff156a2c957746

Recorder checks - from intuitively cheapest to most expensive

view details

push time in 3 days

push eventsimonvandel/rust

Manish Goregaokar

commit sha c100e726c10fe9d212a58a5494126409e7d0e10b

Stabilize intra-doc links

view details

Manish Goregaokar

commit sha 63d5beec43ff7721928821cd83f9790188b03276

Move intra-doc-links documentation out of unstable section

view details

Manish Goregaokar

commit sha bc06674774e6457046e41a48dc3e8be8c5496f11

Mention super/crate/self in docs

view details

Manish Goregaokar

commit sha f072e4a7322e8e2b16410e3225e1afc15d132e36

Mention URL fragments

view details

Manish Goregaokar

commit sha 2a98409634ec38547d03512898192b5bdce15f3d

Fill out docs on intra-doc resolution failure lint

view details

Manish Goregaokar

commit sha 4e0eb0b73ba2defaf0f3c2152e9daa5c18d1603f

Update src/doc/rustdoc/src/linking-to-items-by-name.md Co-authored-by: Joshua Nelson <joshua@yottadb.com>

view details

Manish Goregaokar

commit sha 175e30539d5ee9364a26f89f8a03a60b53690684

Update src/doc/rustdoc/src/linking-to-items-by-name.md Co-authored-by: Joshua Nelson <joshua@yottadb.com>

view details

Manish Goregaokar

commit sha 51c1351f7b9366a295dce5d63c2fd387170d5c34

Resolve some conflicts

view details

Manish Goregaokar

commit sha 6f1fa2b16376f586285453045788519df527a1b2

Fix lint name in docs

view details

Manish Goregaokar

commit sha 792b2ea5812a06fe3d362ae36025998af66199ee

Update src/doc/rustdoc/src/lints.md Co-authored-by: Joshua Nelson <joshua@yottadb.com>

view details

Tomasz Miąsko

commit sha ff1a9e406bfccefedb6c4f2cabc0c4d59ac947d4

Fix underflow when calculating the number of no-op jumps folded When removing unwinds to no-op blocks and folding jumps to no-op blocks, remove the unwind target first. Otherwise we cannot determine if target has been already folded or not. Previous implementation incorrectly assumed that all resume targets had been folded already, occasionally resulting in an underflow: remove_noop_landing_pads: removed 18446744073709551613 jumps and 3 landing pads

view details

Joshua Nelson

commit sha 2f1bfd6399cfe439fbf2e446beafa5c55d1bb843

Preserve doc-comments when generating queries This also changes some comments into doc-comments.

view details

Manish Goregaokar

commit sha 6928041c0a992093a7752ae3c04090caebcd4515

Update src/doc/rustdoc/src/linking-to-items-by-name.md Co-authored-by: Joshua Nelson <joshua@yottadb.com>

view details

Bastian Kauschke

commit sha d4039c55c9ef392261aeaba6c14ae81f5098139a

wip emit errors during AbstractConst building

view details

Bastian Kauschke

commit sha 30cbc9729654c66b9f54779d18f023e47112cdf2

words

view details

yuk1ty

commit sha 16047d46a10813a25e956e659b8861cc67c20cd2

fix typo in docs and comments

view details

Oliver Scherer

commit sha c160bf3c3ef4434d76cc4d093b34e9bb1fdab2a1

Cache `eval_to_allocation_raw` on disk

view details

Mara Bos

commit sha db74e1f1e3e5c7497bb9af68814497c8df1fd0b8

Add cfg(target_has_atomic_equal_alignment). This is needed for Atomic::from_mut.

view details

Mara Bos

commit sha 9e3f94dabc334586d669f3aba0bded607ac782fc

Don't unwrap but report a fatal error for TargetDataLayout::parse.

view details

Mara Bos

commit sha af56ad7633668a790353f17440586e97b4e6a99b

Add feature gate ui test for cfg(target_has_atomic_load_store).

view details

push time in 3 days

create barnchsimonvandel/rust

branch : less-conservative-early-otherwise

created branch time in 3 days

Pull request review commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

 impl OptimizationFinder<'b, 'tcx> {         }     } +    fn find_eq_not(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // Optimize the sequence+        // _4 = Eq(move _5, const 2_u8);+        // StorageDead(_5);+        // _3 = Not(move _4);+        //+        // into _3 = Ne(move _5, const 2_u8)+        if let Rvalue::UnaryOp(UnOp::Not, op) = rvalue {+            let place = op.place()?;+            // See if we can find a Eq that assigns `place`.+            // We limit the search to 3 statements lookback.+            // Usually the first 2 statements are `StorageDead`s for operands for Eq.+            // We record what is marked dead so that we can reorder StorageDead so it comes after Ne++            // We will maximum see 2 StorageDeads+            let mut seen_storage_deads: SmallVec<[_; 2]> = SmallVec::new();+            let lower_index = location.statement_index.saturating_sub(3);+            for (stmt_idx, stmt) in self.body.basic_blocks()[location.block].statements+                [lower_index..location.statement_index]+                .iter()+                .enumerate()+                .rev()+            {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r)) => {+                        if *l == place {+                            match r {+                                Rvalue::BinaryOp(BinOp::Eq, op1, op2) => {+                                    // We need to make sure that the StorageDeads we saw are for

I think it may be beneficial to keep the current version. With your proposal, the interaction in https://github.com/rust-lang/rust/pull/77031#discussion_r492364145 would break. This is only one case, yeah, but it still seems worth to keep that.

What do you think?

simonvandel

comment created time in 4 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

 impl OptimizationFinder<'b, 'tcx> {         }     } +    fn find_eq_not(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // Optimize the sequence+        // _4 = Eq(move _5, const 2_u8);+        // StorageDead(_5);+        // _3 = Not(move _4);+        //+        // into _3 = Ne(move _5, const 2_u8)+        if let Rvalue::UnaryOp(UnOp::Not, op) = rvalue {+            let place = op.place()?;+            // See if we can find a Eq that assigns `place`.+            // We limit the search to 3 statements lookback.+            // Usually the first 2 statements are `StorageDead`s for operands for Eq.+            // We record what is marked dead so that we can reorder StorageDead so it comes after Ne++            // We will maximum see 2 StorageDeads+            let mut seen_storage_deads: SmallVec<[_; 2]> = SmallVec::new();+            let lower_index = location.statement_index.saturating_sub(3);+            for (stmt_idx, stmt) in self.body.basic_blocks()[location.block].statements+                [lower_index..location.statement_index]+                .iter()+                .enumerate()+                .rev()+            {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r)) => {+                        if *l == place {+                            match r {+                                Rvalue::BinaryOp(BinOp::Eq, op1, op2) => {+                                    // We need to make sure that the StorageDeads we saw are for

Yeah that might be simpler to do. For simplicity I'll let other passes optimize the move

simonvandel

comment created time in 5 days

pull request commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

Hi @oli-obk and @wesleywiser I have added a set of commits on top of the original 2, which should resolve your comments. @oli-obk I still need to understand your one comment.

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

simonvandel

comment created time in 5 days

push eventsimonvandel/rust

Ivan Tham

commit sha c5975e9b6c5781b3b7300b7921c14b060086e1c1

Reduce duplicate in liballoc reserve error handling

view details

Federico Ponzi

commit sha 27c90b881df93b53fd3f24dcbfed116379c2fc69

initial implementation of OpenOptions to c_int

view details

Federico Ponzi

commit sha eb3906be4ad375cc6b83cd6a6e0116817db22575

Fix typo get openoptions function name Co-authored-by: Ivan Tham <pickfire@riseup.net>

view details

Federico Ponzi

commit sha 1bc0627607262cc60a7692b16e205f30fc88b89f

Add as_flag function to the OpenOptionsExt struct

view details

Federico Ponzi

commit sha 2c9e27b759a9e9feeb943fb855e32d7383d1dcc6

Merge branch 'convert-openoptions-cint' of github.com:FedericoPonzi/rust into convert-openoptions-cint

view details

Federico Ponzi

commit sha 7c1e5c1dcd25c945f619eda289f639dbe2b002da

Update OpenOptions::as_flags docs, and minor styling

view details

Federico Ponzi

commit sha 321b680fe66d1be04cd67fac75ff7f148fd117fe

Update docs of OpenOptions::as_flags

view details

Federico Ponzi

commit sha 28db5214d2c48e7a58cf79b9e272097260910a33

More implementations of Write for immutable refs Fixes #73836

view details

Federico Ponzi

commit sha ec7f9b927f1896c7f29c602d6b0f961c891d0941

Deduplicates io::Write implementations

view details

Christiaan Dirkx

commit sha 8f27e3cb1b4140d9124d60df0850ef734e73b884

Make some methods of `Pin` unstable const Make the following methods unstable const under the `const_pin` feature: - `new` - `new_unchecked` - `into_inner` - `into_inner_unchecked` - `get_ref` - `into_ref` Also adds tests for these methods in a const context. Tracking issue: #76654

view details

Simon Vandel Sillesen

commit sha e5447a22222ecc6a650e75282cb9931b910854b2

Fix #76432 Only insert StorageDeads if we actually removed one. Fixes an issue where we added StorageDead to a place with no StorageLive

view details

Lzu Tao

commit sha eede953c283c7bbe903a0e8abb44c923baf5cfac

Only get ImplKind::Impl once

view details

Federico Ponzi

commit sha 70292d45060ee2b8829e2af0be54d5a76696cd1d

Sets as_flags as unstable

view details

Dylan MacKenzie

commit sha ed6c7efd87f17a7d9282f4bc7341cb5cbda8db4d

Use enum for status of non-const ops

view details

Dylan MacKenzie

commit sha c3607bd7dd323a898b8cc9d2c603dfd14172c73c

Use helper function for searching `allow_internal_unstable`

view details

Dylan MacKenzie

commit sha e4edc161f20ccbc77fffb7ceb60ebb6102cbd747

Give name to extra `Span` in `LiveDrop` error

view details

Dylan MacKenzie

commit sha 81b3b66487c7001a0dbadf7f9af41ad714702533

Error if an unstable const eval feature is used in a stable const fn

view details

Dylan MacKenzie

commit sha 1e1257b8f87d1e3073020df27765dc57fcf2c0cd

Bless `miri-unleashed` tests `const_mut_refs` doesn't actually work in a `const` or `static`

view details

Dylan MacKenzie

commit sha abc71677da866fd36c70790e768f36d2f809c493

Test that `const_precise_live_drops` can't be depended upon stably

view details

Mark Rousskov

commit sha 7e24136996fd412ba2890952d5f0ddffb3cb7370

Pass --target to lint docs Otherwise, we may not have a standard library built for the native "host" target of the rustc being run.

view details

push time in 5 days

Pull request review commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

 impl OptimizationFinder<'b, 'tcx> {         }     } +    fn find_eq_not(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // Optimize the sequence+        // _4 = Eq(move _5, const 2_u8);+        // StorageDead(_5);+        // _3 = Not(move _4);+        //+        // into _3 = Ne(move _5, const 2_u8)+        if let Rvalue::UnaryOp(UnOp::Not, op) = rvalue {+            let place = op.place()?;+            // See if we can find a Eq that assigns `place`.+            // We limit the search to 3 statements lookback.+            // Usually the first 2 statements are `StorageDead`s for operands for Eq.+            // We record what is marked dead so that we can reorder StorageDead so it comes after Ne++            // We will maximum see 2 StorageDeads+            let mut seen_storage_deads: SmallVec<[_; 2]> = SmallVec::new();+            let lower_index = location.statement_index.saturating_sub(3);+            for (stmt_idx, stmt) in self.body.basic_blocks()[location.block].statements+                [lower_index..location.statement_index]+                .iter()+                .enumerate()+                .rev()+            {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r)) => {+                        if *l == place {+                            match r {+                                Rvalue::BinaryOp(BinOp::Eq, op1, op2) => {+                                    // We need to make sure that the StorageDeads we saw are for

Can you expand on your statement? I don't understand your point about not removing Neq (you mean Not? or Ne?).

Now that I think about it, yeah, it is perhaps unneccessary to require that the StorageDeads are for the Eq operands. Hmm do we even need to do anything special about potential StorageDeads between Eq and Not? I think not, besides doing the swap, which I think we can just do unconditionally for simplicity. We already assert that only StorageDead statements can appear between Eq and Not, and I think simply swapping a StorageDead for a complete unrelated local with Ne should not matter.

simonvandel

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

 impl OptimizationFinder<'b, 'tcx> {         }     } +    fn find_eq_not(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // Optimize the sequence+        // _4 = Eq(move _5, const 2_u8);+        // StorageDead(_5);+        // _3 = Not(move _4);+        //+        // into _3 = Ne(move _5, const 2_u8)+        if let Rvalue::UnaryOp(UnOp::Not, op) = rvalue {+            let place = op.place()?;+            // See if we can find a Eq that assigns `place`.+            // We limit the search to 3 statements lookback.+            // Usually the first 2 statements are `StorageDead`s for operands for Eq.+            // We record what is marked dead so that we can reorder StorageDead so it comes after Ne++            // We will maximum see 2 StorageDeads+            let mut seen_storage_deads: SmallVec<[_; 2]> = SmallVec::new();+            let lower_index = location.statement_index.saturating_sub(3);+            for (stmt_idx, stmt) in self.body.basic_blocks()[location.block].statements+                [lower_index..location.statement_index]+                .iter()+                .enumerate()+                .rev()+            {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r)) => {+                        if *l == place {+                            match r {+                                Rvalue::BinaryOp(BinOp::Eq, op1, op2) => {

True, i'll add a FIXME.

simonvandel

comment created time in 5 days

PullRequestReviewEvent

Pull request review commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

 impl OptimizationFinder<'b, 'tcx> {         }     } +    fn find_eq_not(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // Optimize the sequence+        // _4 = Eq(move _5, const 2_u8);+        // StorageDead(_5);+        // _3 = Not(move _4);+        //+        // into _3 = Ne(move _5, const 2_u8)+        if let Rvalue::UnaryOp(UnOp::Not, op) = rvalue {+            let place = op.place()?;+            // See if we can find a Eq that assigns `place`.+            // We limit the search to 3 statements lookback.+            // Usually the first 2 statements are `StorageDead`s for operands for Eq.+            // We record what is marked dead so that we can reorder StorageDead so it comes after Ne++            // We will maximum see 2 StorageDeads+            let mut seen_storage_deads: SmallVec<[_; 2]> = SmallVec::new();+            let lower_index = location.statement_index.saturating_sub(3);+            for (stmt_idx, stmt) in self.body.basic_blocks()[location.block].statements+                [lower_index..location.statement_index]+                .iter()+                .enumerate()+                .rev()+            {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r)) => {+                        if *l == place {+                            match r {+                                Rvalue::BinaryOp(BinOp::Eq, op1, op2) => {+                                    // We need to make sure that the StorageDeads we saw are for+                                    // either `op1`or `op2` of Eq. Else we bail the optimization.+                                    for (dead_local, _) in seen_storage_deads.iter() {+                                        let dead_local_matches = [op1, op2].iter().any(|x| {+                                            Some(*dead_local) == x.place().map(|x| x.local)+                                        });+                                        if !dead_local_matches {+                                            return None;+                                        }+                                    }++                                    // We need to make sure that the Ne we are going to insert comes before the+                                    // StorageDeads so we want to swap the StorageDead closest to Eq with Ne.

I think the confusion comes from the use of "insert"? We are replacing the Not with a Ne. And since we are going to use the operands from Eq in Ne, we need to make sure that we do not mark these operands as dead before they are used. I'll push up a new commit where I try to explain this better.

simonvandel

comment created time in 5 days

PullRequestReviewEvent

pull request commentrust-lang/rust

Fix #76803 miscompilation

Hi @wesleywiser Just wanted to ping you that I have resolved your comment.

simonvandel

comment created time in 5 days

pull request commentrust-lang/rust

MIR pass to remove unneeded drops on types not needing drop

Let's try again with the test ignored on wasm

simonvandel

comment created time in 5 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 05f84c67a4f38136b1a7be9065781611061a23d3

Ignore test on wasm as it does not unwind

view details

push time in 5 days

pull request commentrust-lang/rust

MIR pass to remove unneeded drops on types not needing drop

Hmm seems like the same error as in the rollup. When I did the rebase I also reblessed but that didn't change any files. Not sure what is wrong at this point.

simonvandel

comment created time in 5 days

pull request commentrust-lang/rust

MIR pass to remove unneeded drops on types not needing drop

Rebased

simonvandel

comment created time in 5 days

push eventsimonvandel/rust

Ivan Tham

commit sha c5975e9b6c5781b3b7300b7921c14b060086e1c1

Reduce duplicate in liballoc reserve error handling

view details

Federico Ponzi

commit sha 27c90b881df93b53fd3f24dcbfed116379c2fc69

initial implementation of OpenOptions to c_int

view details

Federico Ponzi

commit sha eb3906be4ad375cc6b83cd6a6e0116817db22575

Fix typo get openoptions function name Co-authored-by: Ivan Tham <pickfire@riseup.net>

view details

Federico Ponzi

commit sha 1bc0627607262cc60a7692b16e205f30fc88b89f

Add as_flag function to the OpenOptionsExt struct

view details

Federico Ponzi

commit sha 2c9e27b759a9e9feeb943fb855e32d7383d1dcc6

Merge branch 'convert-openoptions-cint' of github.com:FedericoPonzi/rust into convert-openoptions-cint

view details

Federico Ponzi

commit sha 7c1e5c1dcd25c945f619eda289f639dbe2b002da

Update OpenOptions::as_flags docs, and minor styling

view details

Federico Ponzi

commit sha 321b680fe66d1be04cd67fac75ff7f148fd117fe

Update docs of OpenOptions::as_flags

view details

Federico Ponzi

commit sha 28db5214d2c48e7a58cf79b9e272097260910a33

More implementations of Write for immutable refs Fixes #73836

view details

Federico Ponzi

commit sha ec7f9b927f1896c7f29c602d6b0f961c891d0941

Deduplicates io::Write implementations

view details

Christiaan Dirkx

commit sha 8f27e3cb1b4140d9124d60df0850ef734e73b884

Make some methods of `Pin` unstable const Make the following methods unstable const under the `const_pin` feature: - `new` - `new_unchecked` - `into_inner` - `into_inner_unchecked` - `get_ref` - `into_ref` Also adds tests for these methods in a const context. Tracking issue: #76654

view details

Lzu Tao

commit sha eede953c283c7bbe903a0e8abb44c923baf5cfac

Only get ImplKind::Impl once

view details

Federico Ponzi

commit sha 70292d45060ee2b8829e2af0be54d5a76696cd1d

Sets as_flags as unstable

view details

Dylan MacKenzie

commit sha ed6c7efd87f17a7d9282f4bc7341cb5cbda8db4d

Use enum for status of non-const ops

view details

Dylan MacKenzie

commit sha c3607bd7dd323a898b8cc9d2c603dfd14172c73c

Use helper function for searching `allow_internal_unstable`

view details

Dylan MacKenzie

commit sha e4edc161f20ccbc77fffb7ceb60ebb6102cbd747

Give name to extra `Span` in `LiveDrop` error

view details

Dylan MacKenzie

commit sha 81b3b66487c7001a0dbadf7f9af41ad714702533

Error if an unstable const eval feature is used in a stable const fn

view details

Dylan MacKenzie

commit sha 1e1257b8f87d1e3073020df27765dc57fcf2c0cd

Bless `miri-unleashed` tests `const_mut_refs` doesn't actually work in a `const` or `static`

view details

Dylan MacKenzie

commit sha abc71677da866fd36c70790e768f36d2f809c493

Test that `const_precise_live_drops` can't be depended upon stably

view details

Mark Rousskov

commit sha 7e24136996fd412ba2890952d5f0ddffb3cb7370

Pass --target to lint docs Otherwise, we may not have a standard library built for the native "host" target of the rustc being run.

view details

Mark Rousskov

commit sha bd4e0af0b54afc91903c282740e25ee6135224c8

Build rustdoc for cross-compiled targets This isn't an issue for most folks who use x.py dist, which will directly depend on this. But for x.py build, if we don't properly set target here rustdoc will not be built. Currently, there is not a default-on step for generating a rustc for a given target either, so we will fail to build a rustc as well.

view details

push time in 5 days

pull request commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

Hi @ecstatic-morse This optimization pass was created in response to #68867 which demonstrated a case where LLVM would not make this optimization. I did a small comparison (see https://github.com/rust-lang/rust/issues/68867#issuecomment-696975257) which shows that the final asm that LLVM generates looks a lot cleaner. I have not benchmarked what the actualy speedup is in terms of running the function though.

simonvandel

comment created time in 5 days

issue commentrust-lang/rust

Bad codegen with simple match statement

After #75119 final asm appears much better. I'll be using the following test file 68867.rs:

type CSSFloat = f32;

pub enum ViewportPercentageLength {
    Vw(CSSFloat),
    Vh(CSSFloat),
    Vmin(CSSFloat),
    Vmax(CSSFloat),
}

impl ViewportPercentageLength {
    fn try_sum(&self, other: &Self) -> Result<Self, ()> {
        use self::ViewportPercentageLength::*;
        Ok(match (self, other) {
            (&Vw(one), &Vw(other)) => Vw(one + other),
            (&Vh(one), &Vh(other)) => Vh(one + other),
            (&Vmin(one), &Vmin(other)) => Vmin(one + other),
            (&Vmax(one), &Vmax(other)) => Vmax(one + other),
            _ => return Err(()),
        })
    }
}

#[no_mangle]
pub extern "C" fn sum_them(
    one: &ViewportPercentageLength,
    other: &ViewportPercentageLength,
    out: &mut ViewportPercentageLength,
) -> bool {
    match one.try_sum(other) {
        Ok(v) => {
            *out = v;
            true
        }
        Err(()) => false,
    }
}

fn main() {}

before: rustup run nightly-2020-09-20 rustc 68867.rs --emit=asm -O -C opt-level=3 -o 2020-09-20.s

	.section	.text.sum_them,"ax",@progbits
	.globl	sum_them
	.p2align	4, 0x90
	.type	sum_them,@function
sum_them:
	.cfi_startproc
	movl	(%rdi), %eax
	movss	4(%rdi), %xmm0
	movl	(%rsi), %ecx
	movss	4(%rsi), %xmm1
	leaq	.LJTI5_0(%rip), %rsi
	movslq	(%rsi,%rax,4), %rax
	addq	%rsi, %rax
	jmpq	*%rax
.LBB5_1:
	xorl	%eax, %eax
	testl	%ecx, %ecx
	je	.LBB5_8
	retq
.LBB5_3:
	movl	$2, %eax
	cmpl	$2, %ecx
	je	.LBB5_8
.LBB5_9:
	xorl	%eax, %eax
	retq
.LBB5_5:
	movl	$3, %eax
	cmpl	$3, %ecx
	jne	.LBB5_9
.LBB5_8:
	addss	%xmm1, %xmm0
	movl	%eax, (%rdx)
	movss	%xmm0, 4(%rdx)
	movb	$1, %al
	retq
.LBB5_7:
	movl	$1, %eax
	cmpl	$1, %ecx
	jne	.LBB5_9
	jmp	.LBB5_8
.Lfunc_end5:
	.size	sum_them, .Lfunc_end5-sum_them
	.cfi_endproc
	.section	.rodata.sum_them,"a",@progbits
	.p2align	2
.LJTI5_0:
	.long	.LBB5_1-.LJTI5_0
	.long	.LBB5_7-.LJTI5_0
	.long	.LBB5_3-.LJTI5_0
	.long	.LBB5_5-.LJTI5_0

after: rustup run nightly-2020-09-21 rustc 68867.rs --emit=asm -O -C opt-level=3 -o 2020-09-21.s

	.section	.text.sum_them,"ax",@progbits
	.globl	sum_them
	.p2align	4, 0x90
	.type	sum_them,@function
sum_them:
	.cfi_startproc
	movl	(%rdi), %eax
	cmpl	%eax, (%rsi)
	jne	.LBB5_1
	movss	4(%rdi), %xmm0
	addss	4(%rsi), %xmm0
	movl	%eax, (%rdx)
	movss	%xmm0, 4(%rdx)
	movb	$1, %al
	retq
.LBB5_1:
	xorl	%eax, %eax
	retq
.Lfunc_end5:
	.size	sum_them, .Lfunc_end5-sum_them
	.cfi_endproc
emilio

comment created time in 5 days

Pull request review commentrust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne

           _17 = (*_13);                    // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL           StorageLive(_18);                // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL           _18 = const 1_i32;               // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL-          _16 = Eq(move _17, const 1_i32); // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL+          nop;                             // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL+          _15 = Ne(_17, const 1_i32);      // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL+          nop;                             // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL           StorageDead(_18);                // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL-          StorageDead(_17);                // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL-          _15 = Not(move _16);             // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL           StorageDead(_16);                // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL-          switchInt(_15) -> [false: bb4, otherwise: bb5]; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL+          switchInt(move _17) -> [1_i32: bb4, otherwise: bb5]; // scope 4 at $SRC_DIR/core/src/macros/mod.rs:LL:COL

I think this is a pretty cool interaction between SimplifyComparisonIntegral and this optimization that makes it possible to eliminate the Ne entirely, since we can just switch on _17 directly.

simonvandel

comment created time in 6 days

PullRequestReviewEvent

PR opened rust-lang/rust

[MIR-OPT]: Optimization that turns Eq-Not pair into Ne
+452 -75

0 comment

8 changed files

pr created time in 6 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 208a69b072585dcde8f35edf34c4add6effe35ec

Implement optimization that turns Eq-Not pair into Ne

view details

push time in 6 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha b1a522acecac63a29a5c33fcee9c771db3635198

Implement optimization that turns Eq-Not pair into Ne

view details

push time in 6 days

push eventsimonvandel/rust

Guillaume Gomez

commit sha 69ffed763d1540c387db3b578848184026da0484

Add error explanation for E0755

view details

Tavian Barnes

commit sha a06edda3ad9abd4f07d07bbe46cb488efeebbbd0

Fix segfault if pthread_getattr_np fails glibc destroys[1] the passed pthread_attr_t if pthread_getattr_np() fails. Destroying it again leads to a segfault. Fix it by only destroying it on success for glibc. [1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_getattr_np.c;h=ce437205e41dc05653e435f6188768cccdd91c99;hb=HEAD#l205

view details

Tavian Barnes

commit sha a684153f2920729f9fc3ea27ddb77d7cc3543214

Only call pthread_attr_destroy() after getattr_np() succeeds on all libcs The calling convention of pthread_getattr_np() is to initialize the pthread_attr_t, so _destroy() is only necessary on success (and _init() isn't necessary beforehand). On the other hand, FreeBSD wants the attr_t to be initialized before pthread_attr_get_np(), and therefore it should always be destroyed afterwards.

view details

Jethro Beekman

commit sha 1d2290ffb0f8f85c8de56c17e6be748d84dcfb04

Update LLVM

view details

Juan Aguilar Santillana

commit sha 7b5d9836c47509e16900a274ed0b552a2e30a36a

Remove redundant to_string

view details

Matthias Krüger

commit sha 026922ad60a9529f16b792e8c2fe805ab3906259

make replace_prefix only take &str as arguments https://github.com/rust-lang/rust/pull/76828#issuecomment-694078200

view details

Juan Aguilar Santillana

commit sha 28cfa9730eec41314dee99323f7d20aaadde9e0e

Simplify panic_if_treat_err_as_bug avoiding allocations

view details

Alexis Bourget

commit sha 4675a3104b3ace025560337c5d164e330f6b9d68

Use intra-doc links in core/src/iter when possible

view details

Alexis Bourget

commit sha bffd2111f7b033902e60889da5d3fa7a033a7d5e

Finish moving to intra doc links for std::sync

view details

Alexis Bourget

commit sha 982ec0d0c9ed93d806340502d48de190e1558a64

Fix broken link

view details

Alexis Bourget

commit sha b534d9f6e1e2b3e77842c5ededa62f6bcfb2ea58

Fix broken link

view details

khyperia

commit sha 0bc405e3521d84cfaef7d94f1ae40c6c16796c8b

Remove DeclareMethods

view details

Giacomo Stevanato

commit sha 924cd135b6ab0fe48dae26d9ae30eaadebcd066d

Added benchmarks for BinaryHeap

view details

Giacomo Stevanato

commit sha af1e3633f734930a50000cc424fbcdc6629885c3

Set sift=true only when PeekMut yields a mutable reference

view details

Giacomo Stevanato

commit sha ca15e9d8a11e7c25eb85930d1da3009647c1680e

Fix time complexity in BinaryHeap::peek_mut docs

view details

Tomasz Miąsko

commit sha 65edf54c256e5369fdf9c0a972cd83d2414d5bb5

Add a regression test for copy propagation miscompilation

view details

est31

commit sha cebbd9fcd35a63569b8fb5c836b5a26089861c41

Use as_nanos in bench.rs and base.rs

view details

est31

commit sha 43193dcb882466163436057e50c96bb74d9bf50f

Use as_secs_f64 in profiling.rs

view details

est31

commit sha 4bc0e55ac4280be80d8cd0f9bc26bd0949f75494

Replace write_fmt with write! Latter is simpler

view details

Dániel Buga

commit sha b2c5f99883bf7ba348c9e9c03e7592b18ef59665

Add test for issue #34634

view details

push time in 6 days

pull request commentrust-lang/rust

Add optimization to avoid load of address

Rebased on master and added a new commit such that Add is always generated instead of CheckedAdd, which broke the test diff on noopt testruns.

simonvandel

comment created time in 6 days

push eventsimonvandel/rust

CDirkx

commit sha 518f1ccb728aa03665e51710c12973a74cc98df5

Stabilize some Result methods as const Stabilize the following methods of `Result` as const: - `is_ok` - `is_err` - `as_ref` Possible because of stabilization of #49146 (Allow if and match in constants).

view details

Christiaan Dirkx

commit sha 787b2707a77fa1a98f512a4905662a1a16daf13c

Move const tests for `Result` to `library\core` Part of #76268

view details

Guillaume Gomez

commit sha 69ffed763d1540c387db3b578848184026da0484

Add error explanation for E0755

view details

Tavian Barnes

commit sha a06edda3ad9abd4f07d07bbe46cb488efeebbbd0

Fix segfault if pthread_getattr_np fails glibc destroys[1] the passed pthread_attr_t if pthread_getattr_np() fails. Destroying it again leads to a segfault. Fix it by only destroying it on success for glibc. [1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=nptl/pthread_getattr_np.c;h=ce437205e41dc05653e435f6188768cccdd91c99;hb=HEAD#l205

view details

Tavian Barnes

commit sha a684153f2920729f9fc3ea27ddb77d7cc3543214

Only call pthread_attr_destroy() after getattr_np() succeeds on all libcs The calling convention of pthread_getattr_np() is to initialize the pthread_attr_t, so _destroy() is only necessary on success (and _init() isn't necessary beforehand). On the other hand, FreeBSD wants the attr_t to be initialized before pthread_attr_get_np(), and therefore it should always be destroyed afterwards.

view details

Camelid

commit sha fd79ed42254d7483569ccc48ef35a79635ed5881

Add docs for `BasicBlock`

view details

Camelid

commit sha a872ec47145ce3a82c39bedaca21b99e867d9be2

Clarify how branching works in a CFG

view details

Stein Somers

commit sha 176956c115c2b797471a3f59eef3e17789229007

Test and fix Sync & Send traits of BTreeMap artefacts

view details

Camelid

commit sha c051f61d3c078343db70e355feea808892deed75

Improve wording Co-authored-by: Joshua Nelson <joshua@yottadb.com>

view details

khyperia

commit sha 21b0c1286a1f01cb8a21bda0973833ca11889364

Extract some intrinsics out of rustc_codegen_llvm A significant amount of intrinsics do not actually need backend-specific behaviors to be implemented, instead relying on methods already in rustc_codegen_ssa. So, extract those methods out to rustc_codegen_ssa, so that each backend doesn't need to reimplement the same code.

view details

Joshua Nelson

commit sha c35ce3ff170333d11ccf89e75dc87c49f44a570a

Don't generate bootstrap usage unless it's needed Previously, `x.py` would unconditionally run `x.py build` to get the help message. After https://github.com/rust-lang/rust/issues/76165, when checking the CI stage was moved into `Config`, that would cause an assertion failure (but only only in CI!): ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `1`, right: `2`', src/bootstrap/config.rs:619:49 ``` This changes bootstrap to only generate a help message when it needs to (when someone passes `--help`).

view details

Jethro Beekman

commit sha 1d2290ffb0f8f85c8de56c17e6be748d84dcfb04

Update LLVM

view details

Matthias Krüger

commit sha 94dae6004035c356b00dac8764c1b4808d740928

simplfy condition in ItemLowerer::with_trait_impl_ref()

view details

Camelid

commit sha 57eb29cd2dc30c47b613ced135422a4120bc6a78

Update based on review suggestions

view details

Ivan Tham

commit sha b7c8bea6cbf0aff4cbb36b127edc0bb4c66c4cf9

Fix wording in mir doc

view details

Hanif Bin Ariffin

commit sha f4a7149f499a4b91d296678002f0bce4ded85038

Don't compile regex at every function call. Use `SyncOnceCell` to only compile it once. I believe this still adds some kind of locking mechanism?

view details

est31

commit sha b47913962097874257ad10227b943ef7af85d49f

Remove intrinsics::arith_offset use from libarena The use of arith_offset was added in 803e9ae67b770d8500c4ab5862e988d29118356a before the stable wrapper of the intrinsic was available. https://doc.rust-lang.org/stable/std/intrinsics/fn.arith_offset.html

view details

est31

commit sha 4fe6ca37898bcd65488764f2679e27c936879ade

Replace const_generics feature gate with min_const_generics The latter is on the path to stabilization.

view details

est31

commit sha ebdea011436dfea810ff1bbd827636ac75f6f092

Remove redundant #![feature(...)] 's from compiler/

view details

Bastian Kauschke

commit sha 5f58e00ca565c8964dbf89f510236f72951d0bab

fix array_windows docs

view details

push time in 6 days

pull request commentrust-lang/rust

MIR pass to remove unneeded drops on types not needing drop

Rebased and reblessed tests.

simonvandel

comment created time in 6 days

push eventsimonvandel/rust

Marcel Hellwig

commit sha 73e27b3e18dcbbef3a36620c4a44306e2bbdcd13

deny(unsafe_op_in_unsafe_fn) in libstd/process.rs

view details

Marcel Hellwig

commit sha 00d537dcd03f9ff5ebdf8b86e039dbdb0a7f850c

deny(unsafe_op_in_unsafe_fn) in libstd/path.rs

view details

Ivan Tham

commit sha a7468705cbf0fb551b8b1d8b420123262f7d92b2

Use translated variable for test string Test should be educative, added english translation and pronounciation.

view details

Ivan Tham

commit sha ba4c4988161abbe58e973b792c7e271785b4bc4d

Add more info for Vec Drain doc See its documentation for more

view details

Ivan Tham

commit sha 71484121001b69aefdc41fd7192b7095250517a7

Vec slice example fix style and show type elision

view details

David Wood

commit sha 0f2bd56b29857453835e47abbe96a80b175632d1

lint/ty: move fns to avoid abstraction violation This commit moves `transparent_newtype_field` and `is_zst` to `LateContext` where they are used, rather than being on the `VariantDef` and `TyS` types. Signed-off-by: David Wood <david@davidtw.co>

view details

CDirkx

commit sha 518f1ccb728aa03665e51710c12973a74cc98df5

Stabilize some Result methods as const Stabilize the following methods of `Result` as const: - `is_ok` - `is_err` - `as_ref` Possible because of stabilization of #49146 (Allow if and match in constants).

view details

CDirkx

commit sha ea5dc0909ea1ed4135f1bdecbaa3423051be578d

Make some Ordering methods const Constify the following methods of `core::cmp::Ordering`: - `reverse` - `then` Stabilizes these methods as const under the `const_ordering` feature. Also adds a test for these methods in a const context. Possible because of #49146 (Allow `if` and `match` in constants).

view details

Howard Su

commit sha a80d39041e2d5cd58a846c9ef9e01ee9d691a7ed

Use inline(never) instead of cold inline(never) is better way to avoid optimizer to inline the function instead of cold.

view details

Jethro Beekman

commit sha 0b5e681f5af0d3989b49121969f09cf29f029263

Improve SGX RWLock initializer test

view details

Tomasz Miąsko

commit sha 9daf8fd5b1d369cd2f91ac919dc5d17f4fd43c0c

inliner: Emit storage markers for introduced arg temporaries When introducing argument temporaries during inlining, emit storage marker statements just before the assignment and in the beginning of the return block. This ensures that such temporaries will not be considered live across yield points after inlining inside a generator.

view details

Christiaan Dirkx

commit sha 787b2707a77fa1a98f512a4905662a1a16daf13c

Move const tests for `Result` to `library\core` Part of #76268

view details

Christiaan Dirkx

commit sha 79d563c819483eaf6e67b6aaaef9d0ca6030337d

Move const tests for `Ordering` to `library\core` Part of #76268

view details

Tomasz Miąsko

commit sha b54386ab7a9da8a4f22db3a35a9ec7b0f2b98b6c

Detect overflow in proc_macro_server subspan

view details

Tomasz Miąsko

commit sha d98bac4e4e3cc87ec9b848c173d570ebe2aa30b6

Add tests for overflow in Vec::drain

view details

Tomasz Miąsko

commit sha f8cfb2f5ad847b871399dfef9b8b8ff4e84a75cb

Add tests for overflow in String / VecDeque operations using ranges

view details

Scott McMurray

commit sha 6092828d1f432bb313818e7cfab961c0e494f69e

Add `[T; N]: TryFrom<Vec<T>>` This is very similar to the existing `Box<[T; N]>: TryFrom<Box<[T]>>`, but allows avoiding the `shrink_to_fit` if you have a vector and not a boxed slice.

view details

David Wood

commit sha f8376b59d1391a5191a561c44067355f1a99c7c0

shim: monomorphic `FnPtrShim`s during construction This commit adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`) - as substitutions will no longer occur during codegen, function pointer shims can now be polymorphic without incurring double substitutions. Signed-off-by: David Wood <david@davidtw.co>

view details

kadmin

commit sha 6cb671628393e292d5e68e6367f80488ace46532

Add test for checking if-let or-patterns

view details

Ayush Kumar Mishra

commit sha 941dca8ed238a04a55741127165e9ad80671ed8a

Add Arith Tests in Library

view details

push time in 6 days

create barnchsimonvandel/rust

branch : eq-not

created branch time in 6 days

create barnchsimonvandel/rust

branch : inst-combine-deref3

created branch time in 7 days

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+// compile-flags: -Z mir-opt-level=3++// example from #68867+type CSSFloat = f32;++pub enum ViewportPercentageLength {+    Vw(CSSFloat),+    Vh(CSSFloat),+    Vmin(CSSFloat),+    Vmax(CSSFloat),+}++// EMIT_MIR early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff+// EMIT_MIR early_otherwise_branch_68867.try_sum EarlyOtherwiseBranch.before SimplifyBranches-after-copy-prop.after

Thanks, pushed that

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 0363694c7ff72d0a4b1c52ebf2320930c3b60da8

emit diff after SimplifyBranches-after-copy-prop

view details

push time in 8 days

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+// compile-flags: -Z mir-opt-level=3++// example from #68867+type CSSFloat = f32;++pub enum ViewportPercentageLength {+    Vw(CSSFloat),+    Vh(CSSFloat),+    Vmin(CSSFloat),+    Vmax(CSSFloat),+}++// EMIT_MIR early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff+// EMIT_MIR early_otherwise_branch_68867.try_sum EarlyOtherwiseBranch.before SimplifyBranches-after-copy-prop.after

@oli-obk Tidy complaines that this is longer than 100 chars. I'm not sure how to compress it. Any ideas?

simonvandel

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+// compile-flags: -Z mir-opt-level=3++// example from #68867+type CSSFloat = f32;++pub enum ViewportPercentageLength {+    Vw(CSSFloat),+    Vh(CSSFloat),+    Vmin(CSSFloat),+    Vmax(CSSFloat),+}++// EMIT_MIR early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff

Just pushed a diff from before EarlyOtherwiseBranch to after SimplifyBranches-after-copy-prop. Or do you mean something else?

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 13e8e20df3307d8eaf8b6f86e73f313fcaab39b2

emit diff after SimplifyBranches-after-copy-prop

view details

push time in 8 days

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+use crate::{+    transform::{MirPass, MirSource},+    util::patch::MirPatch,+};+use rustc_middle::mir::*;+use rustc_middle::ty::{Ty, TyCtxt};+use std::{borrow::Cow, fmt::Debug};++use super::simplify::simplify_cfg;++/// This pass optimizes something like+/// ```text+/// let x: Option<()>;+/// let y: Option<()>;+/// match (x,y) {+///     (Some(_), Some(_)) => {0},+///     _ => {1}+/// }+/// ```+/// into something like+/// ```text+/// let x: Option<()>;+/// let y: Option<()>;+/// let discriminant_x = // get discriminant of x+/// let discriminant_y = // get discriminant of y+/// if discriminant_x != discriminant_y || discriminant_x == None {1} else {0}+/// ```+pub struct EarlyOtherwiseBranch;++impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {+    fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'tcx>) {+        if tcx.sess.opts.debugging_opts.mir_opt_level < 1 {

@oli-obk should I gate this optimization? If yes, which?

simonvandel

comment created time in 8 days

PullRequestReviewEvent

pull request commentrust-lang/rust

Add optimization to avoid load of address

Squashed and rebased on master

simonvandel

comment created time in 8 days

push eventsimonvandel/rust

Marcel Hellwig

commit sha 73e27b3e18dcbbef3a36620c4a44306e2bbdcd13

deny(unsafe_op_in_unsafe_fn) in libstd/process.rs

view details

Marcel Hellwig

commit sha 00d537dcd03f9ff5ebdf8b86e039dbdb0a7f850c

deny(unsafe_op_in_unsafe_fn) in libstd/path.rs

view details

Ivan Tham

commit sha a7468705cbf0fb551b8b1d8b420123262f7d92b2

Use translated variable for test string Test should be educative, added english translation and pronounciation.

view details

Ivan Tham

commit sha ba4c4988161abbe58e973b792c7e271785b4bc4d

Add more info for Vec Drain doc See its documentation for more

view details

Ivan Tham

commit sha 71484121001b69aefdc41fd7192b7095250517a7

Vec slice example fix style and show type elision

view details

David Wood

commit sha 0f2bd56b29857453835e47abbe96a80b175632d1

lint/ty: move fns to avoid abstraction violation This commit moves `transparent_newtype_field` and `is_zst` to `LateContext` where they are used, rather than being on the `VariantDef` and `TyS` types. Signed-off-by: David Wood <david@davidtw.co>

view details

CDirkx

commit sha ea5dc0909ea1ed4135f1bdecbaa3423051be578d

Make some Ordering methods const Constify the following methods of `core::cmp::Ordering`: - `reverse` - `then` Stabilizes these methods as const under the `const_ordering` feature. Also adds a test for these methods in a const context. Possible because of #49146 (Allow `if` and `match` in constants).

view details

Howard Su

commit sha a80d39041e2d5cd58a846c9ef9e01ee9d691a7ed

Use inline(never) instead of cold inline(never) is better way to avoid optimizer to inline the function instead of cold.

view details

Christiaan Dirkx

commit sha 79d563c819483eaf6e67b6aaaef9d0ca6030337d

Move const tests for `Ordering` to `library\core` Part of #76268

view details

Tomasz Miąsko

commit sha b54386ab7a9da8a4f22db3a35a9ec7b0f2b98b6c

Detect overflow in proc_macro_server subspan

view details

Tomasz Miąsko

commit sha d98bac4e4e3cc87ec9b848c173d570ebe2aa30b6

Add tests for overflow in Vec::drain

view details

Tomasz Miąsko

commit sha f8cfb2f5ad847b871399dfef9b8b8ff4e84a75cb

Add tests for overflow in String / VecDeque operations using ranges

view details

Scott McMurray

commit sha 6092828d1f432bb313818e7cfab961c0e494f69e

Add `[T; N]: TryFrom<Vec<T>>` This is very similar to the existing `Box<[T; N]>: TryFrom<Box<[T]>>`, but allows avoiding the `shrink_to_fit` if you have a vector and not a boxed slice.

view details

David Wood

commit sha f8376b59d1391a5191a561c44067355f1a99c7c0

shim: monomorphic `FnPtrShim`s during construction This commit adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`) - as substitutions will no longer occur during codegen, function pointer shims can now be polymorphic without incurring double substitutions. Signed-off-by: David Wood <david@davidtw.co>

view details

kadmin

commit sha 6cb671628393e292d5e68e6367f80488ace46532

Add test for checking if-let or-patterns

view details

Ayush Kumar Mishra

commit sha 941dca8ed238a04a55741127165e9ad80671ed8a

Add Arith Tests in Library

view details

Ayush Kumar Mishra

commit sha dc37b553accd4fb2f8d0c59f69c701b524361cc2

Minor refactoring

view details

Ayush Kumar Mishra

commit sha 7d834c87d2ebb3d8dd4895bc5fabc4d44a1d2b52

Move Various str tests in library

view details

scottmcm

commit sha 2c8a4c8f73e8b36e72b15e7f97ef29ad36c15e17

Nightly is currently 1.48

view details

Ivan Tham

commit sha 685f04220ee584f00f60e5ff9d7aca16351c5399

Clean up vec benches bench_in_place style

view details

push time in 8 days

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+// compile-flags: -Z mir-opt-level=3++// example from #68867+type CSSFloat = f32;++pub enum ViewportPercentageLength {+    Vw(CSSFloat),+    Vh(CSSFloat),+    Vmin(CSSFloat),+    Vmax(CSSFloat),+}++// EMIT_MIR early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff

Rebasing on master, the diff looks even better as DestinationPropagation is now in master

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

David Wood

commit sha f8376b59d1391a5191a561c44067355f1a99c7c0

shim: monomorphic `FnPtrShim`s during construction This commit adjusts MIR shim construction so that substitutions are applied to function pointer shims during construction, rather than during codegen (as determined by `substs_for_mir_body`) - as substitutions will no longer occur during codegen, function pointer shims can now be polymorphic without incurring double substitutions. Signed-off-by: David Wood <david@davidtw.co>

view details

Jonas Schievink

commit sha 78ff69ba1086decb205b988f05aba7711dddb221

Implement a destination propagation pass

view details

Jonas Schievink

commit sha 43ad8e4260bec289c522a2fd3597c275e9e3c39c

simplify_try: print dest_prop diff and bless The new diff is to convince me that this is correct and nothing funky is going on.

view details

Jonas Schievink

commit sha 16498953856a41e781da65709f1d111cef66af91

simplify_try: clean up test

view details

Jonas Schievink

commit sha 8a7b1c38940e8c0a013dacf52db6a7884f156d3e

Make nrvo-simple set mir-opt-level=1 The additional copies are due to the lack of copy propagation

view details

Jonas Schievink

commit sha 8a3e2b78bb0595bc9205b29898eb128836b5c57f

Bless mir-opt tests

view details

Jonas Schievink

commit sha 812d4bbc8d1a240ecc900ffafacb5ce34f69e9f3

Fix dataflow assert errors

view details

Jonas Schievink

commit sha 7dbc7f76e1a0f1d054655f6fa5786b700745b66e

Add a few dest-prop MIR tests

view details

Jonas Schievink

commit sha 402f863d8ac2e69abf415d9ed9c1b9984e037700

perf: walk liveness backwards in Conflicts::build

view details

Jonas Schievink

commit sha 665a98d21f926fbd8a89fe2af7c448ff34deadc3

Fix dest-prop mir-opt tests

view details

Jonas Schievink

commit sha ab26fb140c9225c690a219c055a54eba57188d4a

perf: only calculate conflicts for candidates

view details

Jonas Schievink

commit sha ddd6930b549d069ac13de66b8676fed4feb95ec4

perf: bail out when there's >500 candidate locals

view details

Jonas Schievink

commit sha 88538adf9ae1886d9b5c1f45d55b2f76bd6435bd

Record intra-statement/terminator conflicts Some MIR statements and terminators have an (undocumented...) invariant that some of their input and outputs must not overlap. This records conflicts between locals used in these positions.

view details

Jonas Schievink

commit sha 934634eacc2721e482672a99f91ed458580eb978

More logging

view details

Jonas Schievink

commit sha 484db5b08a83bd8875e0e938a0f78ce0a220bb17

Properly inherit conflicts when merging locals

view details

Jonas Schievink

commit sha 572883444899ea0aecd5cd6cdf3466255dd4c7e0

Fix rebase fallout

view details

Jonas Schievink

commit sha 7af964fecf77696e523020a430fd4a0d0d4bc190

Limit block count

view details

Jonas Schievink

commit sha cd5d7201ad1e5bf9d69e9a15e385ba03f678ad87

Fix rebase fallout

view details

Jonas Schievink

commit sha 682de94e315eac8be64423815edc4a0aa9e36539

Move inner items outside

view details

Jonas Schievink

commit sha ffd9445812cf8dc10a12f62db5135a0a17e066f5

Return `Place` by value

view details

push time in 8 days

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+// compile-flags: -Z mir-opt-level=3++// example from #68867+type CSSFloat = f32;++pub enum ViewportPercentageLength {+    Vw(CSSFloat),+    Vh(CSSFloat),+    Vmin(CSSFloat),+    Vmax(CSSFloat),+}++// EMIT_MIR early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff

I pushed a new commit that adds this (if I understood correctly what you meant)

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 6e45568b56d7ed2b6219e1f1ad79212dbe4d50fe

emit diff after SimplifyBranches-after-copy-prop

view details

push time in 8 days

Pull request review commentrust-lang/rust

Add optimization to avoid load of address

 impl OptimizationFinder<'b, 'tcx> {         OptimizationFinder { body, tcx, optimizations: OptimizationList::default() }     } +    fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // look for the sequence+        // _2 = &_1;+        // ...+        // _5 = (*_2)+        //+        // which we can replace the last statement with `_5 = _1` to avoid the load of _2+        if let Rvalue::Use(op) = rvalue {+            let local_being_derefed = match op.place()?.as_ref() {+                PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),+                _ => None,+            }?;++            let stmt_index = location.statement_index;+            // look behind for statement that assigns the local from a address of operator+            // 6 is chosen as a heuristic determined by seeing the number of times the optimization kicked in compiling rust std+            let lower_index = stmt_index.saturating_sub(6);+            let statements_to_look_in = self.body.basic_blocks()[location.block].statements+                [lower_index..stmt_index]+                .iter()+                .rev();+            for stmt in statements_to_look_in {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r))+                        if l.local == local_being_derefed =>+                    {+                        match r {+                            // looking for _local_being_deref = &_1;+                            Rvalue::Ref(+                                _,+                                BorrowKind::Shared | BorrowKind::Shallow,+                                place_taken_address_of,+                            ) => {+                                self.optimizations+                                    .unneeded_deref+                                    .insert(location, *place_taken_address_of);+                                return Some(());+                            }+                            _ => {+                                // we found an assignment of the place that is not a ref, e.g _local_being_derefed = _2;+                                // We therefore have to bail the optimization since the optimization is no longer valid+                                return None;+                            }+                        }+                    }+                    _ => {}

Cool. Yeah it should be possible to do this optimization without the lookback, such that a single statement is only visited once. I'll open a new pr for that.

Can we do a perf run on the current pr? I'm curious if this has any impact

simonvandel

comment created time in 8 days

PullRequestReviewEvent

pull request commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

simonvandel

comment created time in 8 days

pull request commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

I have rebased on master and added some more commits to cleanup the cfg and add storageDeads for temps that are introduced. The last commit also enables this pass temporarily on mir-opt-level=1 such that we can check how perf is affected.

Locally, this optimization fires 201 times on rustc-std.

simonvandel

comment created time in 8 days

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+- // MIR for `opt1` before EarlyOtherwiseBranch

I removed usize as input as a) I was tired of forgetting to update 32bit tests b) there was no point in testing different bitness

simonvandel

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentrust-lang/rust

New MIR optimization pass to reduce branches on match of tuples of enums

+- // MIR for `opt1` before EarlyOtherwiseBranch++ // MIR for `opt1` after EarlyOtherwiseBranch+  +  fn opt1(_1: std::option::Option<usize>, _2: std::option::Option<usize>) -> usize {+      debug x => _1;                       // in scope 0 at $DIR/early_otherwise_branch.rs:5:9: 5:10+      debug y => _2;                       // in scope 0 at $DIR/early_otherwise_branch.rs:5:27: 5:28+      let mut _0: usize;                   // return place in scope 0 at $DIR/early_otherwise_branch.rs:5:47: 5:52+      let mut _3: (std::option::Option<usize>, std::option::Option<usize>); // in scope 0 at $DIR/early_otherwise_branch.rs:6:11: 6:16+      let mut _4: std::option::Option<usize>; // in scope 0 at $DIR/early_otherwise_branch.rs:6:12: 6:13+      let mut _5: std::option::Option<usize>; // in scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15+      let mut _6: isize;                   // in scope 0 at $DIR/early_otherwise_branch.rs:7:19: 7:26+      let mut _7: isize;                   // in scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17+      let _8: usize;                       // in scope 0 at $DIR/early_otherwise_branch.rs:7:15: 7:16+      let _9: usize;                       // in scope 0 at $DIR/early_otherwise_branch.rs:7:24: 7:25++     let mut _10: isize;                  // in scope 0 at $DIR/early_otherwise_branch.rs:7:19: 7:26++     let mut _11: bool;                   // in scope 0 at $DIR/early_otherwise_branch.rs:7:19: 7:26+      scope 1 {+          debug a => _8;                   // in scope 1 at $DIR/early_otherwise_branch.rs:7:15: 7:16+          debug b => _9;                   // in scope 1 at $DIR/early_otherwise_branch.rs:7:24: 7:25+      }+  +      bb0: {+          StorageLive(_3);                 // scope 0 at $DIR/early_otherwise_branch.rs:6:11: 6:16+          StorageLive(_4);                 // scope 0 at $DIR/early_otherwise_branch.rs:6:12: 6:13+          _4 = _1;                         // scope 0 at $DIR/early_otherwise_branch.rs:6:12: 6:13+          StorageLive(_5);                 // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15+          _5 = _2;                         // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15+          (_3.0: std::option::Option<usize>) = move _4; // scope 0 at $DIR/early_otherwise_branch.rs:6:11: 6:16+          (_3.1: std::option::Option<usize>) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:6:11: 6:16+          StorageDead(_5);                 // scope 0 at $DIR/early_otherwise_branch.rs:6:15: 6:16+          StorageDead(_4);                 // scope 0 at $DIR/early_otherwise_branch.rs:6:15: 6:16+          _7 = discriminant((_3.0: std::option::Option<usize>)); // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17+-         switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17++         StorageLive(_10);                // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17++         _10 = discriminant((_3.1: std::option::Option<usize>)); // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17++         StorageLive(_11);                // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17++         _11 = Ne(_10, _7);               // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17++         StorageDead(_10);                // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17++         switchInt(move _11) -> [false: bb6, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:7:10: 7:17

It's been a while, but I finally looked at it again. I don't think it is that easy to use BitAnd to avoid the extra bb. See https://github.com/rust-lang/rust/pull/75119/files#diff-37f80fe71480f2b22fb8fd1fc103fda4R88 where we need to check both 0 and 1.

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

bors

commit sha 397db054cb1f3d98e3d2809d25c60f1979cd5a97

Auto merge of #75529 - bugadani:bounds-check, r=nagisa Eliminate some other bound checks when index comes from an enum #36962 introduced an assumption for the upper limit of the enum's value. This PR adds an assumption to the lower value as well. I've modified the original codegen test to show that derived (in that case, adding 1) values also don't generate bounds checks. However, this test is actually carefully crafted to not hit a bug: if the enum's variants are modified to 1 and 2 instead of 2 and 3, the test fails by adding a bounds check. I suppose this is an LLVM issue and #75525, while not exactly in this context should be tracking it. I'm not at all confident if this patch can be accepted, or even if it _should_ be accepted in this state. But I'm curious about what others think :) ~Improves~ Should improve #13926 but does not close it because it's not exactly predictable, where bounds checks may pop up against the assumptions.

view details

Takayuki Nakata

commit sha aa7ffa5257667edb284de16b529df3d4111d70ab

Fix FP in `same_item_push` Don't emit a lint when the pushed item doesn't have Clone trait

view details

CDirkx

commit sha ea5dc0909ea1ed4135f1bdecbaa3423051be578d

Make some Ordering methods const Constify the following methods of `core::cmp::Ordering`: - `reverse` - `then` Stabilizes these methods as const under the `const_ordering` feature. Also adds a test for these methods in a const context. Possible because of #49146 (Allow `if` and `match` in constants).

view details

Jon Gjengset

commit sha 010891f8b83d0795d8d92770755f0a0cc1d0a91d

Merge branch 'master' into stabilize-vecdeque-make_contiguous

view details

Jon Gjengset

commit sha 8b55360f702bc4a0b0bc9fdef51c36145303eea7

Will land in 1.48, not 1.47

view details

Mark Rousskov

commit sha d77c351c893b29167df0ccbfca3fe77334e7f89b

Move ninja requirements to a dynamic check, when actually building It isn't practical to determine whether we'll build LLVM very early in the pipeline, so move the ninja checking to a dynamic check.

view details

bors

commit sha 67e18c2d5cb56a7b34312265ec6d4c780028cfe9

Auto merge of #5993 - taiki-e:default_trait_access, r=phansch default_trait_access: Fix wrong suggestion https://github.com/rust-lang/rust-clippy/issues/5975#issuecomment-683751131 > I think the underlying problem is clippy suggests code with complete parameters, not clippy triggers this lint even for complex types. AFAIK, If code compiles with `Default::default`, it doesn't need to specify any parameters, as type inference is working. (So, in this case, `default_trait_access` should suggest `RefCell::default`.) Fixes #5975 Fixes #5990 changelog: `default_trait_access`: fixed wrong suggestion

view details

Denis Vasilik

commit sha 9c7fb6c44750af069bf382404adaa7a6287f9007

Use intra-doc links

view details

bors

commit sha 58d5ce4929ff4aee3d20973080e0391eb775f3d6

Auto merge of #76197 - Mark-Simulacrum:no-llvm-no-ninja, r=pietroalbini Move ninja requirements to a dynamic check, when actually building It isn't practical to determine whether we'll build LLVM very early in the pipeline, so move the ninja checking to a dynamic check. r? @pietroalbini -- this should fix nightlies

view details

Denis Vasilik

commit sha b639cb1e462757aa191060e68da5e0de54e9c016

Enhance wording Co-authored-by: Joshua Nelson <joshua@yottadb.com>

view details

CDirkx

commit sha b31cc8f83e7f50f54bffa93e909d51cdabf9f5fa

Make all methods of `std::net::Ipv6Addr` const Make the following methods of `std::net::Ipv6Addr` unstable const under the `const_ipv6` feature: - `segments` - `is_unspecified` - `is_loopback` - `is_global` (unstable) - `is_unique_local` - `is_unicast_link_local_strict` - `is_documentation` - `multicast_scope` - `is_multicast` - `to_ipv4_mapped` - `to_ipv4` Changed the implementation of `is_unspecified` and `is_loopback` to use a `match` instead of `==`. Part of #76205

view details

Denis Vasilik

commit sha e7d074392e560517546725e7e3ba5b3fe8978ee8

Use intra-doc links

view details

Joshua Nelson

commit sha ba664c258dd2f5516e987091a31acaa537312cf6

Codegen defaults come from rustc, not cargo

view details

Kornel

commit sha 7ec1de062a1aadef0293bb65e71fbcc7cc24ebfd

Clarify message about unresolved use

view details

CDirkx

commit sha ee9e48bafcc9667f08027e50ed84578e9861a456

Make methods unstable const under `const_ipv4`

view details

Mateusz Mikuła

commit sha 770231e54d0266406791bab1fda7e300d074ebda

Replace MinGW library hack with heuristic controlling link mode

view details

Denis Vasilik

commit sha 3510c568874eb1274805b25cfa5cc54aa1819030

Improve readability

view details

bors

commit sha eb9e7c357e26bf41c47661720e46f4498de32b83

Auto merge of #74559 - jonhoo:stabilize-vecdeque-make_contiguous, r=dtolnay Stabilize deque_make_contiguous Closes #70929. /cc @Amanieu

view details

Mark Rousskov

commit sha 77d4f94201df03df1e4f9a2ac133c994927e4cd2

Bump tracing

view details

Jes Bak Hansen

commit sha 7eb4b1b4b96642197b1bdeac4998d4d5f725f0cf

Document lint missing_doc_code_examples is nightly-only

view details

push time in 8 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 9146ed28290efe3e3743e8ba0d2a4dbe944d76fd

Update src/librustc_mir/transform/early_otherwise_branch.rs Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>

view details

push time in 8 days

Pull request review commentrust-lang/rust

Fix #76803 miscompilation

 impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {             .basic_blocks()             .iter_enumerated()             .filter_map(|(bb_idx, bb)| {-                let (discr_switched_on, targets) = match &bb.terminator().kind {-                    TerminatorKind::SwitchInt { targets, discr, .. } => (discr, targets),+                let (discr_switched_on, targets_and_values):(_, Vec<_>) = match &bb.terminator().kind {+                    TerminatorKind::SwitchInt { targets, discr, values, .. } => {+                        // if values.len() == targets.len() - 1, we need to include None where no value is present

Added in latest commit

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha a875c7a1ea31f86d4a796209f50303564ce15a16

Add assertion for len of vecs

view details

push time in 8 days

Pull request review commentrust-lang/rust

Add optimization to avoid load of address

 impl OptimizationFinder<'b, 'tcx> {         OptimizationFinder { body, tcx, optimizations: OptimizationList::default() }     } +    fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // look for the sequence+        // _2 = &_1;+        // ...+        // _5 = (*_2)+        //+        // which we can replace the last statement with `_5 = _1` to avoid the load of _2+        if let Rvalue::Use(op) = rvalue {+            let local_being_derefed = match op.place()?.as_ref() {+                PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),+                _ => None,+            }?;++            let stmt_index = location.statement_index;+            // look behind for statement that assigns the local from a address of operator+            // 6 is chosen as a heuristic determined by seeing the number of times the optimization kicked in compiling rust std+            let lower_index = stmt_index.saturating_sub(6);+            let statements_to_look_in = self.body.basic_blocks()[location.block].statements+                [lower_index..stmt_index]+                .iter()+                .rev();+            for stmt in statements_to_look_in {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r))+                        if l.local == local_being_derefed =>+                    {+                        match r {+                            // looking for _local_being_deref = &_1;+                            Rvalue::Ref(+                                _,+                                BorrowKind::Shared | BorrowKind::Shallow,+                                place_taken_address_of,+                            ) => {+                                self.optimizations+                                    .unneeded_deref+                                    .insert(location, *place_taken_address_of);+                                return Some(());+                            }+                            _ => {+                                // we found an assignment of the place that is not a ref, e.g _local_being_derefed = _2;+                                // We therefore have to bail the optimization since the optimization is no longer valid+                                return None;+                            }+                        }+                    }+                    _ => {}

The latest commits now check that local_being_derefed is not mutated using a visitor. I have verified that setting the lookback to 10000 causes a misoptimization without the fix, and fixes it with the fix. I have set it back to to avoid bad runtime complexity. I'm not sure how best to represent that the fix is actually working. For now I separated it into two commits.

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 8f41ea4a4c73bfb014e9123805241e448b5ad027

Use visitor to check mutating use instead of adhoc matching

view details

Simon Vandel Sillesen

commit sha 116283b910a7f8809260ba91cb9b9b647a8900a3

Switch back to 6

view details

push time in 8 days

Pull request review commentrust-lang/rust

Add optimization to avoid load of address

 impl OptimizationFinder<'b, 'tcx> {         OptimizationFinder { body, tcx, optimizations: OptimizationList::default() }     } +    fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // look for the sequence+        // _2 = &_1;+        // ...+        // _5 = (*_2)+        //+        // which we can replace the last statement with `_5 = _1` to avoid the load of _2+        if let Rvalue::Use(op) = rvalue {+            let local_being_derefed = match op.place()?.as_ref() {+                PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),+                _ => None,+            }?;++            let stmt_index = location.statement_index;+            // look behind for statement that assigns the local from a address of operator+            // 6 is chosen as a heuristic determined by seeing the number of times the optimization kicked in compiling rust std+            let lower_index = stmt_index.saturating_sub(6);+            let statements_to_look_in = self.body.basic_blocks()[location.block].statements+                [lower_index..stmt_index]+                .iter()+                .rev();+            for stmt in statements_to_look_in {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r))+                        if l.local == local_being_derefed =>+                    {+                        match r {+                            // looking for _local_being_deref = &_1;+                            Rvalue::Ref(+                                _,+                                BorrowKind::Shared | BorrowKind::Shallow,+                                place_taken_address_of,+                            ) => {+                                self.optimizations+                                    .unneeded_deref+                                    .insert(location, *place_taken_address_of);+                                return Some(());+                            }+                            _ => {+                                // we found an assignment of the place that is not a ref, e.g _local_being_derefed = _2;+                                // We therefore have to bail the optimization since the optimization is no longer valid+                                return None;+                            }+                        }+                    }+                    _ => {}

Ah, I saw your comment a tad too late. I already pushed a fix, but i'll see if it is cleaner/less adhoc to use the visitor. Thanks for the hint.

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 356be417e83f281c76ae21469cb4698a655886f0

Set lookback high to demonstrate miscompilation

view details

Simon Vandel Sillesen

commit sha 8d5b55fb2098e12ce4db4579c01767e7f402c486

Fix miscompilation with mutable reference from rhs

view details

Simon Vandel Sillesen

commit sha 9cc21a0a05939e99eecd17013a959155f12f8591

Set lookback back to 6

view details

push time in 8 days

Pull request review commentrust-lang/rust

Add optimization to avoid load of address

 impl OptimizationFinder<'b, 'tcx> {         OptimizationFinder { body, tcx, optimizations: OptimizationList::default() }     } +    fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // look for the sequence+        // _2 = &_1;+        // ...+        // _5 = (*_2)+        //+        // which we can replace the last statement with `_5 = _1` to avoid the load of _2+        if let Rvalue::Use(op) = rvalue {+            let local_being_derefed = match op.place()?.as_ref() {+                PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),+                _ => None,+            }?;++            let stmt_index = location.statement_index;+            // look behind for statement that assigns the local from a address of operator+            // 6 is chosen as a heuristic determined by seeing the number of times the optimization kicked in compiling rust std+            let lower_index = stmt_index.saturating_sub(6);+            let statements_to_look_in = self.body.basic_blocks()[location.block].statements+                [lower_index..stmt_index]+                .iter()+                .rev();+            for stmt in statements_to_look_in {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r))+                        if l.local == local_being_derefed =>+                    {+                        match r {+                            // looking for _local_being_deref = &_1;+                            Rvalue::Ref(+                                _,+                                BorrowKind::Shared | BorrowKind::Shallow,+                                place_taken_address_of,+                            ) => {+                                self.optimizations+                                    .unneeded_deref+                                    .insert(location, *place_taken_address_of);+                                return Some(());+                            }+                            _ => {+                                // we found an assignment of the place that is not a ref, e.g _local_being_derefed = _2;+                                // We therefore have to bail the optimization since the optimization is no longer valid+                                return None;+                            }+                        }+                    }+                    _ => {}

You are correct. Setting the lookback higher does indeed cause a miscompilation. I'll look into fixing it.

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha fb2f32ae4be431acf4c5347bca8dbba0f7c0892b

Apply suggestions from code review Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>

view details

push time in 8 days

Pull request review commentrust-lang/rust

Add optimization to avoid load of address

 impl OptimizationFinder<'b, 'tcx> {         OptimizationFinder { body, tcx, optimizations: OptimizationList::default() }     } +    fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // look for the sequence+        // _2 = &_1;+        // ...+        // _5 = (*_2)+        //+        // which we can replace the last statement with `_5 = _1` to avoid the load of _2+        if let Rvalue::Use(op) = rvalue {+            let local_being_derefed = match op.place()?.as_ref() {+                PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),+                _ => None,+            }?;++            let stmt_index = location.statement_index;+            // look behind for statement that assigns the local from a address of operator+            // 6 is chosen as a heuristic determined by seeing the number of times the optimization kicked in compiling rust std+            let lower_index = stmt_index.saturating_sub(6);+            let statements_to_look_in = self.body.basic_blocks()[location.block].statements+                [lower_index..stmt_index]+                .iter()+                .rev();+            for stmt in statements_to_look_in {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r))+                        if l.local == local_being_derefed =>+                    {+                        match r {+                            // looking for _local_being_deref = &_1;+                            Rvalue::Ref(+                                _,+                                BorrowKind::Shared | BorrowKind::Shallow,+                                place_taken_address_of,+                            ) => {+                                self.optimizations+                                    .unneeded_deref+                                    .insert(location, *place_taken_address_of);+                                return Some(());+                            }+                            _ => {+                                // we found an assignment of the place that is not a ref, e.g _local_being_derefed = _2;+                                // We therefore have to bail the optimization since the optimization is no longer valid+                                return None;+                            }+                        }+                    }+                    _ => {}

I added a test for this. It does not seem like it will misfire. I also added more clarifying comments on the matches. I have persuaded myself that since we are only applying this optimization on immutable references, we can't have a mutable reference at the same time, so nothing (besides asm) can break this optimization. My reasoning may be wrong though..

simonvandel

comment created time in 8 days

PullRequestReviewEvent

Pull request review commentrust-lang/rust

Add optimization to avoid load of address

 impl OptimizationFinder<'b, 'tcx> {         OptimizationFinder { body, tcx, optimizations: OptimizationList::default() }     } +    fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {+        // look for the sequence+        // _2 = &_1;+        // ...+        // _5 = (*_2)+        //+        // which we can replace the last statement with `_5 = _1` to avoid the load of _2+        if let Rvalue::Use(op) = rvalue {+            let local_being_derefed = match op.place()?.as_ref() {+                PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),+                _ => None,+            }?;++            let stmt_index = location.statement_index;+            // look behind for statement that assigns the local from a address of operator+            // 6 is chosen as a heuristic determined by seeing the number of times the optimization kicked in compiling rust std+            let lower_index = stmt_index.saturating_sub(6);+            let statements_to_look_in = self.body.basic_blocks()[location.block].statements+                [lower_index..stmt_index]+                .iter()+                .rev();+            for stmt in statements_to_look_in {+                match &stmt.kind {+                    rustc_middle::mir::StatementKind::Assign(box (l, r))

I added exhaustive matches, and now bail on ASM

simonvandel

comment created time in 8 days

PullRequestReviewEvent

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 9e5bd7899a18e3832ad5fe210b941a9db15bb99b

wording in comments

view details

Simon Vandel Sillesen

commit sha fd6678e9f538c0e7a977825a824c8fabb8167ad1

Add test for suspicion of miscompilation

view details

Simon Vandel Sillesen

commit sha e80310c9597efe7ed1998546a9d195e856b25381

Exhaustively check statements, and clarify soundness with comments

view details

push time in 8 days

pull request commentrust-lang/rust

Fix #76803 miscompilation

Rebased @rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

simonvandel

comment created time in 9 days

push eventsimonvandel/rust

Mara Bos

commit sha 1016deb592cec6d02e963bb3ffbfbb2c4f9309b8

Small cleanups in Windows Mutex. - Move `held` into the boxed part, since the SRW lock implementation does not use this. This makes the Mutex 50% smaller. - Use `Cell` instead of `UnsafeCell` for `held`, such that `.replace()` can be used. - Add some comments.

view details

Stein Somers

commit sha 378b64392f5bdbcffbdc6506b00b6bfcfcd46d73

BTreeMap: avoid slices even more

view details

Mara Bos

commit sha 3fadc603ab3fba157dfa7001fd9122692f40746a

Don't use `mut` in Windows Mutex.

view details

Mara Bos

commit sha 0bb96e7490299977abf2d3af16dd752d67ca43a9

Avoid creating `&mut`s in Windows ReentrantMutex.

view details

Lzu Tao

commit sha 9fe9c6da3e7d1d71b6fcb9d99a29ccba8decf04e

Using <Iter>::new instead of exposing internal fields

view details

Wesley Wiser

commit sha dbd7226d299ac23647975068bea1168cf56e0feb

[mir-opt] Disable the `ConsideredEqual` logic in SimplifyBranchSame opt The logic is currently broken and we need to disable it to fix a beta regression (see #76803)

view details

bors

commit sha f3c923a13a458c35ee26b3513533fce8a15c9c05

Auto merge of #76645 - fusion-engineering-forks:windows-lock, r=kennytm Small cleanups in Windows Mutex. - Move `held` into the boxed part, since the SRW lock implementation does not use this. This makes the Mutex 50% smaller. - Use `Cell` instead of `UnsafeCell` for `held`, such that `.replace()` can be used. - Add some comments. - Avoid creating multiple `&mut`s to the critical section object in `ReentrantMutex`.

view details

Nixon Enraght-Moony

commit sha 076e52d0c9cb7856186d33203e33e04a3db898c4

Put bit qualifier before mir/diff

view details

Nixon Enraght-Moony

commit sha 4f23cec3f917143c7d6c52825f867a21f642beec

Rename 64 bit mir files to be more tool friendly See #75746

view details

Nixon Enraght-Moony

commit sha 3c7593e69ffaf3362a598f1c359829387365bd98

Rename 32 bit mir files to be more tool friendly See #75746

view details

Jonas Schievink

commit sha ee1e9343b35c169a100654a511e21c47eb2cb0bc

Distribute rustc sources as part of `rustc-dev`

view details

Nixon Enraght-Moony

commit sha 735776d115e7e842a0c52f70a181ac9211003d55

Fix --bless for mir-opt 32/64 bit file

view details

Valerii Lashmanov

commit sha 2f3296192bb5be5fcb02975395052ee8c3b2bd68

Only visit types once when walking the type tree This fixes #72408. Nested closures were resulting in exponential compilation time. As a performance optimization this change introduces MiniSet, which is a simple small storage optimized set.

view details

Valerii Lashmanov

commit sha 17d2e3b5d208d29d156ff94f112b5bc95acee351

Better handling for exponential-sized types in misc places Mostly to fix ui/issues/issue-37311-type-length-limit/issue-37311.rs. Most parts of the compiler can handle deeply nested types with a lot of duplicates just fine, but some parts still attempt to naively traverse type tree. Before such problems were caught by type length limit check, but now these places will have to be changed to handle duplicated types gracefully.

view details

Valerii Lashmanov

commit sha f583513dc2ad48076665505a1418db6053657f0b

Intorduced MiniMap - a tiny small storage optimized map implementation This makes everything about 1% faster in rustc-perf, mostly negating performance hit of previous commit.

view details

Lzu Tao

commit sha 2818032a2dee83b0b58318828e666e404838c8d9

Calculate more correct capacity in merge_attrs Co-authored-by: jyn514 <joshua@yottadb.com>

view details

est31

commit sha 5acfcceb47609862bba7035cf1cbfd807918dd36

Dogfood new_uninit and maybe_uninit_slice in rustc_arena

view details

est31

commit sha daccd1709ef1913e23d1b2f15dfeb16ac6e70ed8

Replace loop with drop_in_place call

view details

est31

commit sha 2805a0515461d6f70f7d4a6c1f5491dbed5d61b8

Add bench_typed_arena_clear_100 bench

view details

bors

commit sha a0925fba747b4cf910592540aa1f817778dc315c

Auto merge of #76790 - ssomers:btree_slice_slasher_returns, r=Mark-Simulacrum BTreeMap: avoid slices even more Epilogue to #73971: it seems the compiler is unable to realize that creating a slice and `get_unchecked`-ing one element is a simple fetch. So try to spell it out for the only remaining but often invoked case. Also, the previous code doesn't seem fair game to me, using `get_unchecked` to reach beyond the end of a slice. Although the local function `slice_insert` also does that. r? `@Mark-Simulacrum`

view details

push time in 9 days

pull request commentrust-lang/rust

MIR pass to remove unneeded drops on types not needing drop

Hi @oli-obk I pushed some cleanup and your suggestion for running simplify-cfg after the optimization.

Note that on mir-opt-level=1 this pass really does nothing as the inliner is not running.

one thing I'm wondering is whether we should/could just rerun drop elaboration after inlining... That would catch even more cases, but may be expensive.

I suggest handling that in another issue. Do you want to elaborate on it yourself in another issue?

simonvandel

comment created time in 9 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 673935fc0c8cbb4925e4fa0c936e4340aa818be0

Get LocalDefId from source instead of passing in

view details

Simon Vandel Sillesen

commit sha 30dd6cf9ba472d4ff12c9a28d03e3a61d54e34da

The optimization should also apply for DropAndReplace

view details

Simon Vandel Sillesen

commit sha 804f673762d732198e5023be6fa8f1e305e2c2ad

cleanup cfg after optimization

view details

push time in 9 days

PR opened rust-lang/rust

Fix #76803 miscompilation

Seems like it was an oversight that the discriminant value being set was not compared to the target value from the SwitchInt

r? @wesleywiser since you are probably familiar with the optimization and made #76837 to workaround the bug

+79 -15

0 comment

3 changed files

pr created time in 11 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 2fcea07e94dbe99d9694b8ae124b33f7cd8fbcb8

Fix #76803 Check that the variant index matches the target value from the SwitchInt we came from

view details

push time in 11 days

push eventsimonvandel/rust

Simon Vandel Sillesen

commit sha 0c47374d6d81c8a6351d59c3dbe9f22e8964ab9d

Fix #76803 Check that the variant index matches the target value from the SwitchInt we came from

view details

push time in 11 days

create barnchsimonvandel/rust

branch : fix-76803

created branch time in 11 days

pull request commentrust-lang/rust

MIR-opt: Generalize &(*_1) optimization to mutable references

Thanks. The results surprise me. I'm wondering if things have changed since then - it seemed like the observed changes could be explained by different CGU partitioning. Taking your rustc experience in mind, do you think it is worth continuing with this PR, or should I just close it?

simonvandel

comment created time in 11 days

pull request commentrust-lang/rust

MIR-opt: Generalize &(*_1) optimization to mutable references

I'm curious about the measured performance and couldn't find anything on https://github.com/rust-lang/rust/pull/72093. Do you remember where the perf run was performed?

simonvandel

comment created time in 11 days

pull request commentrust-lang/rust

MIR-opt: Generalize &(*_1) optimization to mutable references

So the problem is that it is only valid to optimize _2 = &mut (*_1) into _2 = move _1 iff _1 is not used later on? I'm not that familiar with the dataflow analysises. How difficult is it to check if _1 has later uses?

Alternatively, I'll close this PR - but it's more fun to drive this to something sound :)

simonvandel

comment created time in 11 days

pull request commentrust-lang/rust

MIR-opt: Generalize &(*_1) optimization to mutable references

Hmm I just saw https://github.com/rust-lang/rust/commit/309661e84f04bedb247f42331b144a8d5ad9338d where this was reverted. Not sure why yet

simonvandel

comment created time in 11 days

PR opened rust-lang/rust

MIR-opt: Generalize &(*_1) optimization to mutable references

Running RUSTC_LOG=rustc_mir::transform::instcombine ./x.py test --stage 1 src/test/mir-opt --bless | grep "replacing \`&mut*" | wc -l yields 10601, so it seems to be a fairly usable optimization on rust-std.

+129 -29

0 comment

9 changed files

pr created time in 11 days

more