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

Invalidate all dereferences when encountering non-local assignments #132527

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions compiler/rustc_data_structures/src/fx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
pub type IndexEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
pub type IndexOccupiedEntry<'a, K, V> = indexmap::map::OccupiedEntry<'a, K, V>;

pub use indexmap::set::MutableValues;

#[macro_export]
macro_rules! define_id_collections {
($map_name:ident, $set_name:ident, $entry_name:ident, $key:ty) => {
Expand Down
180 changes: 98 additions & 82 deletions compiler/rustc_mir_transform/src/gvn.rs

Large diffs are not rendered by default.

38 changes: 0 additions & 38 deletions compiler/rustc_mir_transform/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ pub(super) struct SsaLocals {
borrowed_locals: DenseBitSet<Local>,
}

pub(super) enum AssignedValue<'a, 'tcx> {
Arg,
Rvalue(&'a mut Rvalue<'tcx>),
Terminator,
}

impl SsaLocals {
pub(super) fn new<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -152,38 +146,6 @@ impl SsaLocals {
})
}

pub(super) fn for_each_assignment_mut<'tcx>(
&self,
basic_blocks: &mut IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
mut f: impl FnMut(Local, AssignedValue<'_, 'tcx>, Location),
) {
for &local in &self.assignment_order {
match self.assignments[local] {
Set1::One(DefLocation::Argument) => f(
local,
AssignedValue::Arg,
Location { block: START_BLOCK, statement_index: 0 },
),
Set1::One(DefLocation::Assignment(loc)) => {
let bb = &mut basic_blocks[loc.block];
// `loc` must point to a direct assignment to `local`.
let stmt = &mut bb.statements[loc.statement_index];
let StatementKind::Assign(box (target, ref mut rvalue)) = stmt.kind else {
bug!()
};
assert_eq!(target.as_local(), Some(local));
f(local, AssignedValue::Rvalue(rvalue), loc)
}
Set1::One(DefLocation::CallReturn { call, .. }) => {
let bb = &mut basic_blocks[call];
let loc = Location { block: call, statement_index: bb.statements.len() };
f(local, AssignedValue::Terminator, loc)
}
_ => {}
}
}
}

/// Compute the equivalence classes for locals, based on copy statements.
///
/// The returned vector maps each local to the one it copies. In the following case:
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen/clone_as_copy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//@ revisions: DEBUGINFO NODEBUGINFO
//@ compile-flags: -Zunsound-mir-opts
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes
//@ [DEBUGINFO] compile-flags: -Cdebuginfo=full

Expand Down
17 changes: 11 additions & 6 deletions tests/codegen/try_question_mark_nop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ use std::ptr::NonNull;
#[no_mangle]
pub fn option_nop_match_32(x: Option<u32>) -> Option<u32> {
// CHECK: start:
// TWENTY-NEXT: %trunc = trunc nuw i32 %0 to i1
// TWENTY-NEXT: %.2 = select i1 %trunc, i32 %1, i32 undef
// CHECK-NEXT: [[REG1:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %1, 1
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } [[REG1]], i32 %.2, 1
// CHECK-NEXT: ret { i32, i32 } [[REG2]]
// CHECK-NEXT: [[TRUNC:%.*]] = trunc nuw i32 %0 to i1

// NINETEEN-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i32 %0, i32 0
// NINETEEN-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } poison, i32 [[SELECT]], 0
// NINETEEN-NEXT: [[REG3:%.*]] = insertvalue { i32, i32 } [[REG2]], i32 %1, 1

// TWENTY-NEXT: [[SELECT:%.*]] = select i1 [[TRUNC]], i32 %1, i32 undef
// TWENTY-NEXT: [[REG2:%.*]] = insertvalue { i32, i32 } poison, i32 %0, 0
// TWENTY-NEXT: [[REG3:%.*]] = insertvalue { i32, i32 } [[REG2]], i32 [[SELECT]], 1

// CHECK-NEXT: ret { i32, i32 } [[REG3]]
match x {
Some(x) => Some(x),
None => None,
Expand Down
18 changes: 8 additions & 10 deletions tests/coverage/closure.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,17 @@ Number of file 0 mappings: 6
- Code(Counter(0)) at (prev + 2, 9) to (start + 0, 10)
Highest counter ID seen: c1

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

Function name: closure::main::{closure#19}
Raw bytes (26): 0x[01, 01, 01, 01, 05, 04, 01, 43, 0d, 02, 1c, 05, 02, 1d, 02, 12, 02, 02, 11, 00, 12, 01, 01, 11, 01, 0e]
Expand Down
163 changes: 67 additions & 96 deletions tests/coverage/issue-84561.cov-map
Original file line number Diff line number Diff line change
Expand Up @@ -59,109 +59,80 @@ Number of file 0 mappings: 1
Highest counter ID seen: c0

Function name: issue_84561::test3
Raw bytes (315): 0x[01, 01, 1b, 1d, 21, 25, 29, 21, 25, 2d, 31, 21, 17, 25, 2d, 41, 45, 49, 4d, 51, 55, 33, 51, 49, 4d, 33, 37, 49, 4d, 51, 59, 55, 59, 55, 59, 47, 5d, 55, 59, 61, 65, 71, 75, 69, 6d, 69, 6d, 69, 6d, 63, 79, 71, 75, 79, 7d, 7d, 81, 01, 33, 01, 08, 01, 03, 1c, 05, 04, 09, 01, 1c, 09, 02, 05, 04, 1f, 0d, 05, 05, 00, 1f, 11, 01, 05, 00, 1f, 15, 01, 09, 01, 1c, 19, 02, 05, 00, 1f, 1d, 01, 05, 00, 0f, 02, 00, 20, 00, 30, 21, 01, 05, 03, 0f, 25, 03, 20, 00, 30, 29, 00, 33, 00, 41, 06, 00, 4b, 00, 5a, 0a, 01, 05, 00, 0f, 2d, 05, 09, 03, 10, 31, 05, 0d, 00, 1b, 0e, 02, 0d, 00, 1c, 12, 04, 09, 05, 06, 35, 06, 05, 03, 06, 39, 04, 05, 03, 06, 3d, 04, 09, 04, 06, 41, 05, 08, 00, 0f, 45, 01, 09, 03, 0a, 1a, 05, 09, 03, 0a, 33, 05, 08, 00, 0f, 51, 01, 09, 00, 13, 22, 03, 0d, 00, 1d, 26, 03, 09, 00, 13, 2e, 03, 0d, 00, 1d, 47, 03, 05, 00, 0f, 47, 01, 0c, 00, 13, 5d, 01, 0d, 00, 13, 42, 02, 0d, 00, 13, 61, 04, 05, 02, 13, 65, 03, 0d, 00, 13, 4a, 02, 0d, 00, 13, 63, 03, 05, 00, 0f, 69, 01, 0c, 00, 13, 6d, 01, 0d, 03, 0e, 71, 04, 0d, 00, 13, 5a, 02, 0d, 00, 17, 5a, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, 5a, 02, 15, 00, 1b, 75, 04, 0d, 00, 13, 5e, 03, 09, 00, 19, 79, 02, 05, 00, 0f, 66, 03, 09, 00, 22, 7d, 02, 05, 00, 0f, 6a, 03, 09, 00, 2c, 81, 01, 02, 01, 00, 02]
Raw bytes (279): 0x[01, 01, 0a, 0d, 11, 0d, 15, 0d, 19, 1d, 21, 29, 2d, 25, 29, 25, 29, 25, 29, 27, 31, 29, 2d, 33, 01, 08, 01, 03, 1c, 05, 04, 09, 01, 1c, 09, 02, 05, 04, 1f, 09, 05, 05, 00, 1f, 09, 01, 05, 00, 1f, 09, 01, 09, 01, 1c, 0d, 02, 05, 00, 1f, 0d, 01, 05, 00, 0f, 00, 00, 20, 00, 30, 0d, 01, 05, 03, 0f, 00, 03, 20, 00, 30, 00, 00, 33, 00, 41, 00, 00, 4b, 00, 5a, 0d, 01, 05, 00, 0f, 00, 05, 09, 03, 10, 00, 05, 0d, 00, 1b, 00, 02, 0d, 00, 1c, 0d, 04, 09, 05, 06, 0d, 06, 05, 03, 06, 0d, 04, 05, 03, 06, 0d, 04, 09, 04, 06, 0d, 05, 08, 00, 0f, 11, 01, 09, 03, 0a, 02, 05, 09, 03, 0a, 0d, 05, 08, 00, 0f, 15, 01, 09, 00, 13, 00, 03, 0d, 00, 1d, 06, 03, 09, 00, 13, 00, 03, 0d, 00, 1d, 0d, 03, 05, 00, 0f, 0d, 01, 0c, 00, 13, 19, 01, 0d, 00, 13, 0a, 02, 0d, 00, 13, 1d, 04, 05, 02, 13, 21, 03, 0d, 00, 13, 0e, 02, 0d, 00, 13, 27, 03, 05, 00, 0f, 25, 01, 0c, 00, 13, 29, 01, 0d, 03, 0e, 29, 04, 0d, 00, 13, 1e, 02, 0d, 00, 17, 1e, 01, 14, 00, 1b, 00, 01, 15, 00, 1b, 1e, 02, 15, 00, 1b, 2d, 04, 0d, 00, 13, 22, 03, 09, 00, 19, 31, 02, 05, 00, 0f, 31, 03, 09, 00, 22, 00, 02, 05, 00, 0f, 00, 03, 09, 00, 2c, 00, 02, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 27
- expression 0 operands: lhs = Counter(7), rhs = Counter(8)
- expression 1 operands: lhs = Counter(9), rhs = Counter(10)
- expression 2 operands: lhs = Counter(8), rhs = Counter(9)
- expression 3 operands: lhs = Counter(11), rhs = Counter(12)
- expression 4 operands: lhs = Counter(8), rhs = Expression(5, Add)
- expression 5 operands: lhs = Counter(9), rhs = Counter(11)
- expression 6 operands: lhs = Counter(16), rhs = Counter(17)
- expression 7 operands: lhs = Counter(18), rhs = Counter(19)
- expression 8 operands: lhs = Counter(20), rhs = Counter(21)
- expression 9 operands: lhs = Expression(12, Add), rhs = Counter(20)
- expression 10 operands: lhs = Counter(18), rhs = Counter(19)
- expression 11 operands: lhs = Expression(12, Add), rhs = Expression(13, Add)
- expression 12 operands: lhs = Counter(18), rhs = Counter(19)
- expression 13 operands: lhs = Counter(20), rhs = Counter(22)
- expression 14 operands: lhs = Counter(21), rhs = Counter(22)
- expression 15 operands: lhs = Counter(21), rhs = Counter(22)
- expression 16 operands: lhs = Expression(17, Add), rhs = Counter(23)
- expression 17 operands: lhs = Counter(21), rhs = Counter(22)
- expression 18 operands: lhs = Counter(24), rhs = Counter(25)
- expression 19 operands: lhs = Counter(28), rhs = Counter(29)
- expression 20 operands: lhs = Counter(26), rhs = Counter(27)
- expression 21 operands: lhs = Counter(26), rhs = Counter(27)
- expression 22 operands: lhs = Counter(26), rhs = Counter(27)
- expression 23 operands: lhs = Expression(24, Add), rhs = Counter(30)
- expression 24 operands: lhs = Counter(28), rhs = Counter(29)
- expression 25 operands: lhs = Counter(30), rhs = Counter(31)
- expression 26 operands: lhs = Counter(31), rhs = Counter(32)
Number of expressions: 10
- expression 0 operands: lhs = Counter(3), rhs = Counter(4)
- expression 1 operands: lhs = Counter(3), rhs = Counter(5)
- expression 2 operands: lhs = Counter(3), rhs = Counter(6)
- expression 3 operands: lhs = Counter(7), rhs = Counter(8)
- expression 4 operands: lhs = Counter(10), rhs = Counter(11)
- expression 5 operands: lhs = Counter(9), rhs = Counter(10)
- expression 6 operands: lhs = Counter(9), rhs = Counter(10)
- expression 7 operands: lhs = Counter(9), rhs = Counter(10)
- expression 8 operands: lhs = Expression(9, Add), rhs = Counter(12)
- expression 9 operands: lhs = Counter(10), rhs = Counter(11)
Number of file 0 mappings: 51
- Code(Counter(0)) at (prev + 8, 1) to (start + 3, 28)
- Code(Counter(1)) at (prev + 4, 9) to (start + 1, 28)
- Code(Counter(2)) at (prev + 2, 5) to (start + 4, 31)
- Code(Counter(3)) at (prev + 5, 5) to (start + 0, 31)
- Code(Counter(4)) at (prev + 1, 5) to (start + 0, 31)
- Code(Counter(5)) at (prev + 1, 9) to (start + 1, 28)
- Code(Counter(6)) at (prev + 2, 5) to (start + 0, 31)
- Code(Counter(7)) at (prev + 1, 5) to (start + 0, 15)
- Code(Expression(0, Sub)) at (prev + 0, 32) to (start + 0, 48)
- Code(Counter(2)) at (prev + 5, 5) to (start + 0, 31)
- Code(Counter(2)) at (prev + 1, 5) to (start + 0, 31)
- Code(Counter(2)) at (prev + 1, 9) to (start + 1, 28)
- Code(Counter(3)) at (prev + 2, 5) to (start + 0, 31)
- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 15)
- Code(Zero) at (prev + 0, 32) to (start + 0, 48)
- Code(Counter(3)) at (prev + 1, 5) to (start + 3, 15)
- Code(Zero) at (prev + 3, 32) to (start + 0, 48)
- Code(Zero) at (prev + 0, 51) to (start + 0, 65)
- Code(Zero) at (prev + 0, 75) to (start + 0, 90)
- Code(Counter(3)) at (prev + 1, 5) to (start + 0, 15)
- Code(Zero) at (prev + 5, 9) to (start + 3, 16)
- Code(Zero) at (prev + 5, 13) to (start + 0, 27)
- Code(Zero) at (prev + 2, 13) to (start + 0, 28)
- Code(Counter(3)) at (prev + 4, 9) to (start + 5, 6)
- Code(Counter(3)) at (prev + 6, 5) to (start + 3, 6)
- Code(Counter(3)) at (prev + 4, 5) to (start + 3, 6)
- Code(Counter(3)) at (prev + 4, 9) to (start + 4, 6)
- Code(Counter(3)) at (prev + 5, 8) to (start + 0, 15)
- Code(Counter(4)) at (prev + 1, 9) to (start + 3, 10)
- Code(Expression(0, Sub)) at (prev + 5, 9) to (start + 3, 10)
= (c3 - c4)
- Code(Counter(3)) at (prev + 5, 8) to (start + 0, 15)
- Code(Counter(5)) at (prev + 1, 9) to (start + 0, 19)
- Code(Zero) at (prev + 3, 13) to (start + 0, 29)
- Code(Expression(1, Sub)) at (prev + 3, 9) to (start + 0, 19)
= (c3 - c5)
- Code(Zero) at (prev + 3, 13) to (start + 0, 29)
- Code(Counter(3)) at (prev + 3, 5) to (start + 0, 15)
- Code(Counter(3)) at (prev + 1, 12) to (start + 0, 19)
- Code(Counter(6)) at (prev + 1, 13) to (start + 0, 19)
- Code(Expression(2, Sub)) at (prev + 2, 13) to (start + 0, 19)
= (c3 - c6)
- Code(Counter(7)) at (prev + 4, 5) to (start + 2, 19)
- Code(Counter(8)) at (prev + 3, 13) to (start + 0, 19)
- Code(Expression(3, Sub)) at (prev + 2, 13) to (start + 0, 19)
= (c7 - c8)
- Code(Counter(8)) at (prev + 1, 5) to (start + 3, 15)
- Code(Counter(9)) at (prev + 3, 32) to (start + 0, 48)
- Code(Counter(10)) at (prev + 0, 51) to (start + 0, 65)
- Code(Expression(1, Sub)) at (prev + 0, 75) to (start + 0, 90)
- Code(Expression(9, Add)) at (prev + 3, 5) to (start + 0, 15)
= (c10 + c11)
- Code(Counter(9)) at (prev + 1, 12) to (start + 0, 19)
- Code(Counter(10)) at (prev + 1, 13) to (start + 3, 14)
- Code(Counter(10)) at (prev + 4, 13) to (start + 0, 19)
- Code(Expression(7, Sub)) at (prev + 2, 13) to (start + 0, 23)
= (c9 - c10)
- Code(Expression(7, Sub)) at (prev + 1, 20) to (start + 0, 27)
= (c9 - c10)
- Code(Expression(2, Sub)) at (prev + 1, 5) to (start + 0, 15)
= (c8 - c9)
- Code(Counter(11)) at (prev + 5, 9) to (start + 3, 16)
- Code(Counter(12)) at (prev + 5, 13) to (start + 0, 27)
- Code(Expression(3, Sub)) at (prev + 2, 13) to (start + 0, 28)
= (c11 - c12)
- Code(Expression(4, Sub)) at (prev + 4, 9) to (start + 5, 6)
= (c8 - (c9 + c11))
- Code(Counter(13)) at (prev + 6, 5) to (start + 3, 6)
- Code(Counter(14)) at (prev + 4, 5) to (start + 3, 6)
- Code(Counter(15)) at (prev + 4, 9) to (start + 4, 6)
- Code(Counter(16)) at (prev + 5, 8) to (start + 0, 15)
- Code(Counter(17)) at (prev + 1, 9) to (start + 3, 10)
- Code(Expression(6, Sub)) at (prev + 5, 9) to (start + 3, 10)
= (c16 - c17)
- Code(Expression(12, Add)) at (prev + 5, 8) to (start + 0, 15)
= (c18 + c19)
- Code(Counter(20)) at (prev + 1, 9) to (start + 0, 19)
- Code(Expression(8, Sub)) at (prev + 3, 13) to (start + 0, 29)
= (c20 - c21)
- Code(Expression(9, Sub)) at (prev + 3, 9) to (start + 0, 19)
= ((c18 + c19) - c20)
- Code(Expression(11, Sub)) at (prev + 3, 13) to (start + 0, 29)
= ((c18 + c19) - (c20 + c22))
- Code(Expression(17, Add)) at (prev + 3, 5) to (start + 0, 15)
= (c21 + c22)
- Code(Expression(17, Add)) at (prev + 1, 12) to (start + 0, 19)
= (c21 + c22)
- Code(Counter(23)) at (prev + 1, 13) to (start + 0, 19)
- Code(Expression(16, Sub)) at (prev + 2, 13) to (start + 0, 19)
= ((c21 + c22) - c23)
- Code(Counter(24)) at (prev + 4, 5) to (start + 2, 19)
- Code(Counter(25)) at (prev + 3, 13) to (start + 0, 19)
- Code(Expression(18, Sub)) at (prev + 2, 13) to (start + 0, 19)
= (c24 - c25)
- Code(Expression(24, Add)) at (prev + 3, 5) to (start + 0, 15)
= (c28 + c29)
- Code(Counter(26)) at (prev + 1, 12) to (start + 0, 19)
- Code(Counter(27)) at (prev + 1, 13) to (start + 3, 14)
- Code(Counter(28)) at (prev + 4, 13) to (start + 0, 19)
- Code(Expression(22, Sub)) at (prev + 2, 13) to (start + 0, 23)
= (c26 - c27)
- Code(Expression(22, Sub)) at (prev + 1, 20) to (start + 0, 27)
= (c26 - c27)
- Code(Zero) at (prev + 1, 21) to (start + 0, 27)
- Code(Expression(22, Sub)) at (prev + 2, 21) to (start + 0, 27)
= (c26 - c27)
- Code(Counter(29)) at (prev + 4, 13) to (start + 0, 19)
- Code(Expression(23, Sub)) at (prev + 3, 9) to (start + 0, 25)
= ((c28 + c29) - c30)
- Code(Counter(30)) at (prev + 2, 5) to (start + 0, 15)
- Code(Expression(25, Sub)) at (prev + 3, 9) to (start + 0, 34)
= (c30 - c31)
- Code(Counter(31)) at (prev + 2, 5) to (start + 0, 15)
- Code(Expression(26, Sub)) at (prev + 3, 9) to (start + 0, 44)
= (c31 - c32)
- Code(Counter(32)) at (prev + 2, 1) to (start + 0, 2)
Highest counter ID seen: c32
- Code(Expression(7, Sub)) at (prev + 2, 21) to (start + 0, 27)
= (c9 - c10)
- Code(Counter(11)) at (prev + 4, 13) to (start + 0, 19)
- Code(Expression(8, Sub)) at (prev + 3, 9) to (start + 0, 25)
= ((c10 + c11) - c12)
- Code(Counter(12)) at (prev + 2, 5) to (start + 0, 15)
- Code(Counter(12)) at (prev + 3, 9) to (start + 0, 34)
- Code(Zero) at (prev + 2, 5) to (start + 0, 15)
- Code(Zero) at (prev + 3, 9) to (start + 0, 44)
- Code(Zero) at (prev + 2, 1) to (start + 0, 2)
Highest counter ID seen: c12

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

bb0: {
StorageLive(_1);
_1 = const <bool as NeedsDrop>::NEEDS;
- _1 = const <bool as NeedsDrop>::NEEDS;
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
+ _1 = const false;
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

bb0: {
StorageLive(_1);
_1 = const <bool as NeedsDrop>::NEEDS;
- _1 = const <bool as NeedsDrop>::NEEDS;
- switchInt(move _1) -> [0: bb2, otherwise: bb1];
+ _1 = const false;
+ switchInt(const false) -> [0: bb2, otherwise: bb1];
}

Expand Down
14 changes: 9 additions & 5 deletions tests/mir-opt/const_prop/read_immutable_static.main.GVN.diff
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@

bb0: {
StorageLive(_1);
StorageLive(_2);
- StorageLive(_2);
- StorageLive(_3);
+ nop;
+ nop;
_3 = const {ALLOC0: &u8};
_2 = copy (*_3);
- _2 = copy (*_3);
+ _2 = const 2_u8;
StorageLive(_4);
StorageLive(_5);
_5 = const {ALLOC0: &u8};
- _4 = copy (*_5);
+ _4 = copy (*_3);
_1 = Add(move _2, move _4);
- _1 = Add(move _2, move _4);
+ _4 = const 2_u8;
+ _1 = const 4_u8;
StorageDead(_4);
StorageDead(_2);
- StorageDead(_2);
+ nop;
StorageDead(_5);
- StorageDead(_3);
+ nop;
Expand Down
3 changes: 1 addition & 2 deletions tests/mir-opt/const_prop/read_immutable_static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ static FOO: u8 = 2;
fn main() {
// CHECK-LABEL: fn main(
// CHECK: debug x => [[x:_.*]];
// Disabled due to <https://github.com/rust-lang/rust/issues/130853>
// COM: CHECK: [[x]] = const 4_u8;
// CHECK: [[x]] = const 4_u8;
let x = FOO + FOO;
}
3 changes: 2 additions & 1 deletion tests/mir-opt/const_prop/ref_deref.main.GVN.diff
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
StorageLive(_2);
_4 = const main::promoted[0];
_2 = &(*_4);
_1 = copy (*_2);
- _1 = copy (*_2);
+ _1 = const 4_i32;
StorageDead(_2);
_0 = const ();
StorageDead(_1);
Expand Down
3 changes: 2 additions & 1 deletion tests/mir-opt/const_prop/ref_deref_project.main.GVN.diff
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
StorageLive(_2);
_4 = const main::promoted[0];
_2 = &((*_4).1: i32);
_1 = copy (*_2);
- _1 = copy (*_2);
+ _1 = const 5_i32;
StorageDead(_2);
_0 = const ();
StorageDead(_1);
Expand Down
3 changes: 1 addition & 2 deletions tests/mir-opt/const_prop/ref_deref_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
fn main() {
// CHECK-LABEL: fn main(
// CHECK: debug a => [[a:_.*]];
// Disabled due to <https://github.com/rust-lang/rust/issues/130853>
// COM: CHECK: [[a]] = const 5_i32;
// CHECK: [[a]] = const 5_i32;
let a = *(&(4, 5).1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

bb1: {
- _1 = copy (*_2)[_6];
+ _1 = copy (*_2)[1 of 2];
+ _1 = const 2_u32;
StorageDead(_6);
StorageDead(_4);
StorageDead(_2);
Expand Down
Loading
Loading