Implement rdar://7415680 - Twine integer support lacks greatness
authorChris Lattner <sabre@nondot.org>
Wed, 5 May 2010 18:40:33 +0000 (18:40 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 5 May 2010 18:40:33 +0000 (18:40 +0000)
commitea03e10facd07f0b239dcc3a5e31346686acae3c
tree70531bed5f06f4095393026899181c4b34bdcdb5
parent15cdda259ad8cd742a8c4b78b807f1d00d0b8afd
Implement rdar://7415680 - Twine integer support lacks greatness

Microoptimize Twine's with unsigned and int to not pin their value to
the stack.  This saves stack space in common cases and allows mem2reg
in the caller.  A simple example is:

void foo(const Twine &);
void bar(int x) {
  foo("xyz: " + Twine(x));
}

Before:

__Z3bari:
subq $40, %rsp
movl %edi, 36(%rsp)
leaq L_.str3(%rip), %rax
leaq 36(%rsp), %rcx
leaq 8(%rsp), %rdi
movq %rax, 8(%rsp)
movq %rcx, 16(%rsp)
movb $3, 24(%rsp)
movb $7, 25(%rsp)
callq __Z3fooRKN4llvm5TwineE
addq $40, %rsp
ret

After:

__Z3bari:
subq $24, %rsp
leaq L_.str3(%rip), %rax
movq %rax, (%rsp)
movslq %edi, %rax
movq %rax, 8(%rsp)
movb $3, 16(%rsp)
movb $7, 17(%rsp)
leaq (%rsp), %rdi
callq __Z3fooRKN4llvm5TwineE
addq $24, %rsp
ret

It saves 16 bytes of stack and one instruction in this case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103107 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/Twine.h
lib/Support/Twine.cpp