2015-09-23 01:22:58 +08:00
|
|
|
; RUN: llc < %s -mtriple=arm-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARM
|
|
|
|
; RUN: llc < %s -mtriple=thumb-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMB
|
Replace the result usages while legalizing cmpxchg.
We should update the usages to all of the results;
otherwise, we might get assertion failure or SEGV during
the type legalization of ATOMIC_CMP_SWAP_WITH_SUCCESS
with two or more illegal types.
For example, in the following sequence, both i8 and i1
might be illegal in some target, e.g. armv5, mipsel, mips64el,
%0 = cmpxchg i8* %ptr, i8 %desire, i8 %new monotonic monotonic
%1 = extractvalue { i8, i1 } %0, 1
Since both i8 and i1 should be legalized, the corresponding
ATOMIC_CMP_SWAP_WITH_SUCCESS dag will be checked/replaced/updated
twice.
If we don't update the usage to *ALL* of the results in the
first round, the DAG for extractvalue might be processed earlier.
The GetPromotedInteger() will result in assertion failure,
because its operand (i.e. the success bit of cmpxchg) is not
promoted beforehand.
llvm-svn: 213569
2014-07-22 01:33:44 +08:00
|
|
|
|
2015-09-26 08:14:02 +08:00
|
|
|
; RUN: llc < %s -mtriple=armv6-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARMV6
|
|
|
|
; RUN: llc < %s -mtriple=thumbv6-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMBV6
|
|
|
|
|
2015-09-23 01:22:58 +08:00
|
|
|
; RUN: llc < %s -mtriple=armv7-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARMV7
|
|
|
|
; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -asm-verbose=false -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMBV7
|
Replace the result usages while legalizing cmpxchg.
We should update the usages to all of the results;
otherwise, we might get assertion failure or SEGV during
the type legalization of ATOMIC_CMP_SWAP_WITH_SUCCESS
with two or more illegal types.
For example, in the following sequence, both i8 and i1
might be illegal in some target, e.g. armv5, mipsel, mips64el,
%0 = cmpxchg i8* %ptr, i8 %desire, i8 %new monotonic monotonic
%1 = extractvalue { i8, i1 } %0, 1
Since both i8 and i1 should be legalized, the corresponding
ATOMIC_CMP_SWAP_WITH_SUCCESS dag will be checked/replaced/updated
twice.
If we don't update the usage to *ALL* of the results in the
first round, the DAG for extractvalue might be processed earlier.
The GetPromotedInteger() will result in assertion failure,
because its operand (i.e. the success bit of cmpxchg) is not
promoted beforehand.
llvm-svn: 213569
2014-07-22 01:33:44 +08:00
|
|
|
|
|
|
|
define zeroext i1 @test_cmpxchg_res_i8(i8* %addr, i8 %desired, i8 zeroext %new) {
|
|
|
|
entry:
|
|
|
|
%0 = cmpxchg i8* %addr, i8 %desired, i8 %new monotonic monotonic
|
|
|
|
%1 = extractvalue { i8, i1 } %0, 1
|
|
|
|
ret i1 %1
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-ARM-LABEL: test_cmpxchg_res_i8
|
|
|
|
; CHECK-ARM: bl __sync_val_compare_and_swap_1
|
2018-02-16 17:23:59 +08:00
|
|
|
; CHECK-ARM: sub r0, r0, {{r[0-9]+}}
|
|
|
|
; CHECK-ARM: rsbs [[REG:r[0-9]+]], r0, #0
|
|
|
|
; CHECK-ARM: adc r0, r0, [[REG]]
|
Replace the result usages while legalizing cmpxchg.
We should update the usages to all of the results;
otherwise, we might get assertion failure or SEGV during
the type legalization of ATOMIC_CMP_SWAP_WITH_SUCCESS
with two or more illegal types.
For example, in the following sequence, both i8 and i1
might be illegal in some target, e.g. armv5, mipsel, mips64el,
%0 = cmpxchg i8* %ptr, i8 %desire, i8 %new monotonic monotonic
%1 = extractvalue { i8, i1 } %0, 1
Since both i8 and i1 should be legalized, the corresponding
ATOMIC_CMP_SWAP_WITH_SUCCESS dag will be checked/replaced/updated
twice.
If we don't update the usage to *ALL* of the results in the
first round, the DAG for extractvalue might be processed earlier.
The GetPromotedInteger() will result in assertion failure,
because its operand (i.e. the success bit of cmpxchg) is not
promoted beforehand.
llvm-svn: 213569
2014-07-22 01:33:44 +08:00
|
|
|
|
|
|
|
; CHECK-THUMB-LABEL: test_cmpxchg_res_i8
|
|
|
|
; CHECK-THUMB: bl __sync_val_compare_and_swap_1
|
2014-08-21 07:38:50 +08:00
|
|
|
; CHECK-THUMB-NOT: mov [[R1:r[0-7]]], r0
|
2018-02-16 17:23:59 +08:00
|
|
|
; CHECK-THUMB: subs [[R1:r[0-7]]], r0, {{r[0-9]+}}
|
2018-11-01 05:45:48 +08:00
|
|
|
; CHECK-THUMB: rsbs r0, [[R1]], #0
|
2018-02-16 17:23:59 +08:00
|
|
|
; CHECK-THUMB: adcs r0, [[R1]]
|
Replace the result usages while legalizing cmpxchg.
We should update the usages to all of the results;
otherwise, we might get assertion failure or SEGV during
the type legalization of ATOMIC_CMP_SWAP_WITH_SUCCESS
with two or more illegal types.
For example, in the following sequence, both i8 and i1
might be illegal in some target, e.g. armv5, mipsel, mips64el,
%0 = cmpxchg i8* %ptr, i8 %desire, i8 %new monotonic monotonic
%1 = extractvalue { i8, i1 } %0, 1
Since both i8 and i1 should be legalized, the corresponding
ATOMIC_CMP_SWAP_WITH_SUCCESS dag will be checked/replaced/updated
twice.
If we don't update the usage to *ALL* of the results in the
first round, the DAG for extractvalue might be processed earlier.
The GetPromotedInteger() will result in assertion failure,
because its operand (i.e. the success bit of cmpxchg) is not
promoted beforehand.
llvm-svn: 213569
2014-07-22 01:33:44 +08:00
|
|
|
|
2015-09-26 08:14:02 +08:00
|
|
|
; CHECK-ARMV6-LABEL: test_cmpxchg_res_i8:
|
|
|
|
; CHECK-ARMV6-NEXT: .fnstart
|
|
|
|
; CHECK-ARMV6-NEXT: uxtb [[DESIRED:r[0-9]+]], r1
|
|
|
|
; CHECK-ARMV6-NEXT: [[TRY:.LBB[0-9_]+]]:
|
|
|
|
; CHECK-ARMV6-NEXT: ldrexb [[LD:r[0-9]+]], [r0]
|
|
|
|
; CHECK-ARMV6-NEXT: cmp [[LD]], [[DESIRED]]
|
2016-10-21 02:06:52 +08:00
|
|
|
; CHECK-ARMV6-NEXT: movne [[RES:r[0-9]+]], #0
|
|
|
|
; CHECK-ARMV6-NEXT: bxne lr
|
2015-09-26 08:14:02 +08:00
|
|
|
; CHECK-ARMV6-NEXT: strexb [[SUCCESS:r[0-9]+]], r2, [r0]
|
|
|
|
; CHECK-ARMV6-NEXT: cmp [[SUCCESS]], #0
|
2016-10-21 02:06:52 +08:00
|
|
|
; CHECK-ARMV6-NEXT: moveq [[RES]], #1
|
|
|
|
; CHECK-ARMV6-NEXT: bxeq lr
|
|
|
|
; CHECK-ARMV6-NEXT: b [[TRY]]
|
2015-09-26 08:14:02 +08:00
|
|
|
|
|
|
|
; CHECK-THUMBV6-LABEL: test_cmpxchg_res_i8:
|
|
|
|
; CHECK-THUMBV6: mov [[EXPECTED:r[0-9]+]], r1
|
|
|
|
; CHECK-THUMBV6-NEXT: bl __sync_val_compare_and_swap_1
|
2018-02-16 17:23:59 +08:00
|
|
|
; CHECK-THUMBV6-NEXT: uxtb r1, r4
|
|
|
|
; CHECK-THUMBV6-NEXT: subs [[R1:r[0-7]]], r0, {{r[0-9]+}}
|
2018-11-01 05:45:48 +08:00
|
|
|
; CHECK-THUMBV6-NEXT: rsbs r0, [[R1]], #0
|
2018-02-16 17:23:59 +08:00
|
|
|
; CHECK-THUMBV6-NEXT: adcs r0, [[R1]]
|
2015-09-26 08:14:02 +08:00
|
|
|
|
2015-09-23 01:22:58 +08:00
|
|
|
; CHECK-ARMV7-LABEL: test_cmpxchg_res_i8:
|
|
|
|
; CHECK-ARMV7-NEXT: .fnstart
|
|
|
|
; CHECK-ARMV7-NEXT: uxtb [[DESIRED:r[0-9]+]], r1
|
2019-08-30 03:03:58 +08:00
|
|
|
; CHECK-ARMV7-NEXT: [[TRY:.LBB[0-9_]+]]:
|
|
|
|
; CHECK-ARMV7-NEXT: ldrexb [[SUCCESS:r[0-9]+]], [r0]
|
|
|
|
; CHECK-ARMV7-NEXT: cmp [[SUCCESS]], r1
|
|
|
|
; CHECK-ARMV7-NEXT: bne [[EXIT:.LBB[0-9_]+]]
|
|
|
|
; CHECK-ARMV7-NEXT: strexb [[SUCCESS]], r2, [r0]
|
2016-10-19 09:18:25 +08:00
|
|
|
; CHECK-ARMV7-NEXT: cmp [[SUCCESS]], #0
|
Codegen: Make chains from trellis-shaped CFGs
Lay out trellis-shaped CFGs optimally.
A trellis of the shape below:
A B
|\ /|
| \ / |
| X |
| / \ |
|/ \|
C D
would be laid out A; B->C ; D by the current layout algorithm. Now we identify
trellises and lay them out either A->C; B->D or A->D; B->C. This scales with an
increasing number of predecessors. A trellis is a a group of 2 or more
predecessor blocks that all have the same successors.
because of this we can tail duplicate to extend existing trellises.
As an example consider the following CFG:
B D F H
/ \ / \ / \ / \
A---C---E---G---Ret
Where A,C,E,G are all small (Currently 2 instructions).
The CFG preserving layout is then A,B,C,D,E,F,G,H,Ret.
The current code will copy C into B, E into D and G into F and yield the layout
A,C,B(C),E,D(E),F(G),G,H,ret
define void @straight_test(i32 %tag) {
entry:
br label %test1
test1: ; A
%tagbit1 = and i32 %tag, 1
%tagbit1eq0 = icmp eq i32 %tagbit1, 0
br i1 %tagbit1eq0, label %test2, label %optional1
optional1: ; B
call void @a()
br label %test2
test2: ; C
%tagbit2 = and i32 %tag, 2
%tagbit2eq0 = icmp eq i32 %tagbit2, 0
br i1 %tagbit2eq0, label %test3, label %optional2
optional2: ; D
call void @b()
br label %test3
test3: ; E
%tagbit3 = and i32 %tag, 4
%tagbit3eq0 = icmp eq i32 %tagbit3, 0
br i1 %tagbit3eq0, label %test4, label %optional3
optional3: ; F
call void @c()
br label %test4
test4: ; G
%tagbit4 = and i32 %tag, 8
%tagbit4eq0 = icmp eq i32 %tagbit4, 0
br i1 %tagbit4eq0, label %exit, label %optional4
optional4: ; H
call void @d()
br label %exit
exit:
ret void
}
here is the layout after D27742:
straight_test: # @straight_test
; ... Prologue elided
; BB#0: # %entry ; A (merged with test1)
; ... More prologue elided
mr 30, 3
andi. 3, 30, 1
bc 12, 1, .LBB0_2
; BB#1: # %test2 ; C
rlwinm. 3, 30, 0, 30, 30
beq 0, .LBB0_3
b .LBB0_4
.LBB0_2: # %optional1 ; B (copy of C)
bl a
nop
rlwinm. 3, 30, 0, 30, 30
bne 0, .LBB0_4
.LBB0_3: # %test3 ; E
rlwinm. 3, 30, 0, 29, 29
beq 0, .LBB0_5
b .LBB0_6
.LBB0_4: # %optional2 ; D (copy of E)
bl b
nop
rlwinm. 3, 30, 0, 29, 29
bne 0, .LBB0_6
.LBB0_5: # %test4 ; G
rlwinm. 3, 30, 0, 28, 28
beq 0, .LBB0_8
b .LBB0_7
.LBB0_6: # %optional3 ; F (copy of G)
bl c
nop
rlwinm. 3, 30, 0, 28, 28
beq 0, .LBB0_8
.LBB0_7: # %optional4 ; H
bl d
nop
.LBB0_8: # %exit ; Ret
ld 30, 96(1) # 8-byte Folded Reload
addi 1, 1, 112
ld 0, 16(1)
mtlr 0
blr
The tail-duplication has produced some benefit, but it has also produced a
trellis which is not laid out optimally. With this patch, we improve the layouts
of such trellises, and decrease the cost calculation for tail-duplication
accordingly.
This patch produces the layout A,C,E,G,B,D,F,H,Ret. This layout does have
back edges, which is a negative, but it has a bigger compensating
positive, which is that it handles the case where there are long strings
of skipped blocks much better than the original layout. Both layouts
handle runs of executed blocks equally well. Branch prediction also
improves if there is any correlation between subsequent optional blocks.
Here is the resulting concrete layout:
straight_test: # @straight_test
; BB#0: # %entry ; A (merged with test1)
mr 30, 3
andi. 3, 30, 1
bc 12, 1, .LBB0_4
; BB#1: # %test2 ; C
rlwinm. 3, 30, 0, 30, 30
bne 0, .LBB0_5
.LBB0_2: # %test3 ; E
rlwinm. 3, 30, 0, 29, 29
bne 0, .LBB0_6
.LBB0_3: # %test4 ; G
rlwinm. 3, 30, 0, 28, 28
bne 0, .LBB0_7
b .LBB0_8
.LBB0_4: # %optional1 ; B (Copy of C)
bl a
nop
rlwinm. 3, 30, 0, 30, 30
beq 0, .LBB0_2
.LBB0_5: # %optional2 ; D (Copy of E)
bl b
nop
rlwinm. 3, 30, 0, 29, 29
beq 0, .LBB0_3
.LBB0_6: # %optional3 ; F (Copy of G)
bl c
nop
rlwinm. 3, 30, 0, 28, 28
beq 0, .LBB0_8
.LBB0_7: # %optional4 ; H
bl d
nop
.LBB0_8: # %exit
Differential Revision: https://reviews.llvm.org/D28522
llvm-svn: 295223
2017-02-16 03:49:14 +08:00
|
|
|
; CHECK-ARMV7-NEXT: moveq r0, #1
|
2016-10-21 02:06:52 +08:00
|
|
|
; CHECK-ARMV7-NEXT: bxeq lr
|
2019-08-30 03:03:58 +08:00
|
|
|
; CHECK-ARMV7-NEXT: b [[TRY]]
|
|
|
|
; CHECK-ARMV7-NEXT: [[EXIT]]:
|
Codegen: Make chains from trellis-shaped CFGs
Lay out trellis-shaped CFGs optimally.
A trellis of the shape below:
A B
|\ /|
| \ / |
| X |
| / \ |
|/ \|
C D
would be laid out A; B->C ; D by the current layout algorithm. Now we identify
trellises and lay them out either A->C; B->D or A->D; B->C. This scales with an
increasing number of predecessors. A trellis is a a group of 2 or more
predecessor blocks that all have the same successors.
because of this we can tail duplicate to extend existing trellises.
As an example consider the following CFG:
B D F H
/ \ / \ / \ / \
A---C---E---G---Ret
Where A,C,E,G are all small (Currently 2 instructions).
The CFG preserving layout is then A,B,C,D,E,F,G,H,Ret.
The current code will copy C into B, E into D and G into F and yield the layout
A,C,B(C),E,D(E),F(G),G,H,ret
define void @straight_test(i32 %tag) {
entry:
br label %test1
test1: ; A
%tagbit1 = and i32 %tag, 1
%tagbit1eq0 = icmp eq i32 %tagbit1, 0
br i1 %tagbit1eq0, label %test2, label %optional1
optional1: ; B
call void @a()
br label %test2
test2: ; C
%tagbit2 = and i32 %tag, 2
%tagbit2eq0 = icmp eq i32 %tagbit2, 0
br i1 %tagbit2eq0, label %test3, label %optional2
optional2: ; D
call void @b()
br label %test3
test3: ; E
%tagbit3 = and i32 %tag, 4
%tagbit3eq0 = icmp eq i32 %tagbit3, 0
br i1 %tagbit3eq0, label %test4, label %optional3
optional3: ; F
call void @c()
br label %test4
test4: ; G
%tagbit4 = and i32 %tag, 8
%tagbit4eq0 = icmp eq i32 %tagbit4, 0
br i1 %tagbit4eq0, label %exit, label %optional4
optional4: ; H
call void @d()
br label %exit
exit:
ret void
}
here is the layout after D27742:
straight_test: # @straight_test
; ... Prologue elided
; BB#0: # %entry ; A (merged with test1)
; ... More prologue elided
mr 30, 3
andi. 3, 30, 1
bc 12, 1, .LBB0_2
; BB#1: # %test2 ; C
rlwinm. 3, 30, 0, 30, 30
beq 0, .LBB0_3
b .LBB0_4
.LBB0_2: # %optional1 ; B (copy of C)
bl a
nop
rlwinm. 3, 30, 0, 30, 30
bne 0, .LBB0_4
.LBB0_3: # %test3 ; E
rlwinm. 3, 30, 0, 29, 29
beq 0, .LBB0_5
b .LBB0_6
.LBB0_4: # %optional2 ; D (copy of E)
bl b
nop
rlwinm. 3, 30, 0, 29, 29
bne 0, .LBB0_6
.LBB0_5: # %test4 ; G
rlwinm. 3, 30, 0, 28, 28
beq 0, .LBB0_8
b .LBB0_7
.LBB0_6: # %optional3 ; F (copy of G)
bl c
nop
rlwinm. 3, 30, 0, 28, 28
beq 0, .LBB0_8
.LBB0_7: # %optional4 ; H
bl d
nop
.LBB0_8: # %exit ; Ret
ld 30, 96(1) # 8-byte Folded Reload
addi 1, 1, 112
ld 0, 16(1)
mtlr 0
blr
The tail-duplication has produced some benefit, but it has also produced a
trellis which is not laid out optimally. With this patch, we improve the layouts
of such trellises, and decrease the cost calculation for tail-duplication
accordingly.
This patch produces the layout A,C,E,G,B,D,F,H,Ret. This layout does have
back edges, which is a negative, but it has a bigger compensating
positive, which is that it handles the case where there are long strings
of skipped blocks much better than the original layout. Both layouts
handle runs of executed blocks equally well. Branch prediction also
improves if there is any correlation between subsequent optional blocks.
Here is the resulting concrete layout:
straight_test: # @straight_test
; BB#0: # %entry ; A (merged with test1)
mr 30, 3
andi. 3, 30, 1
bc 12, 1, .LBB0_4
; BB#1: # %test2 ; C
rlwinm. 3, 30, 0, 30, 30
bne 0, .LBB0_5
.LBB0_2: # %test3 ; E
rlwinm. 3, 30, 0, 29, 29
bne 0, .LBB0_6
.LBB0_3: # %test4 ; G
rlwinm. 3, 30, 0, 28, 28
bne 0, .LBB0_7
b .LBB0_8
.LBB0_4: # %optional1 ; B (Copy of C)
bl a
nop
rlwinm. 3, 30, 0, 30, 30
beq 0, .LBB0_2
.LBB0_5: # %optional2 ; D (Copy of E)
bl b
nop
rlwinm. 3, 30, 0, 29, 29
beq 0, .LBB0_3
.LBB0_6: # %optional3 ; F (Copy of G)
bl c
nop
rlwinm. 3, 30, 0, 28, 28
beq 0, .LBB0_8
.LBB0_7: # %optional4 ; H
bl d
nop
.LBB0_8: # %exit
Differential Revision: https://reviews.llvm.org/D28522
llvm-svn: 295223
2017-02-16 03:49:14 +08:00
|
|
|
; CHECK-ARMV7-NEXT: mov r0, #0
|
2017-06-28 15:07:03 +08:00
|
|
|
; CHECK-ARMV7-NEXT: clrex
|
2015-09-23 01:22:58 +08:00
|
|
|
; CHECK-ARMV7-NEXT: bx lr
|
Replace the result usages while legalizing cmpxchg.
We should update the usages to all of the results;
otherwise, we might get assertion failure or SEGV during
the type legalization of ATOMIC_CMP_SWAP_WITH_SUCCESS
with two or more illegal types.
For example, in the following sequence, both i8 and i1
might be illegal in some target, e.g. armv5, mipsel, mips64el,
%0 = cmpxchg i8* %ptr, i8 %desire, i8 %new monotonic monotonic
%1 = extractvalue { i8, i1 } %0, 1
Since both i8 and i1 should be legalized, the corresponding
ATOMIC_CMP_SWAP_WITH_SUCCESS dag will be checked/replaced/updated
twice.
If we don't update the usage to *ALL* of the results in the
first round, the DAG for extractvalue might be processed earlier.
The GetPromotedInteger() will result in assertion failure,
because its operand (i.e. the success bit of cmpxchg) is not
promoted beforehand.
llvm-svn: 213569
2014-07-22 01:33:44 +08:00
|
|
|
|
2015-09-23 01:22:58 +08:00
|
|
|
; CHECK-THUMBV7-LABEL: test_cmpxchg_res_i8:
|
|
|
|
; CHECK-THUMBV7-NEXT: .fnstart
|
|
|
|
; CHECK-THUMBV7-NEXT: uxtb [[DESIRED:r[0-9]+]], r1
|
2019-08-30 03:03:58 +08:00
|
|
|
; CHECK-THUMBV7-NEXT: [[TRYLD:.LBB[0-9_]+]]
|
|
|
|
; CHECK-THUMBV7-NEXT: ldrexb [[LD:r[0-9]+]], [r0]
|
|
|
|
; CHECK-THUMBV7-NEXT: cmp [[LD]], [[DESIRED]]
|
|
|
|
; CHECK-THUMBV7-NEXT: bne [[EXIT:.LBB[0-9_]+]]
|
2015-09-23 01:22:58 +08:00
|
|
|
; CHECK-THUMBV7-NEXT: strexb [[SUCCESS:r[0-9]+]], r2, [r0]
|
|
|
|
; CHECK-THUMBV7-NEXT: cmp [[SUCCESS]], #0
|
|
|
|
; CHECK-THUMBV7-NEXT: itt eq
|
|
|
|
; CHECK-THUMBV7-NEXT: moveq r0, #1
|
|
|
|
; CHECK-THUMBV7-NEXT: bxeq lr
|
2019-08-30 03:03:58 +08:00
|
|
|
; CHECK-THUMBV7-NEXT: b [[TRYLD]]
|
|
|
|
; CHECK-THUMBV7-NEXT: [[EXIT]]:
|
2015-09-23 01:22:58 +08:00
|
|
|
; CHECK-THUMBV7-NEXT: movs r0, #0
|
2017-06-28 15:07:03 +08:00
|
|
|
; CHECK-THUMBV7-NEXT: clrex
|
2015-09-23 01:22:58 +08:00
|
|
|
; CHECK-THUMBV7-NEXT: bx lr
|