Opened 3 years ago

Last modified 21 months ago

#13157 new bug

Opportunity to improve case-of-case

Reported by: simonpj Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: JoinPoints Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Consider this code

f g x = (case g x of True  -> not
                     False -> id) `seq` True

With GHC 8 (and -O) we get this Core

f =
  \ (@ t_a1rk) (g_aqD :: t -> Bool) (x_aqE :: t) ->
    case case g_aqD x_aqE of {
           False -> id @ Bool;
           True -> not
         }
    of
    { __DEFAULT ->
    GHC.Types.True
    }

This is obviously bad.

The reasoning is in the long, complicated Note [Single-alternative cases] in Simplify.hs.

Happily with join points the entire Note becomes unnecessary; we can delete the special case that this Note describes, and the Note itself. Result: simpler compiler, and more optimal code.

Change History (2)

comment:1 Changed 3 years ago by simonpj

Keywords: JoinPoints added

comment:2 Changed 21 months ago by nickkuk

It seems to be fixed, namely, GHC-8.2.1 with "-ddump-simpl -O" gives

f = \ (@ t_a1TX) (g_ap0 :: t_a1TX -> Bool) (x_ap1 :: t_a1TX) ->
      case g_ap0 x_ap1 of { __DEFAULT -> GHC.Types.True }

I will try to add test.

Note: See TracTickets for help on using tickets.