-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Optimize away BitAnd and BitOr when possible #74491
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// compile-flags: -O -Zmir-opt-level=3 | ||
|
||
// EMIT_MIR rustc.test.ConstProp.diff | ||
pub fn test(x: bool, y: bool) -> bool { | ||
(y | true) & (x & false) | ||
} | ||
|
||
fn main() { | ||
test(true, false); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/test/mir-opt/const_prop/boolean_identities/rustc.test.ConstProp.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
- // MIR for `test` before ConstProp | ||
+ // MIR for `test` after ConstProp | ||
|
||
fn test(_1: bool, _2: bool) -> bool { | ||
debug x => _1; // in scope 0 at $DIR/boolean_identities.rs:4:13: 4:14 | ||
debug y => _2; // in scope 0 at $DIR/boolean_identities.rs:4:22: 4:23 | ||
let mut _0: bool; // return place in scope 0 at $DIR/boolean_identities.rs:4:34: 4:38 | ||
let mut _3: bool; // in scope 0 at $DIR/boolean_identities.rs:5:5: 5:15 | ||
let mut _4: bool; // in scope 0 at $DIR/boolean_identities.rs:5:6: 5:7 | ||
let mut _5: bool; // in scope 0 at $DIR/boolean_identities.rs:5:18: 5:29 | ||
let mut _6: bool; // in scope 0 at $DIR/boolean_identities.rs:5:19: 5:20 | ||
|
||
bb0: { | ||
StorageLive(_3); // scope 0 at $DIR/boolean_identities.rs:5:5: 5:15 | ||
StorageLive(_4); // scope 0 at $DIR/boolean_identities.rs:5:6: 5:7 | ||
_4 = _2; // scope 0 at $DIR/boolean_identities.rs:5:6: 5:7 | ||
- _3 = BitOr(move _4, const true); // scope 0 at $DIR/boolean_identities.rs:5:5: 5:15 | ||
+ _3 = const true; // scope 0 at $DIR/boolean_identities.rs:5:5: 5:15 | ||
// ty::Const | ||
// + ty: bool | ||
// + val: Value(Scalar(0x01)) | ||
// mir::Constant | ||
- // + span: $DIR/boolean_identities.rs:5:10: 5:14 | ||
+ // + span: $DIR/boolean_identities.rs:5:5: 5:15 | ||
// + literal: Const { ty: bool, val: Value(Scalar(0x01)) } | ||
StorageDead(_4); // scope 0 at $DIR/boolean_identities.rs:5:14: 5:15 | ||
StorageLive(_5); // scope 0 at $DIR/boolean_identities.rs:5:18: 5:29 | ||
StorageLive(_6); // scope 0 at $DIR/boolean_identities.rs:5:19: 5:20 | ||
_6 = _1; // scope 0 at $DIR/boolean_identities.rs:5:19: 5:20 | ||
- _5 = BitAnd(move _6, const false); // scope 0 at $DIR/boolean_identities.rs:5:18: 5:29 | ||
+ _5 = const false; // scope 0 at $DIR/boolean_identities.rs:5:18: 5:29 | ||
// ty::Const | ||
// + ty: bool | ||
// + val: Value(Scalar(0x00)) | ||
// mir::Constant | ||
- // + span: $DIR/boolean_identities.rs:5:23: 5:28 | ||
+ // + span: $DIR/boolean_identities.rs:5:18: 5:29 | ||
// + literal: Const { ty: bool, val: Value(Scalar(0x00)) } | ||
StorageDead(_6); // scope 0 at $DIR/boolean_identities.rs:5:28: 5:29 | ||
- _0 = BitAnd(move _3, move _5); // scope 0 at $DIR/boolean_identities.rs:5:5: 5:29 | ||
+ _0 = const false; // scope 0 at $DIR/boolean_identities.rs:5:5: 5:29 | ||
+ // ty::Const | ||
+ // + ty: bool | ||
+ // + val: Value(Scalar(0x00)) | ||
+ // mir::Constant | ||
+ // + span: $DIR/boolean_identities.rs:5:5: 5:29 | ||
+ // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } | ||
StorageDead(_5); // scope 0 at $DIR/boolean_identities.rs:5:28: 5:29 | ||
StorageDead(_3); // scope 0 at $DIR/boolean_identities.rs:5:28: 5:29 | ||
return; // scope 0 at $DIR/boolean_identities.rs:6:2: 6:2 | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// compile-flags: -O -Zmir-opt-level=3 | ||
|
||
// EMIT_MIR rustc.test.ConstProp.diff | ||
fn test(x : i32) -> i32 { | ||
x * 0 | ||
} | ||
|
||
fn main() { | ||
test(10); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/test/mir-opt/const_prop/mult_by_zero/rustc.test.ConstProp.diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
- // MIR for `test` before ConstProp | ||
+ // MIR for `test` after ConstProp | ||
|
||
fn test(_1: i32) -> i32 { | ||
debug x => _1; // in scope 0 at $DIR/mult_by_zero.rs:4:9: 4:10 | ||
let mut _0: i32; // return place in scope 0 at $DIR/mult_by_zero.rs:4:21: 4:24 | ||
let mut _2: i32; // in scope 0 at $DIR/mult_by_zero.rs:5:3: 5:4 | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/mult_by_zero.rs:5:3: 5:4 | ||
_2 = _1; // scope 0 at $DIR/mult_by_zero.rs:5:3: 5:4 | ||
- _0 = Mul(move _2, const 0_i32); // scope 0 at $DIR/mult_by_zero.rs:5:3: 5:8 | ||
+ _0 = const 0_i32; // scope 0 at $DIR/mult_by_zero.rs:5:3: 5:8 | ||
// ty::Const | ||
// + ty: i32 | ||
// + val: Value(Scalar(0x00000000)) | ||
// mir::Constant | ||
- // + span: $DIR/mult_by_zero.rs:5:7: 5:8 | ||
+ // + span: $DIR/mult_by_zero.rs:5:3: 5:8 | ||
// + literal: Const { ty: i32, val: Value(Scalar(0x00000000)) } | ||
StorageDead(_2); // scope 0 at $DIR/mult_by_zero.rs:5:7: 5:8 | ||
return; // scope 0 at $DIR/mult_by_zero.rs:6:2: 6:2 | ||
} | ||
} | ||
|
3 changes: 2 additions & 1 deletion
3
src/test/ui/consts/const-eval/index-out-of-bounds-never-type.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.