Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[perf] Enable some more MIR optimizations #111061

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
dca02d6
Enable DestinationPropagation by default.
cjgillot Apr 30, 2023
fce6510
Fold consecutive PtrToPtr casts.
cjgillot Oct 11, 2023
7bfb31f
Simplify operands in unions.
cjgillot Oct 31, 2023
44c48d7
Compute unsizing casts in GVN.
cjgillot Dec 17, 2023
cf3ad0e
Compute binary ops between pointers in GVN.
cjgillot Jan 16, 2024
aa05458
Split gvn wide ptr tests.
cjgillot Dec 30, 2023
a6441a6
Perform GVN into debuginfo.
cjgillot Jun 5, 2023
0167761
Const-prop pointers.
cjgillot Jan 6, 2024
47cb509
Dest prop: Support removing writes when this unblocks optimizations
JakobDegen Dec 17, 2022
31e8901
Dest prop: Separate writes to remove into separate data structure in …
JakobDegen Dec 18, 2022
a2cc501
GVN borrowed locals too.
cjgillot Dec 30, 2023
375263d
Merge borrowed locals too.
cjgillot Jan 2, 2024
8e5a9e4
Dereference immutable borrows in GVN.
cjgillot Jan 5, 2024
f5def50
Bless coverage.
cjgillot Jan 16, 2024
8429c25
Enable by default.
cjgillot Jan 18, 2023
d402dc7
Remove ConstGoto and SeparateConstSwitch.
cjgillot Feb 26, 2023
fb38ce6
Reimplement references debuginfo as projection.
cjgillot Aug 26, 2023
ac932b7
Add assume statements in NonZero library types.
cjgillot Oct 15, 2023
e445d0d
Lower inling cost for a statement.
cjgillot Oct 15, 2023
26a6f6f
INSTR_COST=2.
cjgillot Dec 30, 2023
f9c1799
INSTR_COST=1.
cjgillot Dec 30, 2023
25d8366
Limit recursion in terms of places.
cjgillot Jan 14, 2024
7386a8b
Enable DataflowConstProp by default.
cjgillot Oct 22, 2023
0b3a2e8
Merge branch 'dest-prop-move'
cjgillot Jan 19, 2024
532ade3
Merge branch 'gvn-borrowed'
cjgillot Jan 19, 2024
655d7ae
Merge branch 'jump-threading-default'
cjgillot Jan 19, 2024
b0a57b4
Merge branch 'mir-composite-deref'
cjgillot Jan 19, 2024
6d1fdaa
Merge branch 'cheap-stmt'
cjgillot Jan 19, 2024
aacb6b5
Merge branch 'enable-dcp'
cjgillot Jan 19, 2024
19aaef4
Reorder MIR passes.
cjgillot Feb 5, 2023
879be36
InstSimplify calls to constructors.
cjgillot May 16, 2023
83162cd
SROA short arrays too.
cjgillot Jun 24, 2023
4a591aa
Fortify codegen test.
cjgillot Sep 24, 2023
e792ee8
Add more simplify passes.
cjgillot Sep 24, 2023
5f1fd2f
Add test.
cjgillot Oct 3, 2023
d192eb0
Merge places for debuginfo.
cjgillot Jan 19, 2024
0c2525b
Also address in debuginfo.
cjgillot Oct 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable DataflowConstProp by default.
  • Loading branch information
cjgillot committed Jan 19, 2024
commit 7386a8b0fbbc00f3379e7956b0dc92bffd932382
7 changes: 1 addition & 6 deletions compiler/rustc_mir_transform/src/dataflow_const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,18 @@ use crate::const_prop::throw_machine_stop_str;

// These constants are somewhat random guesses and have not been optimized.
// If `tcx.sess.mir_opt_level() >= 4`, we ignore the limits (this can become very expensive).
const BLOCK_LIMIT: usize = 100;
const PLACE_LIMIT: usize = 100;

pub struct DataflowConstProp;

impl<'tcx> MirPass<'tcx> for DataflowConstProp {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.mir_opt_level() >= 3
sess.mir_opt_level() >= 2
}

#[instrument(skip_all level = "debug")]
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
debug!(def_id = ?body.source.def_id());
if tcx.sess.mir_opt_level() < 4 && body.basic_blocks.len() > BLOCK_LIMIT {
debug!("aborted dataflow const prop due too many basic blocks");
return;
}

// We want to have a somewhat linear runtime w.r.t. the number of statements/terminators.
// Let's call this number `n`. Dataflow analysis has `O(h*n)` transfer function
Expand Down
36 changes: 14 additions & 22 deletions tests/coverage/closure.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,16 @@ Number of file 0 mappings: 24
- Code(Expression(1, Add)) at (prev + 1, 5) to (start + 3, 2)
= (c1 + (c0 - c1))

Function name: closure::main::{closure#0}
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 27, 05, 02, 14, 05, 02, 15, 02, 0a, 02, 02, 0a, 00, 0b, 07, 01, 09, 01, 06]
Function name: closure::main::{closure#0} (unused)
Raw bytes (24): 0x[01, 01, 00, 04, 00, 27, 05, 02, 14, 00, 02, 15, 02, 0a, 00, 02, 0a, 00, 0b, 00, 01, 09, 01, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 2
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of expressions: 0
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 39, 5) to (start + 2, 20)
- Code(Counter(1)) at (prev + 2, 21) to (start + 2, 10)
- Code(Expression(0, Sub)) at (prev + 2, 10) to (start + 0, 11)
= (c0 - c1)
- Code(Expression(1, Add)) at (prev + 1, 9) to (start + 1, 6)
= (c1 + (c0 - c1))
- Code(Zero) at (prev + 39, 5) to (start + 2, 20)
- Code(Zero) at (prev + 2, 21) to (start + 2, 10)
- Code(Zero) at (prev + 2, 10) to (start + 0, 11)
- Code(Zero) at (prev + 1, 9) to (start + 1, 6)

Function name: closure::main::{closure#10} (unused)
Raw bytes (10): 0x[01, 01, 00, 01, 00, 9a, 01, 07, 00, 21]
Expand Down Expand Up @@ -148,20 +144,16 @@ Number of file 0 mappings: 6
- Code(Expression(0, Add)) at (prev + 2, 9) to (start + 0, 10)
= (c1 + (c0 - c1))

Function name: closure::main::{closure#18}
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 18, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 12, 00, 13, 07, 01, 11, 01, 0e]
Function name: closure::main::{closure#18} (unused)
Raw bytes (24): 0x[01, 01, 00, 04, 00, 18, 0d, 02, 1c, 00, 02, 1d, 02, 12, 00, 02, 12, 00, 13, 00, 01, 11, 01, 0e]
Number of files: 1
- file 0 => global file 1
Number of expressions: 2
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of expressions: 0
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 24, 13) to (start + 2, 28)
- Code(Counter(1)) at (prev + 2, 29) to (start + 2, 18)
- Code(Expression(0, Sub)) at (prev + 2, 18) to (start + 0, 19)
= (c0 - c1)
- Code(Expression(1, Add)) at (prev + 1, 17) to (start + 1, 14)
= (c1 + (c0 - c1))
- Code(Zero) at (prev + 24, 13) to (start + 2, 28)
- Code(Zero) at (prev + 2, 29) to (start + 2, 18)
- Code(Zero) at (prev + 2, 18) to (start + 0, 19)
- Code(Zero) at (prev + 1, 17) to (start + 1, 14)

Function name: closure::main::{closure#19}
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 42, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 12, 00, 13, 07, 01, 11, 01, 0e]
Expand Down
Loading