Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Replace SingleUseConsts by GVN. #147079

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

Draft
cjgillot wants to merge 4 commits into rust-lang:master
base: master
Choose a base branch
Loading
from cjgillot:gvn-dbg-const
Draft
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
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/mir/consts.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ impl<'tcx> Const<'tcx> {
/// Return true if any evaluation of this constant always returns the same value,
/// taking into account even pointer identity tests.
pub fn is_deterministic(&self) -> bool {
if self.ty().is_primitive() {
// Primitive types hold no provenance, so their result is deterministic.
return true;
}

// Some constants may generate fresh allocations for pointers they contain,
// so using the same constant twice can yield two different results.
// Notably, valtrees purposefully generate new allocations.
Expand Down
401 changes: 249 additions & 152 deletions compiler/rustc_mir_transform/src/gvn.rs
View file Open in desktop

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions compiler/rustc_mir_transform/src/lib.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ declare_passes! {
Final
};
mod simplify_comparison_integral : SimplifyComparisonIntegral;
mod single_use_consts : SingleUseConsts;
mod sroa : ScalarReplacementOfAggregates;
mod strip_debuginfo : StripDebugInfo;
mod unreachable_enum_branching : UnreachableEnumBranching;
Expand Down Expand Up @@ -709,7 +708,6 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
&simplify::SimplifyLocals::AfterGVN,
&match_branches::MatchBranchSimplification,
&dataflow_const_prop::DataflowConstProp,
&single_use_consts::SingleUseConsts,
&o1(simplify_branches::SimplifyConstCondition::AfterConstProp),
&jump_threading::JumpThreading,
&early_otherwise_branch::EarlyOtherwiseBranch,
Expand Down
205 changes: 0 additions & 205 deletions compiler/rustc_mir_transform/src/single_use_consts.rs
View file Open in desktop

This file was deleted.

2 changes: 1 addition & 1 deletion tests/codegen-llvm/amdgpu-addrspacecast.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern crate minicore;

// CHECK-LABEL: @ref_of_local
// CHECK: [[alloca:%[0-9]]] = alloca
// CHECK: %i = addrspacecast ptr addrspace(5) [[alloca]] to ptr
// CHECK: {{%.*}} = addrspacecast ptr addrspace(5) [[alloca]] to ptr
#[no_mangle]
pub fn ref_of_local(f: fn(&i32)) {
let i = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/incremental/hashes/enum_constructors.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn change_field_order_struct_like() -> Enum {
#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck")]
#[rustc_clean(cfg="cfail3")]
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck,optimized_mir")]
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck")]
#[rustc_clean(cfg="cfail6")]
// FIXME(michaelwoerister):Interesting. I would have thought that that changes the MIR. And it
// would if it were not all constants
Expand Down
2 changes: 1 addition & 1 deletion tests/incremental/hashes/struct_constructors.rs
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn change_field_order_regular_struct() -> RegularStruct {
#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg="cfail2", except="opt_hir_owner_nodes,typeck")]
#[rustc_clean(cfg="cfail3")]
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck,optimized_mir")]
#[rustc_clean(cfg="cfail5", except="opt_hir_owner_nodes,typeck")]
#[rustc_clean(cfg="cfail6")]
pub fn change_field_order_regular_struct() -> RegularStruct {
RegularStruct {
Expand Down
16 changes: 11 additions & 5 deletions tests/mir-opt/building/match/sort_candidates.rs
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Check specific cases of sorting candidates in match lowering.
//! Check specific cases of sorting candidates in match lowering.
//@ compile-flags: -Zmir-opt-level=0

// EMIT_MIR sort_candidates.constant_eq.SimplifyCfg-initial.after.mir
fn constant_eq(s: &str, b: bool) -> u32 {
// Check that we only test "a" once

// CHECK-LABEL: fn constant_eq(
// CHECK-NOT: const "a"
// CHECK: {{_[0-9]+}} = const "a" as &[u8] (Transmute);
// CHECK: eq({{.*}}, const "a")
// CHECK-NOT: const "a"
match (s, b) {
("a", _) if true => 1,
Expand All @@ -23,11 +24,16 @@ fn disjoint_ranges(x: i32, b: bool) -> u32 {
// other candidates.

// CHECK-LABEL: fn disjoint_ranges(
// CHECK: debug b => _2;
// CHECK: bb0: {
// CHECK: switchInt(copy _2) -> [0: [[jump:bb.*]], otherwise: {{bb.*}}];
// CHECK: debug b => [[b:_.*]];
// CHECK: [[tmp:_.*]] = copy [[b]];
// CHECK-NEXT: switchInt(move [[tmp]]) -> [0: [[jump:bb.*]], otherwise: {{bb.*}}];
// CHECK: [[jump]]: {
// CHECK-NEXT: StorageDead([[tmp]]);
// CHECK-NEXT: goto -> [[jump3:bb.*]];
// CHECK: [[jump3]]: {
// CHECK-NEXT: _0 = const 3_u32;
// CHECK-NEXT: goto -> [[jumpret:bb.*]];
// CHECK: [[jumpret]]: {
// CHECK-NEXT: return;
match x {
0..10 if b => 0,
Expand Down
Loading
Loading

AltStyle によって変換されたページ (->オリジナル) /