[PATCH] D24108: X86: Fold tail calls into conditional branches where possible (PR26302)
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 15:59:03 PDT 2016
hans created this revision.
hans added reviewers: mkuper, rnk.
hans added a subscriber: llvm-commits.
When branching to a block that immediately tail calls, it is possible to fold the call directly into the branch if the call is direct and there is no stack adjustment, saving one byte.
Example:
```
define void @f(i32 %x, i32 %y) {
entry:
%p = icmp eq i32 %x, %y
br i1 %p, label %bb1, label %bb2
bb1:
tail call void @foo()
ret void
bb2:
tail call void @bar()
ret void
}
```
before:
```
f:
movl 4(%esp), %eax
cmpl 8(%esp), %eax
jne .LBB0_2
jmp foo
.LBB0_2:
jmp bar
```
after:
```
f:
movl 4(%esp), %eax
cmpl 8(%esp), %eax
jne bar
.LBB0_1:
jmp foo
```
I don't expect any significant size savings from this (on a Clang bootstrap I saw 288 bytes), but it does make the code a little tighter.
This patch only does 32-bit, but 64-bit would work similarly.
https://reviews.llvm.org/D24108
Files:
include/llvm/Target/TargetInstrInfo.h
lib/CodeGen/BranchFolding.cpp
lib/Target/X86/X86ExpandPseudo.cpp
lib/Target/X86/X86InstrControl.td
lib/Target/X86/X86InstrInfo.cpp
lib/Target/X86/X86InstrInfo.h
lib/Target/X86/X86MCInstLower.cpp
test/CodeGen/X86/atom-pad-short-functions.ll
test/CodeGen/X86/conditional-tailcall.ll
test/CodeGen/X86/or-branch.ll
test/CodeGen/X86/sibcall.ll
test/CodeGen/X86/xor-icmp.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24108.69917.patch
Type: text/x-patch
Size: 19353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160831/4aeef259/attachment.bin>
More information about the llvm-commits
mailing list