Simon Jakobi pushed to branch wip/sjakobi/elem-tests at Glasgow Haskell Compiler / GHC
Commits:
-
ae3037e9
by Simon Jakobi at 2026-04-01T14:50:34+02:00
12 changed files:
- + libraries/base/tests/perf/ElemFusionUnknownList.hs
- + libraries/base/tests/perf/ElemFusionUnknownList_O1.stderr
- + libraries/base/tests/perf/ElemFusionUnknownList_O2.stderr
- + libraries/base/tests/perf/ElemNoFusion.hs
- + libraries/base/tests/perf/ElemNoFusion_O1.stderr
- + libraries/base/tests/perf/ElemNoFusion_O2.stderr
- โ libraries/base/tests/perf/Makefile
- libraries/base/tests/perf/T17752.hs
- โ libraries/base/tests/perf/T17752.stdout
- + libraries/base/tests/perf/T17752_O1.stderr
- + libraries/base/tests/perf/T17752_O2.stderr
- libraries/base/tests/perf/all.T
Changes:
| 1 | +-- We expect `elem` to fuse with good producers such as `map`, `concatMap`,
|
|
| 2 | +-- and `filter`.
|
|
| 3 | +module ElemFusionUnknownList where
|
|
| 4 | + |
|
| 5 | +fusionElemMap :: Int -> [Int] -> Bool
|
|
| 6 | +fusionElemMap x = elem x . map (+1)
|
|
| 7 | + |
|
| 8 | +fusionNotElemMap :: Int -> [Int] -> Bool
|
|
| 9 | +fusionNotElemMap x = notElem x . map (+1)
|
|
| 10 | + |
|
| 11 | +fusionElemConcatMap :: Int -> [Int] -> Bool
|
|
| 12 | +fusionElemConcatMap x = elem x . concatMap (\y -> [y + 1, y + 2])
|
|
| 13 | + |
|
| 14 | +fusionNotElemConcatMap :: Int -> [Int] -> Bool
|
|
| 15 | +fusionNotElemConcatMap x = notElem x . concatMap (\y -> [y + 1, y + 2])
|
|
| 16 | + |
|
| 17 | +fusionElemFilter :: Int -> [Int] -> Bool
|
|
| 18 | +fusionElemFilter x = elem x . filter odd
|
|
| 19 | + |
|
| 20 | +fusionNotElemFilter :: Int -> [Int] -> Bool
|
|
| 21 | +fusionNotElemFilter x = notElem x . filter odd |
| 1 | +fusionNotElemFilter
|
|
| 2 | + = \ x eta ->
|
|
| 3 | + joinrec {
|
|
| 4 | + go1 ds
|
|
| 5 | + = case ds of {
|
|
| 6 | + [] -> True;
|
|
| 7 | + : y ys ->
|
|
| 8 | + case y of { I# ipv ->
|
|
| 9 | + case remInt# ipv 2# of {
|
|
| 10 | + __DEFAULT ->
|
|
| 11 | + case x of { I# x1 ->
|
|
| 12 | + case ==# x1 ipv of {
|
|
| 13 | + __DEFAULT -> jump go1 ys;
|
|
| 14 | + 1# -> False
|
|
| 15 | + }
|
|
| 16 | + };
|
|
| 17 | + 0# -> jump go1 ys
|
|
| 18 | + }
|
|
| 19 | + }
|
|
| 20 | + }; } in
|
|
| 21 | + jump go1 eta
|
|
| 22 | + |
|
| 23 | +fusionElemFilter
|
|
| 24 | + = \ x eta ->
|
|
| 25 | + joinrec {
|
|
| 26 | + go1 ds
|
|
| 27 | + = case ds of {
|
|
| 28 | + [] -> False;
|
|
| 29 | + : y ys ->
|
|
| 30 | + case y of { I# ipv ->
|
|
| 31 | + case remInt# ipv 2# of {
|
|
| 32 | + __DEFAULT ->
|
|
| 33 | + case x of { I# x1 ->
|
|
| 34 | + case ==# x1 ipv of {
|
|
| 35 | + __DEFAULT -> jump go1 ys;
|
|
| 36 | + 1# -> True
|
|
| 37 | + }
|
|
| 38 | + };
|
|
| 39 | + 0# -> jump go1 ys
|
|
| 40 | + }
|
|
| 41 | + }
|
|
| 42 | + }; } in
|
|
| 43 | + jump go1 eta
|
|
| 44 | + |
|
| 45 | +fusionNotElemConcatMap
|
|
| 46 | + = \ x x1 ->
|
|
| 47 | + joinrec {
|
|
| 48 | + go1 ds
|
|
| 49 | + = case ds of {
|
|
| 50 | + [] -> True;
|
|
| 51 | + : y ys ->
|
|
| 52 | + case y of { I# x2 ->
|
|
| 53 | + case x of { I# x3 ->
|
|
| 54 | + case ==# x3 (+# x2 1#) of {
|
|
| 55 | + __DEFAULT ->
|
|
| 56 | + case ==# x3 (+# x2 2#) of {
|
|
| 57 | + __DEFAULT -> jump go1 ys;
|
|
| 58 | + 1# -> False
|
|
| 59 | + };
|
|
| 60 | + 1# -> False
|
|
| 61 | + }
|
|
| 62 | + }
|
|
| 63 | + }
|
|
| 64 | + }; } in
|
|
| 65 | + jump go1 x1
|
|
| 66 | + |
|
| 67 | +fusionElemConcatMap
|
|
| 68 | + = \ x x1 ->
|
|
| 69 | + joinrec {
|
|
| 70 | + go1 ds
|
|
| 71 | + = case ds of {
|
|
| 72 | + [] -> False;
|
|
| 73 | + : y ys ->
|
|
| 74 | + case y of { I# x2 ->
|
|
| 75 | + case x of { I# x3 ->
|
|
| 76 | + case ==# x3 (+# x2 1#) of {
|
|
| 77 | + __DEFAULT ->
|
|
| 78 | + case ==# x3 (+# x2 2#) of {
|
|
| 79 | + __DEFAULT -> jump go1 ys;
|
|
| 80 | + 1# -> True
|
|
| 81 | + };
|
|
| 82 | + 1# -> True
|
|
| 83 | + }
|
|
| 84 | + }
|
|
| 85 | + }
|
|
| 86 | + }; } in
|
|
| 87 | + jump go1 x1
|
|
| 88 | + |
|
| 89 | +fusionNotElemMap
|
|
| 90 | + = \ x eta ->
|
|
| 91 | + joinrec {
|
|
| 92 | + go1 ds
|
|
| 93 | + = case ds of {
|
|
| 94 | + [] -> True;
|
|
| 95 | + : y ys ->
|
|
| 96 | + case x of { I# x1 ->
|
|
| 97 | + case y of { I# x2 ->
|
|
| 98 | + case ==# x1 (+# x2 1#) of {
|
|
| 99 | + __DEFAULT -> jump go1 ys;
|
|
| 100 | + 1# -> False
|
|
| 101 | + }
|
|
| 102 | + }
|
|
| 103 | + }
|
|
| 104 | + }; } in
|
|
| 105 | + jump go1 eta
|
|
| 106 | + |
|
| 107 | +fusionElemMap
|
|
| 108 | + = \ x eta ->
|
|
| 109 | + joinrec {
|
|
| 110 | + go1 ds
|
|
| 111 | + = case ds of {
|
|
| 112 | + [] -> False;
|
|
| 113 | + : y ys ->
|
|
| 114 | + case x of { I# x1 ->
|
|
| 115 | + case y of { I# x2 ->
|
|
| 116 | + case ==# x1 (+# x2 1#) of {
|
|
| 117 | + __DEFAULT -> jump go1 ys;
|
|
| 118 | + 1# -> True
|
|
| 119 | + }
|
|
| 120 | + }
|
|
| 121 | + }
|
|
| 122 | + }; } in
|
|
| 123 | + jump go1 eta
|
|
| 124 | + |
| 1 | +fusionNotElemFilter
|
|
| 2 | + = \ x eta ->
|
|
| 3 | + joinrec {
|
|
| 4 | + go1 ds
|
|
| 5 | + = case ds of {
|
|
| 6 | + [] -> True;
|
|
| 7 | + : y ys ->
|
|
| 8 | + case y of { I# ipv ->
|
|
| 9 | + case remInt# ipv 2# of {
|
|
| 10 | + __DEFAULT ->
|
|
| 11 | + case x of { I# x1 ->
|
|
| 12 | + case ==# x1 ipv of {
|
|
| 13 | + __DEFAULT ->
|
|
| 14 | + joinrec {
|
|
| 15 | + go2 ds1
|
|
| 16 | + = case ds1 of {
|
|
| 17 | + [] -> True;
|
|
| 18 | + : y1 ys1 ->
|
|
| 19 | + case y1 of { I# ipv1 ->
|
|
| 20 | + case remInt# ipv1 2# of {
|
|
| 21 | + __DEFAULT ->
|
|
| 22 | + case ==# x1 ipv1 of {
|
|
| 23 | + __DEFAULT -> jump go2 ys1;
|
|
| 24 | + 1# -> False
|
|
| 25 | + };
|
|
| 26 | + 0# -> jump go2 ys1
|
|
| 27 | + }
|
|
| 28 | + }
|
|
| 29 | + }; } in
|
|
| 30 | + jump go2 ys;
|
|
| 31 | + 1# -> False
|
|
| 32 | + }
|
|
| 33 | + };
|
|
| 34 | + 0# -> jump go1 ys
|
|
| 35 | + }
|
|
| 36 | + }
|
|
| 37 | + }; } in
|
|
| 38 | + jump go1 eta
|
|
| 39 | + |
|
| 40 | +fusionElemFilter
|
|
| 41 | + = \ x eta ->
|
|
| 42 | + joinrec {
|
|
| 43 | + go1 ds
|
|
| 44 | + = case ds of {
|
|
| 45 | + [] -> False;
|
|
| 46 | + : y ys ->
|
|
| 47 | + case y of { I# ipv ->
|
|
| 48 | + case remInt# ipv 2# of {
|
|
| 49 | + __DEFAULT ->
|
|
| 50 | + case x of { I# x1 ->
|
|
| 51 | + case ==# x1 ipv of {
|
|
| 52 | + __DEFAULT ->
|
|
| 53 | + joinrec {
|
|
| 54 | + go2 ds1
|
|
| 55 | + = case ds1 of {
|
|
| 56 | + [] -> False;
|
|
| 57 | + : y1 ys1 ->
|
|
| 58 | + case y1 of { I# ipv1 ->
|
|
| 59 | + case remInt# ipv1 2# of {
|
|
| 60 | + __DEFAULT ->
|
|
| 61 | + case ==# x1 ipv1 of {
|
|
| 62 | + __DEFAULT -> jump go2 ys1;
|
|
| 63 | + 1# -> True
|
|
| 64 | + };
|
|
| 65 | + 0# -> jump go2 ys1
|
|
| 66 | + }
|
|
| 67 | + }
|
|
| 68 | + }; } in
|
|
| 69 | + jump go2 ys;
|
|
| 70 | + 1# -> True
|
|
| 71 | + }
|
|
| 72 | + };
|
|
| 73 | + 0# -> jump go1 ys
|
|
| 74 | + }
|
|
| 75 | + }
|
|
| 76 | + }; } in
|
|
| 77 | + jump go1 eta
|
|
| 78 | + |
|
| 79 | +fusionNotElemConcatMap
|
|
| 80 | + = \ x x1 ->
|
|
| 81 | + case x1 of {
|
|
| 82 | + [] -> True;
|
|
| 83 | + : y ys ->
|
|
| 84 | + case y of { I# x2 ->
|
|
| 85 | + case x of { I# x3 ->
|
|
| 86 | + case ==# x3 (+# x2 1#) of {
|
|
| 87 | + __DEFAULT ->
|
|
| 88 | + case ==# x3 (+# x2 2#) of {
|
|
| 89 | + __DEFAULT ->
|
|
| 90 | + joinrec {
|
|
| 91 | + go1 ds
|
|
| 92 | + = case ds of {
|
|
| 93 | + [] -> True;
|
|
| 94 | + : y1 ys1 ->
|
|
| 95 | + case y1 of { I# x4 ->
|
|
| 96 | + case ==# x3 (+# x4 1#) of {
|
|
| 97 | + __DEFAULT ->
|
|
| 98 | + case ==# x3 (+# x4 2#) of {
|
|
| 99 | + __DEFAULT -> jump go1 ys1;
|
|
| 100 | + 1# -> False
|
|
| 101 | + };
|
|
| 102 | + 1# -> False
|
|
| 103 | + }
|
|
| 104 | + }
|
|
| 105 | + }; } in
|
|
| 106 | + jump go1 ys;
|
|
| 107 | + 1# -> False
|
|
| 108 | + };
|
|
| 109 | + 1# -> False
|
|
| 110 | + }
|
|
| 111 | + }
|
|
| 112 | + }
|
|
| 113 | + }
|
|
| 114 | + |
|
| 115 | +fusionElemConcatMap
|
|
| 116 | + = \ x x1 ->
|
|
| 117 | + case x1 of {
|
|
| 118 | + [] -> False;
|
|
| 119 | + : y ys ->
|
|
| 120 | + case y of { I# x2 ->
|
|
| 121 | + case x of { I# x3 ->
|
|
| 122 | + case ==# x3 (+# x2 1#) of {
|
|
| 123 | + __DEFAULT ->
|
|
| 124 | + case ==# x3 (+# x2 2#) of {
|
|
| 125 | + __DEFAULT ->
|
|
| 126 | + joinrec {
|
|
| 127 | + go1 ds
|
|
| 128 | + = case ds of {
|
|
| 129 | + [] -> False;
|
|
| 130 | + : y1 ys1 ->
|
|
| 131 | + case y1 of { I# x4 ->
|
|
| 132 | + case ==# x3 (+# x4 1#) of {
|
|
| 133 | + __DEFAULT ->
|
|
| 134 | + case ==# x3 (+# x4 2#) of {
|
|
| 135 | + __DEFAULT -> jump go1 ys1;
|
|
| 136 | + 1# -> True
|
|
| 137 | + };
|
|
| 138 | + 1# -> True
|
|
| 139 | + }
|
|
| 140 | + }
|
|
| 141 | + }; } in
|
|
| 142 | + jump go1 ys;
|
|
| 143 | + 1# -> True
|
|
| 144 | + };
|
|
| 145 | + 1# -> True
|
|
| 146 | + }
|
|
| 147 | + }
|
|
| 148 | + }
|
|
| 149 | + }
|
|
| 150 | + |
|
| 151 | +fusionNotElemMap
|
|
| 152 | + = \ x eta ->
|
|
| 153 | + case eta of {
|
|
| 154 | + [] -> True;
|
|
| 155 | + : y ys ->
|
|
| 156 | + case x of { I# x1 ->
|
|
| 157 | + case y of { I# x2 ->
|
|
| 158 | + case ==# x1 (+# x2 1#) of {
|
|
| 159 | + __DEFAULT ->
|
|
| 160 | + joinrec {
|
|
| 161 | + go1 ds
|
|
| 162 | + = case ds of {
|
|
| 163 | + [] -> True;
|
|
| 164 | + : y1 ys1 ->
|
|
| 165 | + case y1 of { I# x3 ->
|
|
| 166 | + case ==# x1 (+# x3 1#) of {
|
|
| 167 | + __DEFAULT -> jump go1 ys1;
|
|
| 168 | + 1# -> False
|
|
| 169 | + }
|
|
| 170 | + }
|
|
| 171 | + }; } in
|
|
| 172 | + jump go1 ys;
|
|
| 173 | + 1# -> False
|
|
| 174 | + }
|
|
| 175 | + }
|
|
| 176 | + }
|
|
| 177 | + }
|
|
| 178 | + |
|
| 179 | +fusionElemMap
|
|
| 180 | + = \ x eta ->
|
|
| 181 | + case eta of {
|
|
| 182 | + [] -> False;
|
|
| 183 | + : y ys ->
|
|
| 184 | + case x of { I# x1 ->
|
|
| 185 | + case y of { I# x2 ->
|
|
| 186 | + case ==# x1 (+# x2 1#) of {
|
|
| 187 | + __DEFAULT ->
|
|
| 188 | + joinrec {
|
|
| 189 | + go1 ds
|
|
| 190 | + = case ds of {
|
|
| 191 | + [] -> False;
|
|
| 192 | + : y1 ys1 ->
|
|
| 193 | + case y1 of { I# x3 ->
|
|
| 194 | + case ==# x1 (+# x3 1#) of {
|
|
| 195 | + __DEFAULT -> jump go1 ys1;
|
|
| 196 | + 1# -> True
|
|
| 197 | + }
|
|
| 198 | + }
|
|
| 199 | + }; } in
|
|
| 200 | + jump go1 ys;
|
|
| 201 | + 1# -> True
|
|
| 202 | + }
|
|
| 203 | + }
|
|
| 204 | + }
|
|
| 205 | + }
|
|
| 206 | + |
| 1 | +-- As of March 2026, we don't expect `elem` to fuse with `sort` or `NonEmpty.toList`.
|
|
| 2 | +-- `elem` isn't even specialized, and performs dictionary-passing, but that may
|
|
| 3 | +-- change: #27096
|
|
| 4 | +module ElemNoFusion where
|
|
| 5 | + |
|
| 6 | +import Data.List (sort)
|
|
| 7 | +import Data.List.NonEmpty (NonEmpty)
|
|
| 8 | +import qualified Data.List.NonEmpty as NonEmpty
|
|
| 9 | + |
|
| 10 | +noFusionElemNonEmptyToList :: Int -> NonEmpty Int -> Bool
|
|
| 11 | +noFusionElemNonEmptyToList x = elem x . NonEmpty.toList
|
|
| 12 | + |
|
| 13 | +noFusionElemSort :: Int -> [Int] -> Bool
|
|
| 14 | +noFusionElemSort x = elem x . sort |
| 1 | +noFusionElemSort = \ x x1 -> elem $fEqInt x (actualSort gtInt x1)
|
|
| 2 | + |
|
| 3 | +noFusionElemNonEmptyToList
|
|
| 4 | + = \ x x1 -> case x1 of { :| a1 as -> elem $fEqInt x (: a1 as) }
|
|
| 5 | + |
| 1 | +noFusionElemSort = \ x x1 -> elem $fEqInt x (actualSort gtInt x1)
|
|
| 2 | + |
|
| 3 | +noFusionElemNonEmptyToList
|
|
| 4 | + = \ x x1 -> case x1 of { :| a1 as -> elem $fEqInt x (: a1 as) }
|
|
| 5 | + |
| 1 | -# This Makefile runs the tests using GHC's testsuite framework. It
|
|
| 2 | -# assumes the package is part of a GHC build tree with the testsuite
|
|
| 3 | -# installed in ../../../testsuite.
|
|
| 4 | - |
|
| 5 | -TOP=../../../../testsuite
|
|
| 6 | -include $(TOP)/mk/boilerplate.mk
|
|
| 7 | -include $(TOP)/mk/test.mk
|
|
| 8 | - |
|
| 9 | - |
|
| 10 | -T17752:
|
|
| 11 | - '$(TEST_HC)' $(TEST_HC_OPTS) -O --make T17752 -rtsopts -ddump-simpl -ddump-to-file -dsuppress-uniques -dsuppress-all
|
|
| 12 | - # All occurrences of elem should be optimized away.
|
|
| 13 | - # For strings these should result in loops after inlining foldCString.
|
|
| 14 | - # For lists it should result in a case expression.
|
|
| 15 | - echo $$(grep -A4 "elem" T17752.dump-simpl) |
| ... | ... | @@ -6,7 +6,7 @@ module T17752 where |
| 6 | 6 | |
| 7 | 7 | -- Should compile to a pattern match if the rules fire
|
| 8 | 8 | isElemList x = x `elem` ['a','b','c']
|
| 9 | -isNotElemList x = x `elem` ['x','y','z']
|
|
| 9 | +isNotElemList x = x `notElem` ['x','y','z']
|
|
| 10 | 10 | |
| 11 | 11 | isOneOfThese x = x `elem` [1,2,3,4,5::Int]
|
| 12 | 12 | isNotOneOfThese x = x `notElem` [1,2,3,4,5::Int]
|
| 1 | -[1 of 1] Compiling T17752 ( T17752.hs, T17752.o )
|
|
| 2 | - |
| 1 | +isElemList
|
|
| 2 | + = \ x ->
|
|
| 3 | + case x of { C# x1 ->
|
|
| 4 | + case x1 of {
|
|
| 5 | + __DEFAULT -> False;
|
|
| 6 | + 'a'# -> True;
|
|
| 7 | + 'b'# -> True;
|
|
| 8 | + 'c'# -> True
|
|
| 9 | + }
|
|
| 10 | + }
|
|
| 11 | + |
|
| 12 | +isNotElemList
|
|
| 13 | + = \ x ->
|
|
| 14 | + case x of { C# x1 ->
|
|
| 15 | + case x1 of {
|
|
| 16 | + __DEFAULT -> True;
|
|
| 17 | + 'x'# -> False;
|
|
| 18 | + 'y'# -> False;
|
|
| 19 | + 'z'# -> False
|
|
| 20 | + }
|
|
| 21 | + }
|
|
| 22 | + |
|
| 23 | +isOneOfThese
|
|
| 24 | + = \ x ->
|
|
| 25 | + case x of { I# x1 ->
|
|
| 26 | + case x1 of {
|
|
| 27 | + __DEFAULT -> False;
|
|
| 28 | + 1# -> True;
|
|
| 29 | + 2# -> True;
|
|
| 30 | + 3# -> True;
|
|
| 31 | + 4# -> True;
|
|
| 32 | + 5# -> True
|
|
| 33 | + }
|
|
| 34 | + }
|
|
| 35 | + |
|
| 36 | +isNotOneOfThese
|
|
| 37 | + = \ x ->
|
|
| 38 | + case x of { I# x1 ->
|
|
| 39 | + case x1 of {
|
|
| 40 | + __DEFAULT -> True;
|
|
| 41 | + 1# -> False;
|
|
| 42 | + 2# -> False;
|
|
| 43 | + 3# -> False;
|
|
| 44 | + 4# -> False;
|
|
| 45 | + 5# -> False
|
|
| 46 | + }
|
|
| 47 | + }
|
|
| 48 | + |
|
| 49 | +isElemString
|
|
| 50 | + = \ x ->
|
|
| 51 | + joinrec {
|
|
| 52 | + go addr z
|
|
| 53 | + = case indexCharOffAddr# addr 0# of ch {
|
|
| 54 | + __DEFAULT ->
|
|
| 55 | + case x of { C# x1 ->
|
|
| 56 | + case eqChar# x1 ch of {
|
|
| 57 | + __DEFAULT -> jump go (plusAddr# addr 1#) z;
|
|
| 58 | + 1# -> True
|
|
| 59 | + }
|
|
| 60 | + };
|
|
| 61 | + '\NUL'# -> z
|
|
| 62 | + }; } in
|
|
| 63 | + jump go isElemString1 False
|
|
| 64 | + |
|
| 65 | +isNotElemString
|
|
| 66 | + = \ x ->
|
|
| 67 | + joinrec {
|
|
| 68 | + go addr z
|
|
| 69 | + = case indexCharOffAddr# addr 0# of ch {
|
|
| 70 | + __DEFAULT ->
|
|
| 71 | + case x of { C# x1 ->
|
|
| 72 | + case eqChar# x1 ch of {
|
|
| 73 | + __DEFAULT -> jump go (plusAddr# addr 1#) z;
|
|
| 74 | + 1# -> False
|
|
| 75 | + }
|
|
| 76 | + };
|
|
| 77 | + '\NUL'# ->
|
|
| 78 | + case z of {
|
|
| 79 | + False -> True;
|
|
| 80 | + True -> False
|
|
| 81 | + }
|
|
| 82 | + }; } in
|
|
| 83 | + jump go isNotElemString1 False
|
|
| 84 | + |
|
| 85 | +isElemStringUtf
|
|
| 86 | + = \ x ->
|
|
| 87 | + unpackFoldrCStringUtf8#
|
|
| 88 | + isElemStringUtf1
|
|
| 89 | + (\ y r ->
|
|
| 90 | + case x of { C# x1 ->
|
|
| 91 | + case y of { C# y1 ->
|
|
| 92 | + case eqChar# x1 y1 of {
|
|
| 93 | + __DEFAULT -> r;
|
|
| 94 | + 1# -> True
|
|
| 95 | + }
|
|
| 96 | + }
|
|
| 97 | + })
|
|
| 98 | + False
|
|
| 99 | + |
|
| 100 | +isNotElemStringUtf
|
|
| 101 | + = \ x ->
|
|
| 102 | + case unpackFoldrCStringUtf8#
|
|
| 103 | + isNotElemStringUtf1
|
|
| 104 | + (\ y r ->
|
|
| 105 | + case x of { C# x1 ->
|
|
| 106 | + case y of { C# y1 ->
|
|
| 107 | + case eqChar# x1 y1 of {
|
|
| 108 | + __DEFAULT -> r;
|
|
| 109 | + 1# -> True
|
|
| 110 | + }
|
|
| 111 | + }
|
|
| 112 | + })
|
|
| 113 | + False
|
|
| 114 | + of {
|
|
| 115 | + False -> True;
|
|
| 116 | + True -> False
|
|
| 117 | + }
|
|
| 118 | + |
| 1 | +isElemList
|
|
| 2 | + = \ x ->
|
|
| 3 | + case x of { C# x1 ->
|
|
| 4 | + case x1 of {
|
|
| 5 | + __DEFAULT -> False;
|
|
| 6 | + 'a'# -> True;
|
|
| 7 | + 'b'# -> True;
|
|
| 8 | + 'c'# -> True
|
|
| 9 | + }
|
|
| 10 | + }
|
|
| 11 | + |
|
| 12 | +isNotElemList
|
|
| 13 | + = \ x ->
|
|
| 14 | + case x of { C# x1 ->
|
|
| 15 | + case x1 of {
|
|
| 16 | + __DEFAULT -> True;
|
|
| 17 | + 'x'# -> False;
|
|
| 18 | + 'y'# -> False;
|
|
| 19 | + 'z'# -> False
|
|
| 20 | + }
|
|
| 21 | + }
|
|
| 22 | + |
|
| 23 | +isOneOfThese
|
|
| 24 | + = \ x ->
|
|
| 25 | + case x of { I# x1 ->
|
|
| 26 | + case x1 of {
|
|
| 27 | + __DEFAULT -> False;
|
|
| 28 | + 1# -> True;
|
|
| 29 | + 2# -> True;
|
|
| 30 | + 3# -> True;
|
|
| 31 | + 4# -> True;
|
|
| 32 | + 5# -> True
|
|
| 33 | + }
|
|
| 34 | + }
|
|
| 35 | + |
|
| 36 | +isNotOneOfThese
|
|
| 37 | + = \ x ->
|
|
| 38 | + case x of { I# x1 ->
|
|
| 39 | + case x1 of {
|
|
| 40 | + __DEFAULT -> True;
|
|
| 41 | + 1# -> False;
|
|
| 42 | + 2# -> False;
|
|
| 43 | + 3# -> False;
|
|
| 44 | + 4# -> False;
|
|
| 45 | + 5# -> False
|
|
| 46 | + }
|
|
| 47 | + }
|
|
| 48 | + |
|
| 49 | +isElemString
|
|
| 50 | + = \ x ->
|
|
| 51 | + case indexCharOffAddr# isElemString1 0# of ch {
|
|
| 52 | + __DEFAULT ->
|
|
| 53 | + case x of { C# x1 ->
|
|
| 54 | + case eqChar# x1 ch of {
|
|
| 55 | + __DEFAULT ->
|
|
| 56 | + joinrec {
|
|
| 57 | + go addr z
|
|
| 58 | + = case indexCharOffAddr# addr 0# of ch1 {
|
|
| 59 | + __DEFAULT ->
|
|
| 60 | + case eqChar# x1 ch1 of {
|
|
| 61 | + __DEFAULT -> jump go (plusAddr# addr 1#) z;
|
|
| 62 | + 1# -> True
|
|
| 63 | + };
|
|
| 64 | + '\NUL'# -> z
|
|
| 65 | + }; } in
|
|
| 66 | + jump go (plusAddr# isElemString1 1#) False;
|
|
| 67 | + 1# -> True
|
|
| 68 | + }
|
|
| 69 | + };
|
|
| 70 | + '\NUL'# -> False
|
|
| 71 | + }
|
|
| 72 | + |
|
| 73 | +isNotElemString
|
|
| 74 | + = \ x ->
|
|
| 75 | + case indexCharOffAddr# isNotElemString1 0# of ch {
|
|
| 76 | + __DEFAULT ->
|
|
| 77 | + case x of { C# x1 ->
|
|
| 78 | + case eqChar# x1 ch of {
|
|
| 79 | + __DEFAULT ->
|
|
| 80 | + joinrec {
|
|
| 81 | + $sgo sc
|
|
| 82 | + = case indexCharOffAddr# sc 0# of ch1 {
|
|
| 83 | + __DEFAULT ->
|
|
| 84 | + case eqChar# x1 ch1 of {
|
|
| 85 | + __DEFAULT -> jump $sgo (plusAddr# sc 1#);
|
|
| 86 | + 1# -> False
|
|
| 87 | + };
|
|
| 88 | + '\NUL'# -> True
|
|
| 89 | + }; } in
|
|
| 90 | + jump $sgo (plusAddr# isNotElemString1 1#);
|
|
| 91 | + 1# -> False
|
|
| 92 | + }
|
|
| 93 | + };
|
|
| 94 | + '\NUL'# -> True
|
|
| 95 | + }
|
|
| 96 | + |
|
| 97 | +isElemStringUtf
|
|
| 98 | + = \ x ->
|
|
| 99 | + unpackFoldrCStringUtf8#
|
|
| 100 | + isElemStringUtf1
|
|
| 101 | + (\ y r ->
|
|
| 102 | + case x of { C# x1 ->
|
|
| 103 | + case y of { C# y1 ->
|
|
| 104 | + case eqChar# x1 y1 of {
|
|
| 105 | + __DEFAULT -> r;
|
|
| 106 | + 1# -> True
|
|
| 107 | + }
|
|
| 108 | + }
|
|
| 109 | + })
|
|
| 110 | + False
|
|
| 111 | + |
|
| 112 | +isNotElemStringUtf
|
|
| 113 | + = \ x ->
|
|
| 114 | + case unpackFoldrCStringUtf8#
|
|
| 115 | + isNotElemStringUtf1
|
|
| 116 | + (\ y r ->
|
|
| 117 | + case x of { C# x1 ->
|
|
| 118 | + case y of { C# y1 ->
|
|
| 119 | + case eqChar# x1 y1 of {
|
|
| 120 | + __DEFAULT -> r;
|
|
| 121 | + 1# -> True
|
|
| 122 | + }
|
|
| 123 | + }
|
|
| 124 | + })
|
|
| 125 | + False
|
|
| 126 | + of {
|
|
| 127 | + False -> True;
|
|
| 128 | + True -> False
|
|
| 129 | + }
|
|
| 130 | + |
| ... | ... | @@ -2,10 +2,25 @@ |
| 2 | 2 | setTestOpts(js_skip)
|
| 3 | 3 | |
| 4 | 4 | #--------------------------------------
|
| 5 | -# Check specialization of elem via rules
|
|
| 5 | +# Check optimization of `elem`
|
|
| 6 | 6 | #--------------------------------------
|
| 7 | 7 | |
| 8 | -test('T17752', [only_ways(['normal'])] , makefile_test, ['T17752'])
|
|
| 8 | +elemCoreFilter = "sed -En '/^(is|fusion|noFusion)[A-Za-z]*($| )/,/^$/p'"
|
|
| 9 | + |
|
| 10 | +def elemCoreTest(test_name, module_name, opt):
|
|
| 11 | + test(test_name,
|
|
| 12 | + [only_ways(['normal']), extra_files([module_name + '.hs'])],
|
|
| 13 | + multimod_compile_filter,
|
|
| 14 | + [module_name,
|
|
| 15 | + f'{opt} -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 16 | + elemCoreFilter])
|
|
| 17 | + |
|
| 18 | +elemCoreTest('T17752_O1', 'T17752', '-O1')
|
|
| 19 | +elemCoreTest('T17752_O2', 'T17752', '-O2')
|
|
| 20 | +elemCoreTest('ElemFusionUnknownList_O1', 'ElemFusionUnknownList', '-O1')
|
|
| 21 | +elemCoreTest('ElemFusionUnknownList_O2', 'ElemFusionUnknownList', '-O2')
|
|
| 22 | +elemCoreTest('ElemNoFusion_O1', 'ElemNoFusion', '-O1')
|
|
| 23 | +elemCoreTest('ElemNoFusion_O2', 'ElemNoFusion', '-O2')
|
|
| 9 | 24 | |
| 10 | 25 | #--------------------------------------
|
| 11 | 26 |