#2132: Optimise nested comparisons
---------------------------------+------------------------------------------
    Reporter:  simonpj           |        Owner:  simonpj                
        Type:  bug               |       Status:  patch                  
    Priority:  low               |    Milestone:  7.4.1                  
   Component:  Compiler          |      Version:  6.8.2                  
    Keywords:                    |     Testcase:                         
   Blockedby:                    |   Difficulty:  Unknown                
          Os:  Unknown/Multiple  |     Blocking:                         
Architecture:  Unknown/Multiple  |      Failure:  Runtime performance bug
---------------------------------+------------------------------------------

Comment(by basvandijk):

 Replying to [comment:18 michalt]:
 > Note that this optimization goes a bit further than your example. For
 > instance, once it knows `x ># y` and `y >=# z` it can optimize away `x
 <# z`.

 This is possible with sub-rules:

 {{{
 {-# RULES
 forall x y t f.
   (case (x ># y) of
      True  -> t
      False -> f
   )
   =
   (case (x ># y) of
      True  -> t {{ forall z t2 f2.
                    (case (y >=# z) of
                      True  -> t2
                      False -> f2
                    )
                    =
                    (case (y >=# z) of
                      True  -> t2 {{(x <# z)=False}}
                      False -> f2
                    )
                 }}
      False -> f
   )
   #-}
 }}}


 > Similarly knowing `x ># 100` and `y <# 10` it can get rid of `x ==# y`.
 > That would be probably quite difficult to do with rules (even extended).

 Encoding it for the concrete `100` and `10` is easy. However encoding it
 for all numbers is not possible without having the ability to reason about
 numbers in the language of RULES.

 I'm sure your patch is way more powerful since I expect it will have this
 ability. I do wonder if sub-rules have other useful applications?

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