#2253: Native code generator could do better
-----------------------------------------+----------------------------------
Reporter: dons | Owner:
Type: run-time performance bug | Status: new
Priority: normal | Milestone:
Component: Compiler (NCG) | Version: 6.8.2
Severity: normal | Resolution:
Keywords: | Testcase:
Architecture: Multiple | Os: Unknown
-----------------------------------------+----------------------------------
Changes (by dons):
* architecture: x86_64 (amd64) => Multiple
Comment:
== Program 3 ==
Source:
{{{
import Data.Array.Vector
main = print . sumU . consU 0xdeadbeef . replicateU (100000000::Int) $
(8::Int)
}}}
Core:
{{{
Main.$s$wfold =
\ (sc_sMc :: Int#) (sc1_sMd :: Int#) ->
case sc_sMc of wild_X13 {
__DEFAULT -> Main.$s$wfold (+# wild_X13 1) (+# sc1_sMd 8);
100000000 -> sc1_sMd
}
}}}
Native backend:
{{{
Main_zdszdwfold_info:
movq %rsi,%rax
cmpq $100000000,%rax
jne .LcND
movq %rdi,%rbx
jmp *(%rbp)
.LcND:
leaq 8(%rdi),%rcx
leaq 1(%rax),%rsi
movq %rcx,%rdi
jmp Main_zdszdwfold_info
}}}
C backend:
{{{
Main_zdszdwfold_info:
cmpq $100000000, %rsi
je .L5
.L3:
leaq 1(%rsi), %rsi
addq $8, %rdi
jmp Main_zdszdwfold_info
.L5:
movq %rdi, %rbx
jmp *(%rbp)
}}}
Runtime:
Native backend: 0.143
C backend: 0.120
== Program 4 ==
Source:
{{{
import Data.Array.Vector
import Data.Bits
main = print . sumU . mapU (`shiftL` 1) . filterU (<20). mapU (*2) . mapU
(+1) . replicateU (100000000::Int) $ (8::Int)
}}}
Core:
{{{
Main.$wfold =
\ (ww_sNZ :: Int#) (ww1_sO3 :: Int#) ->
case ww1_sO3 of wild_X1j {
__DEFAULT -> Main.$wfold (+# ww_sNZ 36) (+# wild_X1j 1);
100000000 -> ww_sNZ
}
}}}
(Ridiculously awesome!)
Native backend:
{{{
Main_zdwfold_info:
movq %rdi,%rax
cmpq $100000000,%rax
jne .LcPY
movq %rsi,%rbx
jmp *(%rbp)
.LcPY:
incq %rax
addq $36,%rsi
movq %rax,%rdi
jmp Main_zdwfold_info
}}}
C backend:
{{{
Main_zdwfold_info:
cmpq $100000000, %rdi
je .L5
.L3:
addq $36, %rsi
leaq 1(%rdi), %rdi
jmp Main_zdwfold_info
.L5:
movq %rsi, %rbx
jmp *(%rbp)
}}}
Runtime:
C backend: 0.120s
Native backend: 0.195s
== Program 5 ==
Source:
{{{
import Data.Array.Vector
import Data.Bits
main = print . sumU . mapU fstS $ zipU
(enumFromToU 1 (100000000 :: Int))
(enumFromToU 2 (100000001 :: Int))
}}}
Core:
{{{
Main.$s$wfold =
\ (sc_sRJ :: Int#)
(sc1_sRK :: Int#)
(sc2_sRL :: Int#) ->
case ># sc1_sRK 100000000 of wild_aM2 {
False ->
case ># sc_sRJ 100000001 of wild1_XMw {
False ->
Main.$s$wfold
(+# sc_sRJ 1) (+# sc1_sRK 1) (+# sc2_sRL sc1_sRK);
True -> sc2_sRL
};
True -> sc2_sRL
}
}}}
Native backend:
{{{
Main_zdszdwfold_info:
cmpq $100000000,%rdi
jg .LcTr
cmpq $100000001,%rsi
jg .LcTu
movq %r8,%rax
addq %rdi,%rax
leaq 1(%rdi),%rcx
incq %rsi
movq %rcx,%rdi
movq %rax,%r8
jmp Main_zdszdwfold_info
.LcTr:
movq %r8,%rbx
jmp *(%rbp)
.LcTu:
movq %r8,%rbx
jmp *(%rbp)
}}}
C backend:
{{{
Main_zdszdwfold_info:
cmpq $100000000, %rdi
jg .L5
cmpq $100000001, %rsi
jg .L5
leaq (%rdi,%r8), %rax
incq %rsi
incq %rdi
movq %rax, %r8
jmp Main_zdszdwfold_info
.L3:
.L5:
movq %r8, %rbx
jmp *(%rbp)
}}}
Runtime:
Native backend: 0.216
C backend: 0.194
== Program 6 ==
Source:
{{{
n = 40000000
main = do
let c = replicateU n (2::Double)
a = mapU fromIntegral (enumFromToU 0 (n-1) ) :: UArr Double
print (sumU (zipWithU (*) c a))
}}}
Core
{{{
Main.$s$wfold =
\ (sc_sXT :: Int#)
(sc1_sXU :: Int#)
(sc2_sXV :: Double#) ->
case sc1_sXU of wild_X1h {
__DEFAULT ->
case ># sc_sXT 39999999 of wild1_aMi {
False ->
Main.$s$wfold
(+# sc_sXT 1)
(+# wild_X1h 1)
(+## sc2_sXV (*## 2.0 (int2Double# sc_sXT)));
True -> sc2_sXV
};
40000000 -> sc2_sXV
}
}}}
Native backend:
{{{
Main_zdszdwfold_info:
movq %rdi,%rax
cmpq $40000000,%rax
jne .LcZK
jmp *(%rbp)
.LcZK:
cmpq $39999999,%rsi
jg .LcZN
cvtsi2sdq %rsi,%xmm0
mulsd .LnZP(%rip),%xmm0
movsd %xmm5,%xmm7
addsd %xmm0,%xmm7
incq %rax
incq %rsi
movq %rax,%rdi
movsd %xmm7,%xmm5
jmp Main_zdszdwfold_info
.LcZN:
jmp *(%rbp)
}}}
C backend:
{{{
Main_zdszdwfold_info:
cmpq $40000000, %rdi
je .L9
.L5:
cmpq $39999999, %rsi
jg .L9
cvtsi2sdq %rsi, %xmm0
leaq 1(%rdi), %rdi
incq %rsi
addsd %xmm0, %xmm0
addsd %xmm0, %xmm5
jmp Main_zdszdwfold_info
.L9:
jmp *(%rbp)
}}}
Runtime:
Native backend: 0.192
C backend: 0.142
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2253#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs