mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-02 07:17:36 +00:00
[FastISel] Let the target decide first if it wants to materialize a constant.
This changes the order in which FastISel tries to materialize a constant. Originally it would try to use a simple target-independent approach, which can lead to the generation of inefficient code. On X86 this would result in the use of movabsq to materialize any 64bit integer constant - even for simple and small values such as 0 and 1. Also some very funny floating-point materialization could be observed too. On AArch64 it would materialize the constant 0 in a register even the architecture has an actual "zero" register. On ARM it would generate unnecessary mov instructions or not use mvn. This change simply changes the order and always asks the target first if it likes to materialize the constant. This doesn't fix all the issues mentioned above, but it enables the targets to implement such optimizations. Related to <rdar://problem/17420988>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215588 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -117,17 +117,11 @@ entry:
|
||||
; ARM-LONG: blx [[R]]
|
||||
; THUMB: @t10
|
||||
; THUMB: movs [[R0:l?r[0-9]*]], #0
|
||||
; THUMB: movt [[R0]], #0
|
||||
; THUMB: movs [[R1:l?r[0-9]*]], #248
|
||||
; THUMB: movt [[R1]], #0
|
||||
; THUMB: movs [[R2:l?r[0-9]*]], #187
|
||||
; THUMB: movt [[R2]], #0
|
||||
; THUMB: movs [[R3:l?r[0-9]*]], #28
|
||||
; THUMB: movt [[R3]], #0
|
||||
; THUMB: movw [[R4:l?r[0-9]*]], #40
|
||||
; THUMB: movt [[R4]], #0
|
||||
; THUMB: movw [[R5:l?r[0-9]*]], #186
|
||||
; THUMB: movt [[R5]], #0
|
||||
; THUMB: and [[R0]], [[R0]], #255
|
||||
; THUMB: and [[R1]], [[R1]], #255
|
||||
; THUMB: and [[R2]], [[R2]], #255
|
||||
|
||||
@@ -14,7 +14,6 @@ entry:
|
||||
; THUMB-NOT: ldr
|
||||
; THUMB-NOT: sxtb
|
||||
; THUMB: movs r0, #0
|
||||
; THUMB: movt r0, #0
|
||||
; THUMB: pop
|
||||
ret i32 0
|
||||
}
|
||||
|
||||
@@ -31,9 +31,7 @@ define void @t1() nounwind ssp {
|
||||
; THUMB: {{(movt r0, :upper16:_?message1)|(ldr r0, \[r0\])}}
|
||||
; THUMB: adds r0, #5
|
||||
; THUMB: movs r1, #64
|
||||
; THUMB: movt r1, #0
|
||||
; THUMB: movs r2, #10
|
||||
; THUMB: movt r2, #0
|
||||
; THUMB: and r1, r1, #255
|
||||
; THUMB: bl {{_?}}memset
|
||||
; THUMB-LONG-LABEL: t1:
|
||||
@@ -71,7 +69,6 @@ define void @t2() nounwind ssp {
|
||||
; THUMB: adds r1, r0, #4
|
||||
; THUMB: adds r0, #16
|
||||
; THUMB: movs r2, #17
|
||||
; THUMB: movt r2, #0
|
||||
; THUMB: str r0, [sp[[SLOT:[, #0-9]*]]] @ 4-byte Spill
|
||||
; THUMB: mov r0, r1
|
||||
; THUMB: ldr r1, [sp[[SLOT]]] @ 4-byte Reload
|
||||
@@ -109,7 +106,6 @@ define void @t3() nounwind ssp {
|
||||
; THUMB: adds r1, r0, #4
|
||||
; THUMB: adds r0, #16
|
||||
; THUMB: movs r2, #10
|
||||
; THUMB: movt r2, #0
|
||||
; THUMB: str r0, [sp[[SLOT:[, #0-9]*]]] @ 4-byte Spill
|
||||
; THUMB: mov r0, r1
|
||||
; THUMB: ldr r1, [sp[[SLOT]]] @ 4-byte Reload
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
; RUN: llc -O0 -verify-machineinstrs -fast-isel-abort -relocation-model=dynamic-no-pic -arm-use-movt=false -mtriple=armv7-apple-ios < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM
|
||||
; RUN: llc -O0 -verify-machineinstrs -fast-isel-abort -relocation-model=dynamic-no-pic -arm-use-movt=false -mtriple=armv7-linux-gnueabi < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM
|
||||
; RUN: llc < %s -O0 -verify-machineinstrs -fast-isel-abort -relocation-model=dynamic-no-pic -mtriple=thumbv7-apple-ios | FileCheck %s --check-prefix=THUMB
|
||||
; RUN: llc -O0 -verify-machineinstrs -fast-isel-abort -relocation-model=dynamic-no-pic -arm-use-movt=false -mtriple=thumbv7-apple-ios < %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM
|
||||
; RUN: llc -O0 -verify-machineinstrs -fast-isel-abort -relocation-model=dynamic-no-pic -arm-use-movt=true -mtriple=thumbv7-apple-ios < %s | FileCheck %s --check-prefix=CHECK --check-prefix=THUMB
|
||||
; rdar://10412592
|
||||
|
||||
; Note: The Thumb code is being generated by the target-independent selector.
|
||||
|
||||
define void @t1() nounwind {
|
||||
entry:
|
||||
; ARM: t1
|
||||
; THUMB: t1
|
||||
; ARM: mvn r0, #0
|
||||
; THUMB: movw r0, #65535
|
||||
; THUMB: movt r0, #65535
|
||||
; CHECK-LABEL: t1
|
||||
; CHECK: mvn r0, #0
|
||||
call void @foo(i32 -1)
|
||||
ret void
|
||||
}
|
||||
@@ -20,22 +16,16 @@ declare void @foo(i32)
|
||||
|
||||
define void @t2() nounwind {
|
||||
entry:
|
||||
; ARM: t2
|
||||
; THUMB: t2
|
||||
; ARM: mvn r0, #233
|
||||
; THUMB: movw r0, #65302
|
||||
; THUMB: movt r0, #65535
|
||||
; CHECK-LABEL: t2
|
||||
; CHECK: mvn r0, #233
|
||||
call void @foo(i32 -234)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @t3() nounwind {
|
||||
entry:
|
||||
; ARM: t3
|
||||
; THUMB: t3
|
||||
; ARM: mvn r0, #256
|
||||
; THUMB: movw r0, #65279
|
||||
; THUMB: movt r0, #65535
|
||||
; CHECK-LABEL: t3
|
||||
; CHECK: mvn r0, #256
|
||||
call void @foo(i32 -257)
|
||||
ret void
|
||||
}
|
||||
@@ -43,66 +33,51 @@ entry:
|
||||
; Load from constant pool
|
||||
define void @t4() nounwind {
|
||||
entry:
|
||||
; ARM: t4
|
||||
; THUMB: t4
|
||||
; ARM: ldr r0
|
||||
; THUMB: movw r0, #65278
|
||||
; THUMB: movt r0, #65535
|
||||
; ARM-LABEL: t4
|
||||
; ARM: ldr r0
|
||||
; THUMB-LABEL: t4
|
||||
; THUMB: movw r0, #65278
|
||||
; THUMB: movt r0, #65535
|
||||
call void @foo(i32 -258)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @t5() nounwind {
|
||||
entry:
|
||||
; ARM: t5
|
||||
; THUMB: t5
|
||||
; ARM: mvn r0, #65280
|
||||
; THUMB: movs r0, #255
|
||||
; THUMB: movt r0, #65535
|
||||
; CHECK-LABEL: t5
|
||||
; CHECK: mvn r0, #65280
|
||||
call void @foo(i32 -65281)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @t6() nounwind {
|
||||
entry:
|
||||
; ARM: t6
|
||||
; THUMB: t6
|
||||
; ARM: mvn r0, #978944
|
||||
; THUMB: movw r0, #4095
|
||||
; THUMB: movt r0, #65521
|
||||
; CHECK-LABEL: t6
|
||||
; CHECK: mvn r0, #978944
|
||||
call void @foo(i32 -978945)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @t7() nounwind {
|
||||
entry:
|
||||
; ARM: t7
|
||||
; THUMB: t7
|
||||
; ARM: mvn r0, #267386880
|
||||
; THUMB: movw r0, #65535
|
||||
; THUMB: movt r0, #61455
|
||||
; CHECK-LABEL: t7
|
||||
; CHECK: mvn r0, #267386880
|
||||
call void @foo(i32 -267386881)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @t8() nounwind {
|
||||
entry:
|
||||
; ARM: t8
|
||||
; THUMB: t8
|
||||
; ARM: mvn r0, #65280
|
||||
; THUMB: movs r0, #255
|
||||
; THUMB: movt r0, #65535
|
||||
; CHECK-LABEL: t8
|
||||
; CHECK: mvn r0, #65280
|
||||
call void @foo(i32 -65281)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @t9() nounwind {
|
||||
entry:
|
||||
; ARM: t9
|
||||
; THUMB: t9
|
||||
; ARM: mvn r0, #2130706432
|
||||
; THUMB: movw r0, #65535
|
||||
; THUMB: movt r0, #33023
|
||||
; CHECK-LABEL: t9
|
||||
; CHECK: mvn r0, #2130706432
|
||||
call void @foo(i32 -2130706433)
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ entry:
|
||||
; ARM: mov r0, r{{[1-9]}}
|
||||
; THUMB: t1
|
||||
; THUMB: movs r{{[1-9]}}, #10
|
||||
; THUMB: movt r{{[1-9]}}, #0
|
||||
; THUMB: cmp r0, #0
|
||||
; THUMB: it eq
|
||||
; THUMB: moveq r{{[1-9]}}, #20
|
||||
@@ -59,13 +58,12 @@ entry:
|
||||
; ARM: cmp r0, #0
|
||||
; ARM: mvneq r{{[1-9]}}, #0
|
||||
; ARM: mov r0, r{{[1-9]}}
|
||||
; THUMB: t4
|
||||
; THUMB: movw r{{[1-9]}}, #65526
|
||||
; THUMB: movt r{{[1-9]}}, #65535
|
||||
; THUMB-LABEL: t4
|
||||
; THUMB: mvn [[REG:r[1-9]+]], #9
|
||||
; THUMB: cmp r0, #0
|
||||
; THUMB: it eq
|
||||
; THUMB: mvneq r{{[1-9]}}, #0
|
||||
; THUMB: mov r0, r{{[1-9]}}
|
||||
; THUMB: mvneq [[REG]], #0
|
||||
; THUMB: mov r0, [[REG]]
|
||||
%0 = select i1 %c, i32 -10, i32 -1
|
||||
ret i32 %0
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ entry:
|
||||
; ARM: bl {{_?CallVariadic}}
|
||||
; THUMB: sub sp, #32
|
||||
; THUMB: movs r0, #5
|
||||
; THUMB: movt r0, #0
|
||||
; THUMB: ldr r1, [sp, #28]
|
||||
; THUMB: ldr r2, [sp, #24]
|
||||
; THUMB: ldr r3, [sp, #20]
|
||||
|
||||
Reference in New Issue
Block a user