mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-13 23:18:58 +00:00
a1a323c637
TwoAddressInstructionPass stops after a successful commuting but 3 Addr conversion might be good for some cases. Consider: int foo(int a, int b) { return a + b; } Before this commit, we emit: addl %esi, %edi movl %edi, %eax ret After this commit, we try 3 Addr conversion: leal (%rsi,%rdi), %eax ret Patch by Volkan Keles <vkeles@apple.com>! Differential Revision: http://reviews.llvm.org/D10851 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241206 91177308-0d34-0410-b5e6-96231b3b80d8
47 lines
1.2 KiB
LLVM
47 lines
1.2 KiB
LLVM
;; X's live range extends beyond the shift, so the register allocator
|
|
;; cannot coalesce it with Y. Because of this, a copy needs to be
|
|
;; emitted before the shift to save the register value before it is
|
|
;; clobbered. However, this copy is not needed if the register
|
|
;; allocator turns the shift into an LEA. This also occurs for ADD.
|
|
|
|
; Check that the shift gets turned into an LEA.
|
|
; RUN: llc < %s -mcpu=generic -mtriple=x86_64-apple-darwin | FileCheck %s
|
|
|
|
@G = external global i32
|
|
|
|
define i32 @test1(i32 %X) nounwind {
|
|
; CHECK-LABEL: test1:
|
|
; CHECK-NOT: mov
|
|
; CHECK: leal 1(%rdi)
|
|
%Z = add i32 %X, 1
|
|
store volatile i32 %Z, i32* @G
|
|
ret i32 %X
|
|
}
|
|
|
|
; rdar://8977508
|
|
; The second add should not be transformed to leal nor should it be
|
|
; commutted (which would require inserting a copy).
|
|
define i32 @test2(i32 inreg %a, i32 inreg %b, i32 %c, i32 %d) nounwind {
|
|
entry:
|
|
; CHECK-LABEL: test2:
|
|
; CHECK: leal
|
|
; CHECK-NEXT: addl
|
|
; CHECK-NEXT: addl
|
|
; CHECK-NEXT: ret
|
|
%add = add i32 %b, %a
|
|
%add3 = add i32 %add, %c
|
|
%add5 = add i32 %add3, %d
|
|
ret i32 %add5
|
|
}
|
|
|
|
; rdar://9002648
|
|
define i64 @test3(i64 %x) nounwind readnone ssp {
|
|
entry:
|
|
; CHECK-LABEL: test3:
|
|
; CHECK: leaq (%rdi,%rdi), %rax
|
|
; CHECK-NOT: addq
|
|
; CHECK-NEXT: ret
|
|
%0 = shl i64 %x, 1
|
|
ret i64 %0
|
|
}
|