]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #28651 - dotdash:exhaustive_match, r=eddyb
authorbors <bors@rust-lang.org>
Sun, 27 Sep 2015 05:29:39 +0000 (05:29 +0000)
committerbors <bors@rust-lang.org>
Sun, 27 Sep 2015 05:29:39 +0000 (05:29 +0000)
By putting an "unreachable" instruction into the default arm of a switch
instruction we can let LLVM know that the match is exhaustive, allowing
for better optimizations.

For example, this match:
```rust
pub enum Enum {
    One,
    Two,
    Three,
}

impl Enum {
    pub fn get_disc(self) -> u8 {
        match self {
            Enum::One => 0,
            Enum::Two => 1,
            Enum::Three => 2,
        }
    }
}
```

Currently compiles to this on x86_64:
```asm
  .cfi_startproc
  movzbl  %dil, %ecx
  cmpl  $1, %ecx
  setne %al
  testb %cl, %cl
  je  .LBB0_2
  incb  %al
  movb  %al, %dil
.LBB0_2:
  movb  %dil, %al
  retq
.Lfunc_end0:
```

But with this change we get:
```asm
  .cfi_startproc
  movb  %dil, %al
  retq
.Lfunc_end0:
```

1  2 
src/librustc_trans/trans/_match.rs

Simple merge