Commit 91abb987 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Add test for applying specialisations inside InlineRules

parent 20c9800b
......@@ -63,4 +63,8 @@ test('T3717', only_ways(['optc','optasm']),
compile,
['-ddump-simpl -dsuppress-uniques -fno-code'])
test('spec-inline', only_ways(['optc','optasm']),
compile,
['-O2 -ddump-simpl -dsuppress-uniques -fno-code'])
{- This test checks that specialiations can apply inside
wrappers. In particular, the wrapper for 'foo' should
look like
Tmpl= \ (n_aal [Occ=Once!] :: GHC.Types.Int) ->
case n_aal of _ { GHC.Types.I# ipv_smZ [Occ=Once] ->
case Roman.foo_$s$wgo ipv_smZ 6 of ww_spp { __DEFAULT ->
GHC.Types.I# ww_spp
}
}}]
Note the $s$wgo. That in turn allows $wgo to be dead code.
-}
module Roman where
foo :: Int -> Int
foo n = n `seq` go (Just n) (Just (6::Int))
where
go u (Just x)
= x `seq`
case u of
Nothing -> go (Just 10) (Just m)
Just n
| n <= 0 -> 0
| n < 100 -> go (Just (n-2)) (Just x)
| n < 500 -> go (Just (n-3)) (Just m)
| otherwise -> go (Just (n-1)) (Just (m+m))
where
m = x+x+x+x+x+x+x
==================== Tidy Core ====================
Roman.foo2 :: GHC.Types.Int
[GblId,
Caf=NoCafRefs,
Str=DmdType m,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=0, Value=True,
ConLike=True, Cheap=True, Expandable=True,
Guidance=IF_ARGS [] 1 2}]
Roman.foo2 = GHC.Types.I# 6
Roman.foo1 :: Data.Maybe.Maybe GHC.Types.Int
[GblId,
Caf=NoCafRefs,
Str=DmdType,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=0, Value=True,
ConLike=True, Cheap=True, Expandable=True,
Guidance=IF_ARGS [] 1 2}]
Roman.foo1 = Data.Maybe.Just @ GHC.Types.Int Roman.foo2
Roman.foo3 :: GHC.Types.Int
[GblId, Str=DmdType b]
Roman.foo3 =
Control.Exception.Base.patError
@ GHC.Types.Int "spec-inline.hs:(19,5)-(29,25)|function go"
Rec {
Roman.foo_$s$wgo1 [Occ=LoopBreaker]
:: GHC.Prim.Int# -> GHC.Prim.Int# -> GHC.Prim.Int#
[GblId, Arity=2, Caf=NoCafRefs, Str=DmdType LL]
Roman.foo_$s$wgo1 =
\ (sc :: GHC.Prim.Int#) (sc1 :: GHC.Prim.Int#) ->
let {
a [Dmd=Just L] :: GHC.Prim.Int#
[LclId, Str=DmdType]
a =
GHC.Prim.+#
(GHC.Prim.+#
(GHC.Prim.+#
(GHC.Prim.+# (GHC.Prim.+# (GHC.Prim.+# sc1 sc1) sc1) sc1) sc1)
sc1)
sc1 } in
case GHC.Prim.<=# sc 0 of _ {
GHC.Bool.False ->
case GHC.Prim.<# sc 100 of _ {
GHC.Bool.False ->
case GHC.Prim.<# sc 500 of _ {
GHC.Bool.False ->
Roman.foo_$s$wgo1 (GHC.Prim.-# sc 1) (GHC.Prim.+# a a);
GHC.Bool.True -> Roman.foo_$s$wgo1 (GHC.Prim.-# sc 3) a
};
GHC.Bool.True -> Roman.foo_$s$wgo1 (GHC.Prim.-# sc 2) sc1
};
GHC.Bool.True -> 0
}
end Rec }
Roman.foo_$s$wgo :: GHC.Prim.Int# -> GHC.Types.Int -> GHC.Prim.Int#
[GblId,
Arity=2,
Caf=NoCafRefs,
Str=DmdType LL,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=2, Value=True,
ConLike=True, Cheap=True, Expandable=True,
Guidance=IF_ARGS [0 2] 29 0}]
Roman.foo_$s$wgo =
\ (sc :: GHC.Prim.Int#) (sc1 :: GHC.Types.Int) ->
case sc1 of _ { GHC.Types.I# ipv ->
let {
a [Dmd=Just L] :: GHC.Prim.Int#
[LclId, Str=DmdType]
a =
GHC.Prim.+#
(GHC.Prim.+#
(GHC.Prim.+#
(GHC.Prim.+# (GHC.Prim.+# (GHC.Prim.+# ipv ipv) ipv) ipv) ipv)
ipv)
ipv } in
case GHC.Prim.<=# sc 0 of _ {
GHC.Bool.False ->
case GHC.Prim.<# sc 100 of _ {
GHC.Bool.False ->
case GHC.Prim.<# sc 500 of _ {
GHC.Bool.False ->
Roman.foo_$s$wgo1 (GHC.Prim.-# sc 1) (GHC.Prim.+# a a);
GHC.Bool.True -> Roman.foo_$s$wgo1 (GHC.Prim.-# sc 3) a
};
GHC.Bool.True -> Roman.foo_$s$wgo1 (GHC.Prim.-# sc 2) ipv
};
GHC.Bool.True -> 0
}
}
Roman.$wgo
:: Data.Maybe.Maybe GHC.Types.Int
-> Data.Maybe.Maybe GHC.Types.Int
-> GHC.Prim.Int#
[GblId,
Arity=2,
Str=DmdType SS,
Unf=Unf{Src=<vanilla>, TopLvl=True, Arity=2, Value=True,
ConLike=True, Cheap=True, Expandable=True,
Guidance=IF_ARGS [6 3] 37 0}]
Roman.$wgo =
\ (w :: Data.Maybe.Maybe GHC.Types.Int)
(w1 :: Data.Maybe.Maybe GHC.Types.Int) ->
case w1 of _ {
Data.Maybe.Nothing ->
Roman.foo3
`cast` (CoUnsafe GHC.Types.Int GHC.Prim.Int#
:: GHC.Types.Int ~ GHC.Prim.Int#);
Data.Maybe.Just x ->
case x of x1 { GHC.Types.I# ipv ->
let {
a [Dmd=Just L] :: GHC.Prim.Int#
[LclId, Str=DmdType]
a =
GHC.Prim.+#
(GHC.Prim.+#
(GHC.Prim.+#
(GHC.Prim.+# (GHC.Prim.+# (GHC.Prim.+# ipv ipv) ipv) ipv) ipv)
ipv)
ipv } in
case w of _ {
Data.Maybe.Nothing -> Roman.foo_$s$wgo1 10 a;
Data.Maybe.Just n ->
case n of _ { GHC.Types.I# x2 ->
case GHC.Prim.<=# x2 0 of _ {
GHC.Bool.False ->
case GHC.Prim.<# x2 100 of _ {
GHC.Bool.False ->
case GHC.Prim.<# x2 500 of _ {
GHC.Bool.False ->
Roman.foo_$s$wgo1 (GHC.Prim.-# x2 1) (GHC.Prim.+# a a);
GHC.Bool.True -> Roman.foo_$s$wgo1 (GHC.Prim.-# x2 3) a
};
GHC.Bool.True -> Roman.foo_$s$wgo (GHC.Prim.-# x2 2) x1
};
GHC.Bool.True -> 0
}
}
}
}
}
Roman.foo_go [InlPrag=INLINE [0]]
:: Data.Maybe.Maybe GHC.Types.Int
-> Data.Maybe.Maybe GHC.Types.Int
-> GHC.Types.Int
[GblId,
Arity=2,
Str=DmdType SSm,
Unf=Unf{Src=Worker=Roman.$wgo, TopLvl=True, Arity=2, Value=True,
ConLike=True, Cheap=True, Expandable=True,
Guidance=ALWAYS_IF(sat_ok=True,boring_ok=False)
Tmpl= \ (w [Occ=Once] :: Data.Maybe.Maybe GHC.Types.Int)
(w1 [Occ=Once] :: Data.Maybe.Maybe GHC.Types.Int) ->
case Roman.$wgo w w1 of ww { __DEFAULT -> GHC.Types.I# ww }}]
Roman.foo_go =
\ (w :: Data.Maybe.Maybe GHC.Types.Int)
(w1 :: Data.Maybe.Maybe GHC.Types.Int) ->
case Roman.$wgo w w1 of ww { __DEFAULT -> GHC.Types.I# ww }
Roman.foo :: GHC.Types.Int -> GHC.Types.Int
[GblId,
Arity=1,
Caf=NoCafRefs,
Str=DmdType S(A)m,
Unf=Unf{Src=InlineRule, TopLvl=True, Arity=1, Value=True,
ConLike=True, Cheap=True, Expandable=True,
Guidance=ALWAYS_IF(sat_ok=True,boring_ok=False)
Tmpl= \ (n [Occ=Once!] :: GHC.Types.Int) ->
case n of n1 { GHC.Types.I# _ ->
Roman.foo_go (Data.Maybe.Just @ GHC.Types.Int n1) Roman.foo1
}}]
Roman.foo =
\ (n :: GHC.Types.Int) ->
case n of _ { GHC.Types.I# ipv ->
case Roman.foo_$s$wgo1 ipv 6 of ww { __DEFAULT -> GHC.Types.I# ww }
}
------ Local rules for imported ids --------
"SC:$wgo0" ALWAYS
forall {sc :: GHC.Prim.Int# sc1 :: GHC.Prim.Int#}
Roman.$wgo (Data.Maybe.Just @ GHC.Types.Int (GHC.Types.I# sc))
(Data.Maybe.Just @ GHC.Types.Int (GHC.Types.I# sc1))
= Roman.foo_$s$wgo1 sc sc1
"SC:$wgo1" ALWAYS
forall {sc :: GHC.Prim.Int# sc1 :: GHC.Types.Int}
Roman.$wgo (Data.Maybe.Just @ GHC.Types.Int (GHC.Types.I# sc))
(Data.Maybe.Just @ GHC.Types.Int sc1)
= Roman.foo_$s$wgo sc sc1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment