]> git.lizzy.rs Git - rust.git/commit
Auto merge of #45821 - djzin:unreachable-match-arms, r=nikomatsakis
authorbors <bors@rust-lang.org>
Tue, 14 Nov 2017 18:47:34 +0000 (18:47 +0000)
committerbors <bors@rust-lang.org>
Tue, 14 Nov 2017 18:47:34 +0000 (18:47 +0000)
commitff0f5de3b3220e1276bfc9a70ce1787ca7a45388
treef7c5ea166f08d25ff100eb6b88a8c9ecea683c01
parentdbeb5bf890211608bff5d28c3801c1a217a78d81
parent5b1cc1d81024a28b77d40a33b49b2d396a120b69
Auto merge of #45821 - djzin:unreachable-match-arms, r=nikomatsakis

always add an unreachable branch on matches to give more info to llvm

As part of https://github.com/djzin/rustc-optimization I discovered that some simple enum optimizations (src/unary/three_valued_enum.rs and src/unary/four_valued_enum.rs in the repo) are not applied - and the reason for this is that we erase the info that the discriminant of an enum is one of the options by putting the last one in an "otherwise" branch. This patch adds an extra branch so that LLVM can know what the possibilities are for the discriminant, which fixes the three- and four- valued cases.

Note that for whatever reason, this doesn't fix the case of 2 variants (most notably `Option` and `Result` have 2 variants) - a pass re-ordering might fix this or we may wish to add "assume" annotations on discriminants to force it to optimize.
src/librustc_mir/build/mod.rs