Closed
Description
Consider this snippet:
#![feature(const_fn_transmute)]
#![feature(or_patterns)]
use std::mem::transmute;
pub const fn foo3(bytes: [u8; 16]) -> Option<[u8; 4]> {
// big endian `u32`s
let dwords: [u32; 4] = unsafe { transmute(bytes) };
const FF: u32 = 0x0000_ffff_u32.to_be();
if let [0, 0, 0 | FF, ip] = dwords {
Some(unsafe { transmute(ip) })
} else {
None
}
}
The or-pattern 0 | FF
has this MIR:
bb3: {
switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at src/lib.rs:10:19: 10:20
}
While bb6
and bb7
points to the same branch:
bb6: {
StorageLive(_4); // scope 1 at src/lib.rs:10:27: 10:29
_4 = _2[3 of 4]; // scope 1 at src/lib.rs:10:27: 10:29
goto -> bb5; // scope 1 at src/lib.rs:10:5: 14:6
}
bb7: {
StorageLive(_4); // scope 1 at src/lib.rs:10:27: 10:29
_4 = _2[3 of 4]; // scope 1 at src/lib.rs:10:27: 10:29
goto -> bb5; // scope 1 at src/lib.rs:10:5: 14:6
}
I would expect the or-pattern points the same branch.
Metadata
Metadata
Assignees
Labels
Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: MIR optimizationsRelating to patterns and pattern matchingCategory: An issue proposing an enhancement or a PR with one.Category: An issue highlighting optimization opportunities or PRs implementing suchCall for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(or_patterns)]`Relevant to the compiler team, which will review and decide on the PR/issue.