Opened 10 years ago

Last modified 3 years ago

#3767 new bug

SpecConstr for join points

Reported by: simonpj Owned by:
Priority: low Milestone:
Component: Compiler Version: 6.12.1
Keywords: SpecConstr Cc: dterei
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The attached file Spec.hs has a case (from Roman's fusion code) where SpecConstr is not doing the right thing. Let's look at one of the mutually recursive loops that SpecConstr generates for foo:

lvl_rzY :: GHC.Types.Int
lvl_rzY = GHC.Types.I# 2147483647

lvl1_rA0 :: Data.Either.Either GHC.Types.Int GHC.Types.Int
lvl1_rA0 = Data.Either.Left @ GHC.Types.Int @ GHC.Types.Int lvl_rzY

$s$wgo_szT :: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
$s$wgo_szT =
  \ (sc_sz6 :: GHC.Prim.Int#) (sc1_sz7 :: GHC.Prim.Int#) ->
    let {
      $w$j_syG
        :: GHC.Prim.Int#
           -> Data.Either.Either GHC.Types.Int GHC.Types.Int
           -> GHC.Prim.Int#
      [LclId, Arity=2, Str=DmdType LS]
      $w$j_syG =
        \ (ww_sy6 :: GHC.Prim.Int#)
          (w2_sy8 :: Data.Either.Either GHC.Types.Int GHC.Types.Int) ->
          case GHC.Prim.<=# ww_sy6 0 of _ {
            GHC.Bool.False -> $wgo_syE (GHC.Prim.+# sc_sz6 ww_sy6) w2_sy8;
            GHC.Bool.True -> $wgo_syE sc_sz6 w2_sy8
          } } in
    case GHC.Prim.># sc1_sz7 0 of _ {
      GHC.Bool.False -> $s$wgo1_szS sc_sz6 ipv_swo;
      GHC.Bool.True ->
        case sc1_sz7 of wild1_awb {
          __DEFAULT ->
            case GHC.Prim.remInt# wild1_awb 2 of _ {
              __DEFAULT -> $s$wgo_szT sc_sz6 (GHC.Prim.-# wild1_awb 1);
              0 ->
                case w1_syr of _ { GHC.Types.I# ww_sy6 ->
                $w$j_syG
                  ww_sy6
                  (Data.Either.Left
                     @ GHC.Types.Int
                     @ GHC.Types.Int
                     (GHC.Types.I# (GHC.Prim.-# wild1_awb 1)))
                }
            };
          (-2147483648) ->
            case w1_syr of _ { GHC.Types.I# ww_sy6 ->
            $w$j_syG ww_sy6 lvl1_rA0
            }
        }
    };

Note that the join point has an argument of type (Either Int Int) but it is always called with (Left (I# <n>)). This means that the recursive call in the join point is always of the form ($wgo_syE <m> (Left (I# <n>))) and we have a specialisation for that. However the join point itself doesn't scrutinse its argument, and that means that GHC ignores the potential specialisation.

Simon

Attachments (1)

Spec.hs (1.9 KB) - added by simonpj 10 years ago.

Download all attachments as: .zip

Change History (15)

Changed 10 years ago by simonpj

Attachment: Spec.hs added

comment:1 Changed 10 years ago by simonpj

See also #2642, which is more or less the same.

comment:2 Changed 9 years ago by igloo

Milestone: 6.14 branch6.14.1

comment:3 Changed 9 years ago by igloo

Milestone: 7.0.17.0.2

comment:4 Changed 9 years ago by igloo

Milestone: 7.0.27.2.1

comment:5 Changed 8 years ago by dterei

Cc: dterei added

comment:6 Changed 8 years ago by igloo

Milestone: 7.2.17.4.1

comment:7 Changed 8 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:8 Changed 7 years ago by igloo

Milestone: 7.6.17.6.2

comment:9 Changed 5 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:10 Changed 5 years ago by thomie

difficulty: Unknown
Type of failure: None/UnknownRuntime performance bug

comment:11 Changed 5 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:12 Changed 4 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:13 Changed 4 years ago by thomie

Milestone: 8.0.1

comment:14 Changed 3 years ago by simonpj

Keywords: SpecConstr added
Note: See TracTickets for help on using tickets.