Simon Jakobi pushed to branch wip/sjakobi/elem-tests at Glasgow Haskell Compiler / GHC
Commits:
-
75f2bdd4
by Simon Jakobi at 2026-03-27T16:18:24+01:00
7 changed files:
- โ libraries/base/tests/perf/Makefile
- libraries/base/tests/perf/T17752.hs
- โ libraries/base/tests/perf/T17752.stdout
- + libraries/base/tests/perf/T17752_O0.stderr
- + libraries/base/tests/perf/T17752_O1.stderr
- + libraries/base/tests/perf/T17752_O2.stderr
- libraries/base/tests/perf/all.T
Changes:
| 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 | + elem
|
|
| 4 | + $fFoldableList
|
|
| 5 | + $fEqChar
|
|
| 6 | + x
|
|
| 7 | + (: (C# 'a'#) (: (C# 'b'#) (: (C# 'c'#) [])))
|
|
| 8 | + |
|
| 9 | +isNotElemList
|
|
| 10 | + = \ x ->
|
|
| 11 | + notElem
|
|
| 12 | + $fFoldableList
|
|
| 13 | + $fEqChar
|
|
| 14 | + x
|
|
| 15 | + (: (C# 'x'#) (: (C# 'y'#) (: (C# 'z'#) [])))
|
|
| 16 | + |
|
| 17 | +isOneOfThese
|
|
| 18 | + = \ x ->
|
|
| 19 | + elem
|
|
| 20 | + $fFoldableList
|
|
| 21 | + $fEqInt
|
|
| 22 | + x
|
|
| 23 | + (: (I# 1#) (: (I# 2#) (: (I# 3#) (: (I# 4#) (: (I# 5#) [])))))
|
|
| 24 | + |
|
| 25 | +isNotOneOfThese
|
|
| 26 | + = \ x ->
|
|
| 27 | + notElem
|
|
| 28 | + $fFoldableList
|
|
| 29 | + $fEqInt
|
|
| 30 | + x
|
|
| 31 | + (: (I# 1#) (: (I# 2#) (: (I# 3#) (: (I# 4#) (: (I# 5#) [])))))
|
|
| 32 | + |
|
| 33 | +isElemString
|
|
| 34 | + = \ x -> elem $fFoldableList $fEqChar x (unpackCString# "foo"#)
|
|
| 35 | + |
|
| 36 | +isNotElemString
|
|
| 37 | + = \ x -> notElem $fFoldableList $fEqChar x (unpackCString# "bar"#)
|
|
| 38 | + |
|
| 39 | +isElemStringUtf
|
|
| 40 | + = \ x ->
|
|
| 41 | + elem $fFoldableList $fEqChar x (unpackCStringUtf8# "fo\\195\\182"#)
|
|
| 42 | + |
|
| 43 | +isNotElemStringUtf
|
|
| 44 | + = \ x ->
|
|
| 45 | + notElem
|
|
| 46 | + $fFoldableList $fEqChar x (unpackCStringUtf8# "b\\195\\164r"#)
|
|
| 47 | + |
| 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 | + |
| ... | ... | @@ -5,7 +5,26 @@ setTestOpts(js_skip) |
| 5 | 5 | # Check specialization of elem via rules
|
| 6 | 6 | #--------------------------------------
|
| 7 | 7 | |
| 8 | -test('T17752', [only_ways(['normal'])] , makefile_test, ['T17752'])
|
|
| 8 | +test('T17752_O0',
|
|
| 9 | + [only_ways(['normal']), extra_files(['T17752.hs'])],
|
|
| 10 | + multimod_compile_filter,
|
|
| 11 | + ['T17752',
|
|
| 12 | + '-O0 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 13 | + "sed -n '/^is[A-Za-z]*$/,/^$/p'"])
|
|
| 14 | + |
|
| 15 | +test('T17752_O1',
|
|
| 16 | + [only_ways(['normal']), extra_files(['T17752.hs'])],
|
|
| 17 | + multimod_compile_filter,
|
|
| 18 | + ['T17752',
|
|
| 19 | + '-O1 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 20 | + "sed -n '/^is[A-Za-z]*$/,/^$/p'"])
|
|
| 21 | + |
|
| 22 | +test('T17752_O2',
|
|
| 23 | + [only_ways(['normal']), extra_files(['T17752.hs'])],
|
|
| 24 | + multimod_compile_filter,
|
|
| 25 | + ['T17752',
|
|
| 26 | + '-O2 -ddump-simpl -dsuppress-all -dsuppress-uniques -dno-typeable-binds',
|
|
| 27 | + "sed -n '/^is[A-Za-z]*$/,/^$/p'"])
|
|
| 9 | 28 | |
| 10 | 29 | #--------------------------------------
|
| 11 | 30 |