-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve usage of lifetime intrinsics in match expressions
The allocas used in match expression currently don't get good lifetime markers, in fact they only get lifetime start markers, because their lifetimes don't match to cleanup scopes. While the bindings themselves are bog standard and just need a matching pair of start and end markers, they might need them twice, once for a guard clause and once for the match body. The __llmatch alloca OTOH needs a single lifetime start marker, but when there's a guard clause, it needs two end markers, because its lifetime ends either when the guard doesn't match or after the match body. With these intrinsics in place, LLVM can now, for example, optimize code like this: ````rust enum E { A1(int), A2(int), A3(int), A4(int), } pub fn variants(x: E) { match x { A1(m) => bar(&m), A2(m) => bar(&m), A3(m) => bar(&m), A4(m) => bar(&m), } } ```` To a single call to bar, using only a single stack slot. It still fails to eliminate some of checks. ````gas .Ltmp5: .cfi_def_cfa_offset 16 movb (%rdi), %al testb %al, %al je .LBB3_5 movzbl %al, %eax cmpl $1, %eax je .LBB3_5 cmpl $2, %eax .LBB3_5: movq 8(%rdi), %rax movq %rax, (%rsp) leaq (%rsp), %rdi callq _ZN3bar20hcb7a0d8be8e17e37daaE@PLT popq %rax retq ````
- Loading branch information
Showing
3 changed files
with
44 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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 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
0d6f257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pcwalton
at dotdash@0d6f257
0d6f257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging dotdash/rust/match_lifetimes = 0d6f257 into auto
0d6f257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dotdash/rust/match_lifetimes = 0d6f257 merged ok, testing candidate = e70ee12
0d6f257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/493
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/493
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/492
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/493
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/494
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/495
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/494
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/500
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/495
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/494
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/497
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/495
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/495
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/496
0d6f257
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = e70ee12