Simple text fusion example results in rather duplicative code
Consider this program,
module T14221 where
import Data.Text as T
isNumeric :: Text -> Bool
isNumeric t =
T.all isNumeric' t && T.any isNumber t
where
isNumber c = '0' <= c && c <= '9'
isNumeric' c = isNumber c
|| c == 'e'
|| c == 'E'
|| c == '.'
|| c == '-'
|| c == '+'
Compiling with -O
results in over 1 kilobyte of assembler. After looking at the simplified Core the issue becomes apparent: the case analysis of isNumeric'
is duplicated six times,
case ww4_X2zB of {
__DEFAULT -> GHC.Types.False;
'+'# -> jump $wloop_all_s2z2 (GHC.Prim.+# ww3_s2z0 2#);
'-'# -> jump $wloop_all_s2z2 (GHC.Prim.+# ww3_s2z0 2#);
'.'# -> jump $wloop_all_s2z2 (GHC.Prim.+# ww3_s2z0 2#);
'E'# -> jump $wloop_all_s2z2 (GHC.Prim.+# ww3_s2z0 2#);
'e'# -> jump $wloop_all_s2z2 (GHC.Prim.+# ww3_s2z0 2#)
};
It seems to me that we would ideally try to share this bit. Of course, this may be quite tricky to do in practice.
Trac metadata
Trac field | Value |
---|---|
Version | 8.2.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |