[GHC] #2070: Record field selectors are not optimized
GHC
trac at galois.com
Tue Feb 5 05:57:19 EST 2008
#2070: Record field selectors are not optimized
----------------------+-----------------------------------------------------
Reporter: twanvl | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.9
Severity: normal | Resolution:
Keywords: | Difficulty: Unknown
Testcase: | Architecture: Unknown
Os: Unknown |
----------------------+-----------------------------------------------------
Changes (by simonpj):
* difficulty: => Unknown
Comment:
Here's another example, found by Twan van Laarhoven, in GHC itself, module
`Var.lhs`.
When also trying to change the `FastInt` in `Var` to an unpacked `Unique`
I ran into #2070. If I write it out `varUnique` manually I do get a good
result, but not exactly the same. In particular I get:
{{{
NewVar.varUnique =
\r [ds]
case ds of wild {
NewVar.TyVar ds1 rb ds2 ds3 -> GHC.Base.I# [rb];
NewVar.TcTyVar ds1 rb ds2 ds3 -> GHC.Base.I# [rb];
NewVar.GlobalId ds1 rb ds2 ds3 ds4 -> GHC.Base.I# [rb];
NewVar.LocalId ds1 rb ds2 ds3 ds4 -> GHC.Base.I# [rb];
};
}}}
But the automatically generated one looks like this:
{{{
OldVar.varUnique =
\r [var]
case
case var of tpl {
OldVar.TyVar ipv ipv1 ipv2 ipv3 -> ipv1;
OldVar.TcTyVar ipv ipv1 ipv2 ipv3 -> ipv1;
OldVar.GlobalId ipv ipv1 ipv2 ipv3 ipv4 -> ipv1;
OldVar.LocalId ipv ipv1 ipv2 ipv3 ipv4 -> ipv1;
}
of
wild
{ __DEFAULT -> GHC.Base.I# [wild];
};
}}}
In other words, the boxing is taken out of the case branches. I don't know
whether this is an improvement or not. It might reduce code size.
This function
is inlined in the comparison operators, here the difference becomes
larger. The
new code looks like (pseudocode):
{{{
NewVar.== a b
= case a of
TyVar _ c _ _ ->
case b of
TyVar _ d _ _ -> c ==# d
TcTyVar _ d _ _ -> c ==# d
GlobalId _ d _ _ _ -> c ==# d
LocalId _ d _ _ _ -> c ==# d
TcTyVar _ c _ _ ->
etc.
}}}
Here `varUnique b` is inlined for each branch of `varUnique a`. Whereas
the old
code is a lot shorter, because the unique of the first parameter is first
put
into a variable,
{{{
OldVar.== a b
= case (case a of
TyVar _ c _ _ -> c
TcTyVar _ c _ _ -> c
GlobalId _ c _ _ _ -> c
LocalId _ c _ _ _ -> c
) of
c -> case (case b of
TyVar _ d _ _ -> d
TcTyVar _ d _ _ -> d
GlobalId _ d _ _ _ -> d
LocalId _ d _ _ _ -> d
) of
d -> c ==# d
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2070#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list