Opened 5 years ago

Closed 5 years ago

#4930 closed bug (fixed)

Case-of-case not eliminated when it could be

Reported by: rl Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case: simplCore/should_compile/T4930
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description

Small example:

foo :: Int -> Int
foo n = (if n < 5 then error "Too small" else n+2) `seq` n+5

GHC produces this:

foo =
  \ (w_slQ :: Int) ->
    case w_slQ of _ { I# ww_slT ->
    case case <# ww_slT 5 of _ {
           False -> case +# ww_slT 2 of sat_sm1 { __DEFAULT -> I# sat_sm1 };
           True -> foo1
         }
    of _ { I# _ ->
    case +# ww_slT 5 of sat_sm4 { __DEFAULT -> I# sat_sm4 }
    }
    }

It ought to produce something like this instead:

foo n = case n of I# n# ->
        case n# <# 5 of
          True -> foo1
          False -> I# (n# +# 5)

Change History (1)

comment:1 Changed 5 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to simplCore/should_compile/T4930

Good point. Fixed by

Tue Feb  1 12:26:37 GMT 2011  [email protected]
  * Don't make join points when the case has only one non-bottom alternative
  
  This fixes Trac #4930.  See Note [Bottom alternatives] in Simplify.lhs

    M ./compiler/coreSyn/CoreUtils.lhs -1 +20
    M ./compiler/simplCore/Simplify.lhs -7 +35

I don't think this is worth merging.

Simon

Note: See TracTickets for help on using tickets.