about summary refs log tree commit diff
path: root/src/libstd/sys/unix/stack_overflow.rs
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2015-09-25 11:02:51 +0200
committerBjörn Steinbrink <bsteinbr@gmail.com>2015-09-25 11:09:19 +0200
commit91f7c60d2d77423ed8f163beb6f76b92de03a09f (patch)
tree995827f4c0a9a95bdc84305a49662f5d5b5ec72d /src/libstd/sys/unix/stack_overflow.rs
parent5ca60d94316bd56f412ef4c13292237e206babf1 (diff)
downloadrust-91f7c60d2d77423ed8f163beb6f76b92de03a09f.tar.gz
rust-91f7c60d2d77423ed8f163beb6f76b92de03a09f.zip
Tell LLVM when a match is exhaustive
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:
```
Diffstat (limited to 'src/libstd/sys/unix/stack_overflow.rs')
0 files changed, 0 insertions, 0 deletions