Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2011-03-10 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
--+-
  Reporter:  rl   |  Owner:  
  Type:  bug  | Status:  closed  
  Priority:  normal   |  Milestone:  7.2.1   
 Component:  Compiler |Version:  6.13
Resolution:  fixed|   Keywords:  
  Testcase:   |  Blockedby:  
Difficulty:   | Os:  Unknown/Multiple
  Blocking:   |   Architecture:  Unknown/Multiple
   Failure:  Runtime performance bug  |  
--+-

Comment(by michalt):

 Replying to [comment:10 simonpj]:
  The optimisation seems ok, but does this situation ever arise in
 practice?
  Who asks `x  minBound`?
 
  Simon

 Well, I'm pretty sure I've never wrote something like that. ;)

 On the other hand the ticket has been around for a while with a comment or
 two,
 so I thought that the optimization might be useful for someone. But I
 don't
 really feel strongly about it.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:11
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2011-03-10 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
--+-
  Reporter:  rl   |  Owner:  
  Type:  bug  | Status:  new 
  Priority:  normal   |  Milestone:  7.2.1   
 Component:  Compiler |Version:  6.13
Resolution:   |   Keywords:  
  Testcase:   |  Blockedby:  
Difficulty:   | Os:  Unknown/Multiple
  Blocking:   |   Architecture:  Unknown/Multiple
   Failure:  Runtime performance bug  |  
--+-
Changes (by rl):

  * status:  closed = new
  * resolution:  fixed =


Comment:

 Replying to [comment:10 simonpj]:
  The optimisation seems ok, but does this situation ever arise in
 practice?  Who asks `x  minBound`?

 Me! I jump through some hoops in vector to avoid the following problem.

 {{{
 foo :: Num a = a - a
 {-# INLINE foo #-}
 foo x | x  0 = error Negative argument
   | otherwise = e

 bar :: Word - Word
 bar x = foo x + 1
 }}}

 I completely missed the patch, thanks a lot for this! Unfortunately, it
 doesn't handle Int8/Int16/Word8/Word16 and Int32/Word32 on 64 bit systems.
 It isn't very clear how to do this because we only have Int# and Word# in
 Core. Also, the inlining of minBound/maxBound for 64 bit types on 32 bit
 systems which this patch depends on doesn't work reliably. So this ticket
 isn't quite fixed yet but this is good progress!

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:12
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2011-03-09 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
--+-
  Reporter:  rl   |  Owner:  
  Type:  bug  | Status:  closed  
  Priority:  normal   |  Milestone:  7.2.1   
 Component:  Compiler |Version:  6.13
Resolution:  fixed|   Keywords:  
  Testcase:   |  Blockedby:  
Difficulty:   | Os:  Unknown/Multiple
  Blocking:   |   Architecture:  Unknown/Multiple
   Failure:  Runtime performance bug  |  
--+-
Changes (by igloo):

  * status:  patch = closed
  * resolution:  = fixed


Comment:

 Sorry for the delay. Now applied, thanks.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:9
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2011-03-09 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
--+-
  Reporter:  rl   |  Owner:  
  Type:  bug  | Status:  closed  
  Priority:  normal   |  Milestone:  7.2.1   
 Component:  Compiler |Version:  6.13
Resolution:  fixed|   Keywords:  
  Testcase:   |  Blockedby:  
Difficulty:   | Os:  Unknown/Multiple
  Blocking:   |   Architecture:  Unknown/Multiple
   Failure:  Runtime performance bug  |  
--+-

Comment(by simonpj):

 The optimisation seems ok, but does this situation ever arise in practice?
 Who asks `x  minBound`?

 Simon

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:10
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler

___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2010-10-27 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
-+--
Reporter:  rl|Owner: 
Type:  bug   |   Status:  new
Priority:  normal|Milestone:  7.0.1  
   Component:  Compiler  |  Version:  6.13   
Keywords:| Testcase: 
   Blockedby:|   Difficulty: 
  Os:  Unknown/Multiple  | Blocking: 
Architecture:  Unknown/Multiple  |  Failure:  Runtime performance bug
-+--
Changes (by michalt):

 * cc: michal.terep...@… (added)


Comment:

 I've created a patch with rules for PrelRules.lhs that detect comparisons
 with
 minBound and maxBound that are always true or always false (like in the
 above
 examples). And it seems to work just fine:
 {{{
 foo1, foo2, foo3, foo4 :: Int - Bool

 foo1 n = n  minBound

 foo2 n = n  maxBound

 foo3 n = n = minBound

 foo4 n = n = maxBound
 }}}
 gives now
 {{{
 Test.foo1 =
   \ (n_aaD :: GHC.Types.Int) -
 case n_aaD of _ { GHC.Types.I# _ - GHC.Bool.False }

 Test.foo2 =
   \ (n_ag0 :: GHC.Types.Int) -
 case n_ag0 of _ { GHC.Types.I# _ - GHC.Bool.False }

 Test.foo3 =
   \ (n_ag1 :: GHC.Types.Int) -
 case n_ag1 of _ { GHC.Types.I# _ - GHC.Bool.True }

 Test.foo4 =
   \ (n_ag2 :: GHC.Types.Int) -
 case n_ag2 of _ { GHC.Types.I# _ - GHC.Bool.True }
 }}}
 This works fine also for Char, and Word, but interestingly in case of
 Int64 only
 maxBound is inlined, but not minBound (and so foo2 and foo4 are optimised
 but
 not foo1 and foo3), whereas in case of Word64 the opposite happens. For
 example
 by changing the type to Int64 in the above code we have:
 {{{
 Test.foo1 =
   \ (n_aaF :: GHC.Int.Int64) -
 case n_aaF of _ { GHC.Int.I64# a1_ar3 -
 case GHC.Int.$fBoundedInt64_$cminBound
 of _ { GHC.Int.I64# b1_ar7 -
 GHC.Prim.# a1_ar3 b1_ar7
 }
 }

 Test.foo2 =
   \ (n_ag2 :: GHC.Int.Int64) -
 case n_ag2 of _ { GHC.Int.I64# _ - GHC.Bool.False }

 Test.foo3 =
   \ (n_ag3 :: GHC.Int.Int64) -
 case n_ag3 of _ { GHC.Int.I64# a1_arn -
 case GHC.Int.$fBoundedInt64_$cminBound
 of _ { GHC.Int.I64# b1_arr -
 GHC.Prim.=# a1_arn b1_arr
 }
 }

 Test.foo4 =
   \ (n_ag4 :: GHC.Int.Int64) -
 case n_ag4 of _ { GHC.Int.I64# _ - GHC.Bool.True }
 }}}
 Anyway, I'll attach the patch in a second. And please let me know what do
 you
 think about it (especially since I don't really know a lot about GHC
 internals).

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:5
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2010-10-27 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
-+--
Reporter:  rl|Owner: 
Type:  bug   |   Status:  patch  
Priority:  normal|Milestone:  7.0.1  
   Component:  Compiler  |  Version:  6.13   
Keywords:| Testcase: 
   Blockedby:|   Difficulty: 
  Os:  Unknown/Multiple  | Blocking: 
Architecture:  Unknown/Multiple  |  Failure:  Runtime performance bug
-+--
Changes (by michalt):

  * status:  new = patch


-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:6
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2010-10-25 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
-+--
Reporter:  rl|Owner: 
Type:  bug   |   Status:  new
Priority:  normal|Milestone:  7.0.1  
   Component:  Compiler  |  Version:  6.13   
Keywords:| Testcase: 
   Blockedby:|   Difficulty: 
  Os:  Unknown/Multiple  | Blocking: 
Architecture:  Unknown/Multiple  |  Failure:  Runtime performance bug
-+--
Changes (by daniel.is.fischer):

 * cc: daniel.is.fisc...@… (added)


Comment:

 A global
 {{{
 {-# RULES
 ()/minBound  forall x. x  minBound = False
 ()/minBound  forall x. minBound  x = False
 etc.
   #-}
 }}}
 would eliminate those checks in many (almost all, hopefully) cases.
 However, it would break user code relying on incompatible Ord and Enum
 instances (it should not break local bindings for minBound/maxBound since
 the rule refers to GHC.Enum.minBound).

 Alternatively, one could add those rules for every pertinent type, but I'd
 prefer a more general solution.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:3
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2010-10-25 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
-+--
Reporter:  rl|Owner: 
Type:  bug   |   Status:  new
Priority:  normal|Milestone:  7.0.1  
   Component:  Compiler  |  Version:  6.13   
Keywords:| Testcase: 
   Blockedby:|   Difficulty: 
  Os:  Unknown/Multiple  | Blocking: 
Architecture:  Unknown/Multiple  |  Failure:  Runtime performance bug
-+--

Comment(by rl):

 I don't think these rules would work reliably because the comparison
 operators could (and would) be inlined before the rules have had a chance
 to fire. Rules for specific primitive types wouldn't have this problem but
 IIRC, matching against the actual bounds literals can be problematic.

-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:4
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #3744: Comparisons against minBound/maxBound not optimised

2010-01-13 Thread GHC
#3744: Comparisons against minBound/maxBound not optimised
-+--
Reporter:  rl|Owner: 
Type:  bug   |   Status:  new
Priority:  normal|Milestone:  6.14 branch
   Component:  Compiler  |  Version:  6.13   
Keywords:|   Difficulty: 
  Os:  Unknown/Multiple  | Testcase: 
Architecture:  Unknown/Multiple  |  Failure:  Runtime performance bug
-+--
Changes (by igloo):

  * milestone:  = 6.14 branch


-- 
Ticket URL: http://hackage.haskell.org/trac/ghc/ticket/3744#comment:1
GHC http://www.haskell.org/ghc/
The Glasgow Haskell Compiler
___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs