-
Notifications
You must be signed in to change notification settings - Fork 13.5k
optimizing Use expressions inside if condition #111644
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
849af1b
optimizing Use expressions inside if condition
azizghuloum 5693a02
Merge branch 'rust-lang:master' into master
azizghuloum 1a42cdc
Merge branch 'rust-lang:master' into master
azizghuloum b735474
added test for "if e0 && e2 && e3 {}" ensuring that drops dont get dr…
azizghuloum a1847f9
added test case from issue https://github.com/rust-lang/rust/issues/1…
azizghuloum 1335983
modified test to remove explicit blocks in if
azizghuloum 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
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
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
113 changes: 113 additions & 0 deletions
113
tests/mir-opt/building/logical_and_in_conditional.function_from_issue_111583.built.after.mir
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,113 @@ | ||
// MIR for `function_from_issue_111583` after built | ||
|
||
fn function_from_issue_111583(_1: f64) -> () { | ||
debug z => _1; // in scope 0 at $DIR/logical_and_in_conditional.rs:+0:31: +0:32 | ||
let mut _0: (); // return place in scope 0 at $DIR/logical_and_in_conditional.rs:+0:39: +0:39 | ||
let _2: u64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+1:9: +1:13 | ||
let mut _3: u64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+1:16: +1:25 | ||
let mut _5: bool; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:8: +3:38 | ||
let mut _6: u64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:8: +3:33 | ||
let mut _7: u64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:8: +3:26 | ||
let mut _8: u64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:9: +3:20 | ||
let mut _9: f64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:9: +3:10 | ||
let mut _10: u64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:29: +3:33 | ||
let mut _11: bool; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:42: +3:60 | ||
let mut _12: f64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:42: +3:52 | ||
let mut _13: f64; // in scope 0 at $DIR/logical_and_in_conditional.rs:+3:42: +3:43 | ||
scope 1 { | ||
debug mask => _2; // in scope 1 at $DIR/logical_and_in_conditional.rs:+1:9: +1:13 | ||
let mut _4: i32; // in scope 1 at $DIR/logical_and_in_conditional.rs:+2:9: +2:16 | ||
scope 2 { | ||
debug ret => _4; // in scope 2 at $DIR/logical_and_in_conditional.rs:+2:9: +2:16 | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); // scope 0 at $DIR/logical_and_in_conditional.rs:+1:9: +1:13 | ||
StorageLive(_3); // scope 0 at $DIR/logical_and_in_conditional.rs:+1:16: +1:25 | ||
_3 = Shl(const 1_u64, const 38_i32); // scope 0 at $DIR/logical_and_in_conditional.rs:+1:16: +1:25 | ||
_2 = Sub(move _3, const 1_u64); // scope 0 at $DIR/logical_and_in_conditional.rs:+1:16: +1:29 | ||
StorageDead(_3); // scope 0 at $DIR/logical_and_in_conditional.rs:+1:28: +1:29 | ||
FakeRead(ForLet(None), _2); // scope 0 at $DIR/logical_and_in_conditional.rs:+1:9: +1:13 | ||
StorageLive(_4); // scope 1 at $DIR/logical_and_in_conditional.rs:+2:9: +2:16 | ||
_4 = const 0_i32; // scope 1 at $DIR/logical_and_in_conditional.rs:+2:19: +2:20 | ||
FakeRead(ForLet(None), _4); // scope 1 at $DIR/logical_and_in_conditional.rs:+2:9: +2:16 | ||
StorageLive(_5); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:38 | ||
StorageLive(_6); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:33 | ||
StorageLive(_7); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:26 | ||
StorageLive(_8); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:9: +3:20 | ||
StorageLive(_9); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:9: +3:10 | ||
_9 = _1; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:9: +3:10 | ||
_8 = core::f64::<impl f64>::to_bits(move _9) -> [return: bb1, unwind: bb10]; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:9: +3:20 | ||
// mir::Constant | ||
// + span: $DIR/logical_and_in_conditional.rs:28:11: 28:18 | ||
// + literal: Const { ty: fn(f64) -> u64 {core::f64::<impl f64>::to_bits}, val: Value(<ZST>) } | ||
} | ||
|
||
bb1: { | ||
StorageDead(_9); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:19: +3:20 | ||
_7 = Shr(move _8, const 8_i32); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:26 | ||
StorageDead(_8); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:25: +3:26 | ||
StorageLive(_10); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:29: +3:33 | ||
_10 = _2; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:29: +3:33 | ||
_6 = BitAnd(move _7, move _10); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:33 | ||
StorageDead(_10); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:32: +3:33 | ||
StorageDead(_7); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:32: +3:33 | ||
_5 = Eq(move _6, const 0_u64); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:38 | ||
switchInt(move _5) -> [0: bb3, otherwise: bb2]; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:38 | ||
} | ||
|
||
bb2: { | ||
StorageDead(_6); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:37: +3:38 | ||
StorageLive(_11); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:60 | ||
StorageLive(_12); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:52 | ||
StorageLive(_13); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:43 | ||
_13 = _1; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:43 | ||
_12 = Rem(move _13, const 0.0625f64); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:52 | ||
StorageDead(_13); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:51: +3:52 | ||
_11 = Lt(move _12, const 1.0E-13f64); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:60 | ||
switchInt(move _11) -> [0: bb5, otherwise: bb4]; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:60 | ||
} | ||
|
||
bb3: { | ||
goto -> bb7; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:8: +3:38 | ||
} | ||
|
||
bb4: { | ||
StorageDead(_12); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:59: +3:60 | ||
_4 = Add(_4, const 1_i32); // scope 2 at $DIR/logical_and_in_conditional.rs:+4:9: +4:17 | ||
_0 = const (); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:61: +5:6 | ||
goto -> bb9; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:5: +5:6 | ||
} | ||
|
||
bb5: { | ||
goto -> bb6; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:42: +3:60 | ||
} | ||
|
||
bb6: { | ||
StorageDead(_12); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:59: +3:60 | ||
goto -> bb8; // scope 2 at no-location | ||
} | ||
|
||
bb7: { | ||
StorageDead(_6); // scope 2 at $DIR/logical_and_in_conditional.rs:+3:37: +3:38 | ||
goto -> bb8; // scope 2 at no-location | ||
} | ||
|
||
bb8: { | ||
_0 = const (); // scope 2 at $DIR/logical_and_in_conditional.rs:+5:6: +5:6 | ||
goto -> bb9; // scope 2 at $DIR/logical_and_in_conditional.rs:+3:5: +5:6 | ||
} | ||
|
||
bb9: { | ||
StorageDead(_11); // scope 2 at $DIR/logical_and_in_conditional.rs:+5:5: +5:6 | ||
StorageDead(_5); // scope 2 at $DIR/logical_and_in_conditional.rs:+5:5: +5:6 | ||
StorageDead(_4); // scope 1 at $DIR/logical_and_in_conditional.rs:+6:1: +6:2 | ||
StorageDead(_2); // scope 0 at $DIR/logical_and_in_conditional.rs:+6:1: +6:2 | ||
return; // scope 0 at $DIR/logical_and_in_conditional.rs:+6:2: +6:2 | ||
} | ||
|
||
bb10 (cleanup): { | ||
resume; // scope 0 at $DIR/logical_and_in_conditional.rs:+0:1: +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,42 @@ | ||
struct Droppy; | ||
|
||
impl Drop for Droppy { | ||
fn drop(&mut self) { | ||
println!("drop"); | ||
} | ||
} | ||
|
||
// EMIT_MIR logical_and_in_conditional.test_and.built.after.mir | ||
fn test_and(a: i32, b: i32, c: i32) { | ||
if { | ||
let _t = Droppy; | ||
a == 0 | ||
} && { | ||
let _t = Droppy; | ||
b == 0 | ||
} && { | ||
let _t = Droppy; | ||
c == 0 | ||
} {} | ||
} | ||
|
||
// https://github.com/rust-lang/rust/issues/111583 | ||
// EMIT_MIR logical_and_in_conditional.function_from_issue_111583.built.after.mir | ||
fn function_from_issue_111583(z: f64) { | ||
let mask = (1 << 38) - 1; | ||
let mut ret = 0; | ||
if (z.to_bits() >> 8) & mask == 0 && z % 0.0625 < 1e-13 { | ||
ret += 1; | ||
} | ||
} | ||
|
||
fn main() { | ||
function_from_issue_111583(0.0); | ||
for a in 0..1 { | ||
for b in 0..1 { | ||
for c in 0..1 { | ||
test_and(a, b, c); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.