#2130: Mulitple comparisons on Word types produce redundant comparisons
-----------------------------------------+----------------------------------
    Reporter:  dons                      |        Owner:          
        Type:  run-time performance bug  |       Status:  new     
    Priority:  normal                    |    Milestone:          
   Component:  Compiler                  |      Version:  6.8.2   
    Severity:  normal                    |   Resolution:          
    Keywords:  performance, Word         |     Testcase:          
Architecture:  Unknown                   |           Os:  Multiple
-----------------------------------------+----------------------------------
Comment (by dons):

 The extra comparisons bubble through to the final assembly, as you see
 here:



 {{{
 good :: Int -> Bool
 good c | c < 22    = True
        | c < 42     = True
        | otherwise = False
 }}}

 The good Int yields:

 {{{
 good_info:
   cmpq $22,7(%rbx)
   jl .LcgH
   movl $base_GHCziBase_Bool_closure_tbl,%eax
   cmpq $42,7(%rbx)
   setl %cl
   movzbl %cl,%ecx
   movq (%rax,%rcx,8),%rbx
   addq $8,%rbp
   jmp *(%rbp)
 .LcgH:
   movl $base_GHCziBase_True_closure+2,%ebx
   addq $8,%rbp
   jmp *(%rbp)
 }}}

 While our funky Ords for Word:

 {{{
 bad :: Word -> Bool
 bad c | c < 22    = True
       | c < 42     = True
       | otherwise = False
 }}}

 yields:

 {{{
 M_zdwbad_info:
   cmpq $22,%rsi
   je .Lcm7
   cmpq $22,%rsi
   jb .Lcmb
   cmpq $42,%rsi
   je .Lcmd
   movl $base_GHCziBase_Bool_closure_tbl,%eax
   cmpq $42,%rsi
   setb %cl
   movzbl %cl,%ecx
   movq (%rax,%rcx,8),%rbx
   jmp *(%rbp)
 .Lcm7:
   cmpq $42,%rsi
   je .Lcm9
   movl $base_GHCziBase_Bool_closure_tbl,%eax
   cmpq $42,%rsi
   setb %cl
   movzbl %cl,%ecx
   movq (%rax,%rcx,8),%rbx
   jmp *(%rbp)
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2130#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

Reply via email to