Simon Jakobi pushed to branch wip/sjakobi/elem-tests at Glasgow Haskell Compiler / GHC
Commits:
-
8789f4a7
by Simon Jakobi at 2026-03-27T20:55:11+01:00
7 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/all.T
Changes:
| 1 | +module ElemFusionUnknownList where
|
|
| 2 | + |
|
| 3 | +-- These should fuse with producers over unknown list inputs at -O1 and -O2.
|
|
| 4 | +fusionElemMap :: Int -> [Int] -> Bool
|
|
| 5 | +fusionElemMap x = elem x . map (+1)
|
|
| 6 | + |
|
| 7 | +fusionNotElemMap :: Int -> [Int] -> Bool
|
|
| 8 | +fusionNotElemMap x = notElem x . map (+1)
|
|
| 9 | + |
|
| 10 | +fusionElemConcatMap :: Int -> [Int] -> Bool
|
|
| 11 | +fusionElemConcatMap x = elem x . concatMap (\y -> [y + 1, y + 2])
|
|
| 12 | + |
|
| 13 | +fusionNotElemConcatMap :: Int -> [Int] -> Bool
|
|
| 14 | +fusionNotElemConcatMap x = notElem x . concatMap (\y -> [y + 1, y + 2]) |
| 1 | +fusionNotElemConcatMap
|
|
| 2 | + = \ x x1 ->
|
|
| 3 | + joinrec {
|
|
| 4 | + go1 ds
|
|
| 5 | + = case ds of {
|
|
| 6 | + [] -> True;
|
|
| 7 | + : y ys ->
|
|
| 8 | + case y of { I# x2 ->
|
|
| 9 | + case x of { I# x3 ->
|
|
| 10 | + case ==# x3 (+# x2 1#) of {
|
|
| 11 | + __DEFAULT ->
|
|
| 12 | + case ==# x3 (+# x2 2#) of {
|
|
| 13 | + __DEFAULT -> jump go1 ys;
|
|
| 14 | + 1# -> False
|
|
| 15 | + };
|
|
| 16 | + 1# -> False
|
|
| 17 | + }
|
|
| 18 | + }
|
|
| 19 | + }
|
|
| 20 | + }; } in
|
|
| 21 | + jump go1 x1
|
|
| 22 | + |
|
| 23 | +fusionElemConcatMap
|
|
| 24 | + = \ x x1 ->
|
|
| 25 | + joinrec {
|
|
| 26 | + go1 ds
|
|
| 27 | + = case ds of {
|
|
| 28 | + [] -> False;
|
|
| 29 | + : y ys ->
|
|
| 30 | + case y of { I# x2 ->
|
|
| 31 | + case x of { I# x3 ->
|
|
| 32 | + case ==# x3 (+# x2 1#) of {
|
|
| 33 | + __DEFAULT ->
|
|
| 34 | + case ==# x3 (+# x2 2#) of {
|
|
| 35 | + __DEFAULT -> jump go1 ys;
|
|
| 36 | + 1# -> True
|
|
| 37 | + };
|
|
| 38 | + 1# -> True
|
|
| 39 | + }
|
|
| 40 | + }
|
|
| 41 | + }
|
|
| 42 | + }; } in
|
|
| 43 | + jump go1 x1
|
|
| 44 | + |
|
| 45 | +fusionNotElemMap
|
|
| 46 | + = \ x eta ->
|
|
| 47 | + joinrec {
|
|
| 48 | + go1 ds
|
|
| 49 | + = case ds of {
|
|
| 50 | + [] -> True;
|
|
| 51 | + : y ys ->
|
|
| 52 | + case x of { I# x1 ->
|
|
| 53 | + case y of { I# x2 ->
|
|
| 54 | + case ==# x1 (+# x2 1#) of {
|
|
| 55 | + __DEFAULT -> jump go1 ys;
|
|
| 56 | + 1# -> False
|
|
| 57 | + }
|
|
| 58 | + }
|
|
| 59 | + }
|
|
| 60 | + }; } in
|
|
| 61 | + jump go1 eta
|
|
| 62 | + |
|
| 63 | +fusionElemMap
|
|
| 64 | + = \ x eta ->
|
|
| 65 | + joinrec {
|
|
| 66 | + go1 ds
|
|
| 67 | + = case ds of {
|
|
| 68 | + [] -> False;
|
|
| 69 | + : y ys ->
|
|
| 70 | + case x of { I# x1 ->
|
|
| 71 | + case y of { I# x2 ->
|
|
| 72 | + case ==# x1 (+# x2 1#) of {
|
|
| 73 | + __DEFAULT -> jump go1 ys;
|
|
| 74 | + 1# -> True
|
|
| 75 | + }
|
|
| 76 | + }
|
|
| 77 | + }
|
|
| 78 | + }; } in
|
|
| 79 | + jump go1 eta
|
|
| 80 | + |
| 1 | +fusionNotElemConcatMap
|
|
| 2 | + = \ x x1 ->
|
|
| 3 | + case x1 of {
|
|
| 4 | + [] -> True;
|
|
| 5 | + : y ys ->
|
|
| 6 | + case y of { I# x2 ->
|
|
| 7 | + case x of { I# x3 ->
|
|
| 8 | + case ==# x3 (+# x2 1#) of {
|
|
| 9 | + __DEFAULT ->
|
|
| 10 | + case ==# x3 (+# x2 2#) of {
|
|
| 11 | + __DEFAULT ->
|
|
| 12 | + joinrec {
|
|
| 13 | + go1 ds
|
|
| 14 | + = case ds of {
|
|
| 15 | + [] -> True;
|
|
| 16 | + : y1 ys1 ->
|
|
| 17 | + case y1 of { I# x4 ->
|
|
| 18 | + case ==# x3 (+# x4 1#) of {
|
|
| 19 | + __DEFAULT ->
|
|
| 20 | + case ==# x3 (+# x4 2#) of {
|
|
| 21 | + __DEFAULT -> jump go1 ys1;
|
|
| 22 | + 1# -> False
|
|
| 23 | + };
|
|
| 24 | + 1# -> False
|
|
| 25 | + }
|
|
| 26 | + }
|
|
| 27 | + }; } in
|
|
| 28 | + jump go1 ys;
|
|
| 29 | + 1# -> False
|
|
| 30 | + };
|
|
| 31 | + 1# -> False
|
|
| 32 | + }
|
|
| 33 | + }
|
|
| 34 | + }
|
|
| 35 | + }
|
|
| 36 | + |
|
| 37 | +fusionElemConcatMap
|
|
| 38 | + = \ x x1 ->
|
|
| 39 | + case x1 of {
|
|
| 40 | + [] -> False;
|
|
| 41 | + : y ys ->
|
|
| 42 | + case y of { I# x2 ->
|
|
| 43 | + case x of { I# x3 ->
|
|
| 44 | + case ==# x3 (+# x2 1#) of {
|
|
| 45 | + __DEFAULT ->
|
|
| 46 | + case ==# x3 (+# x2 2#) of {
|
|
| 47 | + __DEFAULT ->
|
|
| 48 | + joinrec {
|
|
| 49 | + go1 ds
|
|
| 50 | + = case ds of {
|
|
| 51 | + [] -> False;
|
|
| 52 | + : y1 ys1 ->
|
|
| 53 | + case y1 of { I# x4 ->
|
|
| 54 | + case ==# x3 (+# x4 1#) of {
|
|
| 55 | + __DEFAULT ->
|
|
| 56 | + case ==# x3 (+# x4 2#) of {
|
|
| 57 | + __DEFAULT -> jump go1 ys1;
|
|
| 58 | + 1# -> True
|
|
| 59 | + };
|
|
| 60 | + 1# -> True
|
|
| 61 | + }
|
|
| 62 | + }
|
|
| 63 | + }; } in
|
|
| 64 | + jump go1 ys;
|
|
| 65 | + 1# -> True
|
|
| 66 | + };
|
|
| 67 | + 1# -> True
|
|
| 68 | + }
|
|
| 69 | + }
|
|
| 70 | + }
|
|
| 71 | + }
|
|
| 72 | + |
|
| 73 | +fusionNotElemMap
|
|
| 74 | + = \ x eta ->
|
|
| 75 | + case eta of {
|
|
| 76 | + [] -> True;
|
|
| 77 | + : y ys ->
|
|
| 78 | + case x of { I# x1 ->
|
|
| 79 | + case y of { I# x2 ->
|
|
| 80 | + case ==# x1 (+# x2 1#) of {
|
|
| 81 | + __DEFAULT ->
|
|
| 82 | + joinrec {
|
|
| 83 | + go1 ds
|
|
| 84 | + = case ds of {
|
|
| 85 | + [] -> True;
|
|
| 86 | + : y1 ys1 ->
|
|
| 87 | + case y1 of { I# x3 ->
|
|
| 88 | + case ==# x1 (+# x3 1#) of {
|
|
| 89 | + __DEFAULT -> jump go1 ys1;
|
|
| 90 | + 1# -> False
|
|
| 91 | + }
|
|
| 92 | + }
|
|
| 93 | + }; } in
|
|
| 94 | + jump go1 ys;
|
|
| 95 | + 1# -> False
|
|
| 96 | + }
|
|
| 97 | + }
|
|
| 98 | + }
|
|
| 99 | + }
|
|
| 100 | + |
|
| 101 | +fusionElemMap
|
|
| 102 | + = \ x eta ->
|
|
| 103 | + case eta of {
|
|
| 104 | + [] -> False;
|
|
| 105 | + : y ys ->
|
|
| 106 | + case x of { I# x1 ->
|
|
| 107 | + case y of { I# x2 ->
|
|
| 108 | + case ==# x1 (+# x2 1#) of {
|
|
| 109 | + __DEFAULT ->
|
|
| 110 | + joinrec {
|
|
| 111 | + go1 ds
|
|
| 112 | + = case ds of {
|
|
| 113 | + [] -> False;
|
|
| 114 | + : y1 ys1 ->
|
|
| 115 | + case y1 of { I# x3 ->
|
|
| 116 | + case ==# x1 (+# x3 1#) of {
|
|
| 117 | + __DEFAULT -> jump go1 ys1;
|
|
| 118 | + 1# -> True
|
|
| 119 | + }
|
|
| 120 | + }
|
|
| 121 | + }; } in
|
|
| 122 | + jump go1 ys;
|
|
| 123 | + 1# -> True
|
|
| 124 | + }
|
|
| 125 | + }
|
|
| 126 | + }
|
|
| 127 | + }
|
|
| 128 | + |
| 1 | +module ElemNoFusion where
|
|
| 2 | + |
|
| 3 | +import Data.List (sort)
|
|
| 4 | +import Data.List.NonEmpty (NonEmpty)
|
|
| 5 | +import qualified Data.List.NonEmpty as NonEmpty
|
|
| 6 | + |
|
| 7 | +-- These should not fuse with elem, even at -O1 and -O2.
|
|
| 8 | +noFusionElemNonEmptyToList :: Int -> NonEmpty Int -> Bool
|
|
| 9 | +noFusionElemNonEmptyToList x = elem x . NonEmpty.toList
|
|
| 10 | + |
|
| 11 | +noFusionElemSort :: Int -> [Int] -> Bool
|
|
| 12 | +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 | + |
| ... | ... | @@ -26,6 +26,34 @@ test('T17752_O2', |
| 26 | 26 | '-O2 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
| 27 | 27 | "sed -n '/^is[A-Za-z]*$/,/^$/p'"])
|
| 28 | 28 | |
| 29 | +test('ElemFusionUnknownList_O1',
|
|
| 30 | + [only_ways(['normal']), extra_files(['ElemFusionUnknownList.hs'])],
|
|
| 31 | + multimod_compile_filter,
|
|
| 32 | + ['ElemFusionUnknownList',
|
|
| 33 | + '-O1 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 34 | + "sed -n '/^fusion[A-Za-z]*$/,/^$/p'"])
|
|
| 35 | + |
|
| 36 | +test('ElemFusionUnknownList_O2',
|
|
| 37 | + [only_ways(['normal']), extra_files(['ElemFusionUnknownList.hs'])],
|
|
| 38 | + multimod_compile_filter,
|
|
| 39 | + ['ElemFusionUnknownList',
|
|
| 40 | + '-O2 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 41 | + "sed -n '/^fusion[A-Za-z]*$/,/^$/p'"])
|
|
| 42 | + |
|
| 43 | +test('ElemNoFusion_O1',
|
|
| 44 | + [only_ways(['normal']), extra_files(['ElemNoFusion.hs'])],
|
|
| 45 | + multimod_compile_filter,
|
|
| 46 | + ['ElemNoFusion',
|
|
| 47 | + '-O1 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 48 | + "sed -n '/^noFusion[A-Za-z]*/,/^$/p'"])
|
|
| 49 | + |
|
| 50 | +test('ElemNoFusion_O2',
|
|
| 51 | + [only_ways(['normal']), extra_files(['ElemNoFusion.hs'])],
|
|
| 52 | + multimod_compile_filter,
|
|
| 53 | + ['ElemNoFusion',
|
|
| 54 | + '-O2 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 55 | + "sed -n '/^noFusion[A-Za-z]*/,/^$/p'"])
|
|
| 56 | + |
|
| 29 | 57 | #--------------------------------------
|
| 30 | 58 | |
| 31 | 59 | # We don't expect the code in test to vary at all, but the variance is set to
|