2017-01-13 03:29:18 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
|
2017-01-13 03:48:01 +08:00
|
|
|
; Check that 32-bit division is bypassed correctly.
|
|
|
|
; RUN: llc < %s -mattr=+idivl-to-divb -mtriple=i686-linux | FileCheck %s
|
2012-09-05 02:22:17 +08:00
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_get_quotient(i32 %a, i32 %b) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_get_quotient:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl %eax, %edx
|
|
|
|
; CHECK-NEXT: orl %ecx, %edx
|
|
|
|
; CHECK-NEXT: testl $-256, %edx
|
|
|
|
; CHECK-NEXT: je .LBB0_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK-NEXT: # %bb.2:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: cltd
|
|
|
|
; CHECK-NEXT: idivl %ecx
|
|
|
|
; CHECK-NEXT: retl
|
|
|
|
; CHECK-NEXT: .LBB0_1:
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: divb %cl
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%result = sdiv i32 %a, %b
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_get_remainder(i32 %a, i32 %b) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_get_remainder:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl %eax, %edx
|
|
|
|
; CHECK-NEXT: orl %ecx, %edx
|
|
|
|
; CHECK-NEXT: testl $-256, %edx
|
|
|
|
; CHECK-NEXT: je .LBB1_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK-NEXT: # %bb.2:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: cltd
|
|
|
|
; CHECK-NEXT: idivl %ecx
|
|
|
|
; CHECK-NEXT: movl %edx, %eax
|
|
|
|
; CHECK-NEXT: retl
|
|
|
|
; CHECK-NEXT: .LBB1_1:
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: divb %cl
|
2018-01-23 13:37:00 +08:00
|
|
|
; CHECK-NEXT: movzbl %ah, %eax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%result = srem i32 %a, %b
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_get_quotient_and_remainder(i32 %a, i32 %b) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_get_quotient_and_remainder:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl %eax, %edx
|
|
|
|
; CHECK-NEXT: orl %ecx, %edx
|
|
|
|
; CHECK-NEXT: testl $-256, %edx
|
|
|
|
; CHECK-NEXT: je .LBB2_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK-NEXT: # %bb.2:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: cltd
|
|
|
|
; CHECK-NEXT: idivl %ecx
|
|
|
|
; CHECK-NEXT: addl %edx, %eax
|
|
|
|
; CHECK-NEXT: retl
|
|
|
|
; CHECK-NEXT: .LBB2_1:
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: divb %cl
|
2018-01-23 13:37:00 +08:00
|
|
|
; CHECK-NEXT: movzbl %ah, %edx
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
|
|
|
; CHECK-NEXT: addl %edx, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultdiv = sdiv i32 %a, %b
|
|
|
|
%resultrem = srem i32 %a, %b
|
|
|
|
%result = add i32 %resultdiv, %resultrem
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_div_and_idiv(i32 %a, i32 %b) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_div_and_idiv:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: pushl %ebx
|
|
|
|
; CHECK-NEXT: pushl %edi
|
|
|
|
; CHECK-NEXT: pushl %esi
|
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ebx
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl %ecx, %edi
|
|
|
|
; CHECK-NEXT: orl %ebx, %edi
|
|
|
|
; CHECK-NEXT: testl $-256, %edi
|
|
|
|
; CHECK-NEXT: je .LBB3_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK-NEXT: # %bb.2:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl %ecx, %eax
|
|
|
|
; CHECK-NEXT: cltd
|
|
|
|
; CHECK-NEXT: idivl %ebx
|
|
|
|
; CHECK-NEXT: movl %eax, %esi
|
|
|
|
; CHECK-NEXT: testl $-256, %edi
|
|
|
|
; CHECK-NEXT: je .LBB3_4
|
|
|
|
; CHECK-NEXT: .LBB3_5:
|
|
|
|
; CHECK-NEXT: xorl %edx, %edx
|
|
|
|
; CHECK-NEXT: movl %ecx, %eax
|
|
|
|
; CHECK-NEXT: divl %ebx
|
|
|
|
; CHECK-NEXT: jmp .LBB3_6
|
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-NEXT: .LBB3_1:
|
|
|
|
; CHECK-NEXT: movzbl %cl, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
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-NEXT: divb %bl
|
|
|
|
; CHECK-NEXT: movzbl %al, %esi
|
|
|
|
; CHECK-NEXT: testl $-256, %edi
|
|
|
|
; CHECK-NEXT: jne .LBB3_5
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: .LBB3_4:
|
|
|
|
; CHECK-NEXT: movzbl %cl, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: divb %bl
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
|
|
|
; CHECK-NEXT: .LBB3_6:
|
|
|
|
; CHECK-NEXT: addl %eax, %esi
|
|
|
|
; CHECK-NEXT: movl %esi, %eax
|
|
|
|
; CHECK-NEXT: popl %esi
|
|
|
|
; CHECK-NEXT: popl %edi
|
|
|
|
; CHECK-NEXT: popl %ebx
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultidiv = sdiv i32 %a, %b
|
|
|
|
%resultdiv = udiv i32 %a, %b
|
|
|
|
%result = add i32 %resultidiv, %resultdiv
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_div_imm_imm() nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_div_imm_imm:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl $64, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultdiv = sdiv i32 256, 4
|
|
|
|
ret i32 %resultdiv
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_div_reg_imm(i32 %a) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_div_reg_imm:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl $1041204193, %eax # imm = 0x3E0F83E1
|
|
|
|
; CHECK-NEXT: imull {{[0-9]+}}(%esp)
|
|
|
|
; CHECK-NEXT: movl %edx, %eax
|
|
|
|
; CHECK-NEXT: shrl $31, %eax
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: sarl $3, %edx
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: leal (%edx,%eax), %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultdiv = sdiv i32 %a, 33
|
|
|
|
ret i32 %resultdiv
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_rem_reg_imm(i32 %a) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_rem_reg_imm:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; CHECK-NEXT: movl $1041204193, %edx # imm = 0x3E0F83E1
|
|
|
|
; CHECK-NEXT: movl %ecx, %eax
|
|
|
|
; CHECK-NEXT: imull %edx
|
|
|
|
; CHECK-NEXT: movl %edx, %eax
|
|
|
|
; CHECK-NEXT: shrl $31, %eax
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: sarl $3, %edx
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: addl %eax, %edx
|
|
|
|
; CHECK-NEXT: movl %edx, %eax
|
|
|
|
; CHECK-NEXT: shll $5, %eax
|
|
|
|
; CHECK-NEXT: addl %edx, %eax
|
|
|
|
; CHECK-NEXT: subl %eax, %ecx
|
|
|
|
; CHECK-NEXT: movl %ecx, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultrem = srem i32 %a, 33
|
|
|
|
ret i32 %resultrem
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_divrem_reg_imm(i32 %a) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_divrem_reg_imm:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; CHECK-NEXT: movl $1041204193, %edx # imm = 0x3E0F83E1
|
|
|
|
; CHECK-NEXT: movl %ecx, %eax
|
|
|
|
; CHECK-NEXT: imull %edx
|
|
|
|
; CHECK-NEXT: movl %edx, %eax
|
|
|
|
; CHECK-NEXT: shrl $31, %eax
|
2017-01-13 03:48:01 +08:00
|
|
|
; CHECK-NEXT: sarl $3, %edx
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: addl %eax, %edx
|
|
|
|
; CHECK-NEXT: movl %edx, %eax
|
|
|
|
; CHECK-NEXT: shll $5, %eax
|
|
|
|
; CHECK-NEXT: addl %edx, %eax
|
|
|
|
; CHECK-NEXT: subl %eax, %ecx
|
|
|
|
; CHECK-NEXT: addl %edx, %ecx
|
|
|
|
; CHECK-NEXT: movl %ecx, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultdiv = sdiv i32 %a, 33
|
|
|
|
%resultrem = srem i32 %a, 33
|
|
|
|
%result = add i32 %resultdiv, %resultrem
|
|
|
|
ret i32 %result
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_div_imm_reg(i32 %a) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_div_imm_reg:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; CHECK-NEXT: testl $-256, %ecx
|
|
|
|
; CHECK-NEXT: je .LBB8_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK-NEXT: # %bb.2:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl $4, %eax
|
|
|
|
; CHECK-NEXT: xorl %edx, %edx
|
|
|
|
; CHECK-NEXT: idivl %ecx
|
|
|
|
; CHECK-NEXT: retl
|
|
|
|
; CHECK-NEXT: .LBB8_1:
|
|
|
|
; CHECK-NEXT: movb $4, %al
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: divb %cl
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultdiv = sdiv i32 4, %a
|
|
|
|
ret i32 %resultdiv
|
|
|
|
}
|
|
|
|
|
2012-12-12 21:34:14 +08:00
|
|
|
define i32 @Test_use_rem_imm_reg(i32 %a) nounwind {
|
2013-07-14 14:24:09 +08:00
|
|
|
; CHECK-LABEL: Test_use_rem_imm_reg:
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK: # %bb.0:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
|
|
|
|
; CHECK-NEXT: testl $-256, %ecx
|
|
|
|
; CHECK-NEXT: je .LBB9_1
|
2017-12-05 01:18:51 +08:00
|
|
|
; CHECK-NEXT: # %bb.2:
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: movl $4, %eax
|
|
|
|
; CHECK-NEXT: xorl %edx, %edx
|
|
|
|
; CHECK-NEXT: idivl %ecx
|
|
|
|
; CHECK-NEXT: retl
|
|
|
|
; CHECK-NEXT: .LBB9_1:
|
|
|
|
; CHECK-NEXT: movb $4, %al
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
2018-02-01 06:04:26 +08:00
|
|
|
; CHECK-NEXT: # kill: def $eax killed $eax def $ax
|
2017-01-13 03:29:18 +08:00
|
|
|
; CHECK-NEXT: divb %cl
|
|
|
|
; CHECK-NEXT: movzbl %al, %eax
|
|
|
|
; CHECK-NEXT: retl
|
2012-09-05 02:22:17 +08:00
|
|
|
%resultdiv = sdiv i32 4, %a
|
|
|
|
ret i32 %resultdiv
|
|
|
|
}
|