[GHC] #9661: Branchless ==# is compiled to branchy code

GHC ghc-devs at haskell.org
Mon Apr 20 06:13:16 UTC 2015


#9661: Branchless ==# is compiled to branchy code
-------------------------------------+-------------------------------------
        Reporter:  dfeuer            |                   Owner:  bgamari
            Type:  feature request   |                  Status:  new
        Priority:  normal            |               Milestone:
       Component:  Compiler          |                 Version:  7.9
      Resolution:                    |                Keywords:
Operating System:  Unknown/Multiple  |            Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |               Test Case:
      Blocked By:                    |                Blocking:
 Related Tickets:                    |  Differential Revisions:  D854
-------------------------------------+-------------------------------------

Comment (by jstolarek):

 Replying to [comment:25 rwbarton]:
 > Again there is a distinction between the compiler being able to generate
 branchless code and the compiler giving the user control over whether to
 generate branchless code. For example in that benchmark, it would be even
 better if the user could simply write
 >
 > {{{
 >         let inc     = if v >= 0 then 1 else 0
 > }}}
 >
 > rather than
 >
 > {{{
 >         let !(I# v) = x
 >             inc     = I# (v >=$# 0#)
 > }}}
 I wholeheartedly agree - it would be better if the compiler could generate
 optimized branchless code from higher level abstract code. That said, we
 expose low-level primops and it would be a real shame if the users
 couldn't get branchless behaviour from them. Besides, if we want GHC to
 optimize high-level code to branchless code then I suspect it will be much
 easier to implement if primops compiled to branchless code.

 >  So, this isn't an example of the kind that I am talking about.

 I don't follow. Why not? Surely, this is an ugly piece of code written by
 hand but at the moment GHC can't produce such code from high-level code -
 it had to be written by hand.

 So, I don't claim that compiling `==#` to branchless code is the final
 word on this topic. It's just fixing a bug that I didn't notice when
 originally implementing #6135 - `>=#`, `>#`, `<=#` and `<#` already
 compile to branchless code as they were intended to.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9661#comment:26>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list