-
Notifications
You must be signed in to change notification settings - Fork 13k
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
[mir-opt] simplify Repeat
s that don't actually repeat the operand
#135322
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
- // MIR for `repeat_once_to_aggregate` before InstSimplify-after-simplifycfg | ||
+ // MIR for `repeat_once_to_aggregate` after InstSimplify-after-simplifycfg | ||
|
||
fn repeat_once_to_aggregate(_1: T) -> [T; 1] { | ||
debug x => _1; | ||
let mut _0: [T; 1]; | ||
let mut _2: T; | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
_2 = copy _1; | ||
- _0 = [move _2; 1]; | ||
+ _0 = [move _2]; | ||
StorageDead(_2); | ||
return; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ test-mir-pass: InstSimplify-after-simplifycfg | ||
//@ compile-flags: -C panic=abort | ||
#![crate_type = "lib"] | ||
|
||
// EMIT_MIR simplify_repeat.repeat_once_to_aggregate.InstSimplify-after-simplifycfg.diff | ||
pub fn repeat_once_to_aggregate<T: Copy>(x: T) -> [T; 1] { | ||
// CHECK-LABEL: fn repeat_once_to_aggregate( | ||
// CHECK-NOT: [move {{_[0-9]+}}; 1] | ||
// CHECK: _0 = [move {{_[0-9]+}}]; | ||
// CHECK-NOT: [move {{_[0-9]+}}; 1] | ||
|
||
[x; 1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also test getting the |
||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
- // MIR for `remove_generic_array` before RemoveZsts | ||
+ // MIR for `remove_generic_array` after RemoveZsts | ||
|
||
fn remove_generic_array(_1: T) -> () { | ||
debug x => _1; | ||
let mut _0: (); | ||
let _2: [T; 0]; | ||
let mut _3: T; | ||
scope 1 { | ||
- debug a => _2; | ||
+ debug a => const ZeroSized: [T; 0]; | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
+ nop; | ||
StorageLive(_3); | ||
_3 = copy _1; | ||
- _2 = []; | ||
+ nop; | ||
StorageDead(_3); | ||
- _0 = const (); | ||
- StorageDead(_2); | ||
+ nop; | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
// skip-filecheck | ||
//@ test-mir-pass: RemoveZsts | ||
|
||
union Foo { | ||
x: (), | ||
y: u64, | ||
} | ||
|
||
// EMIT_MIR remove_zsts.get_union.RemoveZsts.diff | ||
// EMIT_MIR remove_zsts.get_union.PreCodegen.after.mir | ||
fn get_union() -> Foo { | ||
// CHECK-LABEL: fn get_union | ||
// CHECK: _0 = Foo { x: const () }; | ||
Foo { x: () } | ||
} | ||
|
||
// EMIT_MIR remove_zsts.remove_generic_array.RemoveZsts.diff | ||
fn remove_generic_array<T: Copy>(x: T) { | ||
// CHECK-LABEL: fn remove_generic_array | ||
// CHECK: debug a => const ZeroSized: [T; 0]; | ||
// CHECK-NOT: = []; | ||
let a = [x; 0]; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a test where the zero comes from a constant not a literal |
||
|
||
fn main() { | ||
get_union(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exhaustively match here. This branch must not have false positives given that it means "definitely not"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Spurious
false
is benign in how it's actually used, but that's not what the comments say, so I should re-work it. Maybe just have the wildcard be_ => None
, since that's more obviously fine, and add the known-false cases explicitly.