Optimize tagToEnum# at Core level
Old comparison primops that returned Bool were implemented by inserting call to tagToEnum#
in the code generator. This call to tagToEnum#
was later optimized away by a special case in the code geenrator (see [[GhcFile(compiler/codeGen/StgCmmExpr.hs)]], Note [case on bool])). Now that we have new comparison primops (see #6135 (closed)) we no longer insert tagToEnum#
in the code generator - all uses of tagToEnum#
come from explicit calls in a source program. But we still have that special case in the code generator to optimize away tagToEnum#
. We should drop that special case in the code generator and handle scrutinizing of tagToEnum#
at the Core level by:
- removing call to
tagToEnum#
in the scrutinee - adding calls to
dataToTag#
in case branches - constant-folding inserted
dataToTag#
Here is an example. This Haskell code:
if tagToEnum# (a ># b)
then E1
else E2
will be translated to this Core:
case tagToEnum# (a ># b) of
True -> E1
False -> E2
and optimized like this:
case a ># b of
dataToTag# True -> E1
dataToTag# False -> E2
>
case a ># b of
1 -> E1
0 -> E2
Trac metadata
Trac field | Value |
---|---|
Version | 7.7 |
Type | Task |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |