diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2021-01-11 11:40:42 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-01-22 15:01:25 -0500 |
commit | 6fbfde95d3612fdd747b9785d409dc32e3fdd744 (patch) | |
tree | 7defe9620a0aeb98dab9f450209825648635e134 /testsuite | |
parent | 0eaf63b6017b173ebfc848985aa6429bb9d0a55c (diff) | |
download | haskell-6fbfde95d3612fdd747b9785d409dc32e3fdd744.tar.gz |
Test constant folding for sized types
Diffstat (limited to 'testsuite')
7 files changed, 393 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/should_run/NumConstantFolding16.hs b/testsuite/tests/simplCore/should_run/NumConstantFolding16.hs new file mode 100644 index 0000000000..b6c759b60e --- /dev/null +++ b/testsuite/tests/simplCore/should_run/NumConstantFolding16.hs @@ -0,0 +1,128 @@ +{-# LANGUAGE MagicHash #-} + +import GHC.Exts hiding + ( (+#) + , (-#) + , (*#) + ) + +import GHC.Word +import GHC.Int + +(+&) = plusWord16# +(-&) = subWord16# +(*&) = timesWord16# + +(+#) = plusInt16# +(-#) = subInt16# +(*#) = timesInt16# + +{-# NOINLINE testsW #-} +-- NOINLINE otherwise basic constant folding rules (without +-- variables) are applied +testsW :: Word16# -> Word16# -> [Word16] +testsW x y = + [ W16# (w43 +& (w37 +& x)) + , W16# (w43 +& (w37 -& x)) + , W16# (w43 +& (x -& w37)) + , W16# (w43 -& (w37 +& x)) + , W16# (w43 -& (w37 -& x)) + , W16# (w43 -& (x -& w37)) + , W16# ((w43 +& x) -& w37) + , W16# ((x +& w43) -& w37) + , W16# ((w43 -& x) -& w37) + , W16# ((x -& w43) -& w37) + + , W16# ((x +& w43) +& (y +& w37)) + , W16# ((x +& w43) +& (y -& w37)) + , W16# ((x +& w43) +& (w37 -& y)) + , W16# ((x -& w43) +& (w37 -& y)) + , W16# ((x -& w43) +& (y -& w37)) + , W16# ((w43 -& x) +& (w37 -& y)) + , W16# ((w43 -& x) +& (y -& w37)) + ] + where + W16# w37 = 37 + W16# w43 = 43 + +{-# NOINLINE testsI #-} +testsI :: Int16# -> Int16# -> [Int16] +testsI x y = + [ I16# (i43 +# (i37 +# x)) + , I16# (i43 +# (i37 -# x)) + , I16# (i43 +# (x -# i37)) + , I16# (i43 -# (i37 +# x)) + , I16# (i43 -# (i37 -# x)) + , I16# (i43 -# (x -# i37)) + , I16# ((i43 +# x) -# i37) + , I16# ((x +# i43) -# i37) + , I16# ((i43 -# x) -# i37) + , I16# ((x -# i43) -# i37) + + , I16# ((x +# i43) +# (y +# i37)) + , I16# ((x +# i43) +# (y -# i37)) + , I16# ((x +# i43) +# (i37 -# y)) + , I16# ((x -# i43) +# (i37 -# y)) + , I16# ((x -# i43) +# (y -# i37)) + , I16# ((i43 -# x) +# (i37 -# y)) + , I16# ((i43 -# x) +# (y -# i37)) + + , I16# ((x +# i43) -# (y +# i37)) + , I16# ((x +# i43) -# (y -# i37)) + , I16# ((x +# i43) -# (i37 -# y)) + , I16# ((x -# i43) -# (y +# i37)) + , I16# ((i43 -# x) -# (i37 +# y)) + , I16# ((x -# i43) -# (y -# i37)) + , I16# ((x -# i43) -# (i37 -# y)) + , I16# ((i43 -# x) -# (y -# i37)) + , I16# ((i43 -# x) -# (i37 -# y)) + + , I16# (i43 *# (i37 *# y)) + , I16# (i43 *# (y *# i37)) + , I16# ((i43 *# x) *# (y *# i37)) + + , I16# (i43 *# (i37 +# y)) + , I16# (i43 *# (i37 -# y)) + , I16# (i43 *# (y -# i37)) + + , I16# (x +# x) + , I16# ((i43 *# x) +# x) + , I16# (x +# (i43 *# x)) + , I16# ((i43 *# x) +# (i37 *# x)) + , I16# ((i43 *# x) +# (x *# i37)) + + , I16# (x -# x) + , I16# ((i43 *# x) -# x) + , I16# (x -# (i43 *# x)) + , I16# ((i43 *# x) -# (i37 *# x)) + , I16# ((i43 *# x) -# (x *# i37)) + + , I16# (x +# (i37 +# y)) + , I16# (x +# (y +# i37)) + , I16# (x +# (i37 -# y)) + , I16# (x +# (y -# i37)) + , I16# (x -# (i37 +# y)) + , I16# (x -# (y +# i37)) + , I16# (x -# (i37 -# y)) + , I16# (x -# (y -# i37)) + , I16# ((i37 +# y) -# x) + , I16# ((y +# i37) -# x) + , I16# ((i37 -# y) -# x) + , I16# ((y -# i37) -# x) + + , I16# (y *# y) + ] + where + I16# i37 = 37 + I16# i43 = 43 + + +main :: IO () +main = do + print (testsW w7 w13) + print (testsI i7 i13) + where + W16# w7 = 7 + W16# w13 = 13 + I16# i7 = 7 + I16# i13 = 13 diff --git a/testsuite/tests/simplCore/should_run/NumConstantFolding16.stdout b/testsuite/tests/simplCore/should_run/NumConstantFolding16.stdout new file mode 100644 index 0000000000..714dd508bf --- /dev/null +++ b/testsuite/tests/simplCore/should_run/NumConstantFolding16.stdout @@ -0,0 +1,2 @@ +[87,73,13,65535,13,73,13,13,65535,65463,100,26,74,65524,65476,60,12] +[87,73,13,-1,13,73,13,13,-1,-73,100,26,74,-12,-60,60,12,0,74,26,-86,-14,-12,-60,60,12,20683,20683,13709,2150,1032,-1032,14,308,308,560,560,0,294,-294,42,42,57,57,31,-17,-43,-43,-17,31,43,43,17,-31,169] diff --git a/testsuite/tests/simplCore/should_run/NumConstantFolding32.hs b/testsuite/tests/simplCore/should_run/NumConstantFolding32.hs new file mode 100644 index 0000000000..56dc38cdae --- /dev/null +++ b/testsuite/tests/simplCore/should_run/NumConstantFolding32.hs @@ -0,0 +1,128 @@ +{-# LANGUAGE MagicHash #-} + +import GHC.Exts hiding + ( (+#) + , (-#) + , (*#) + ) + +import GHC.Word +import GHC.Int + +(+&) = plusWord32# +(-&) = subWord32# +(*&) = timesWord32# + +(+#) = plusInt32# +(-#) = subInt32# +(*#) = timesInt32# + +{-# NOINLINE testsW #-} +-- NOINLINE otherwise basic constant folding rules (without +-- variables) are applied +testsW :: Word32# -> Word32# -> [Word32] +testsW x y = + [ W32# (w43 +& (w37 +& x)) + , W32# (w43 +& (w37 -& x)) + , W32# (w43 +& (x -& w37)) + , W32# (w43 -& (w37 +& x)) + , W32# (w43 -& (w37 -& x)) + , W32# (w43 -& (x -& w37)) + , W32# ((w43 +& x) -& w37) + , W32# ((x +& w43) -& w37) + , W32# ((w43 -& x) -& w37) + , W32# ((x -& w43) -& w37) + + , W32# ((x +& w43) +& (y +& w37)) + , W32# ((x +& w43) +& (y -& w37)) + , W32# ((x +& w43) +& (w37 -& y)) + , W32# ((x -& w43) +& (w37 -& y)) + , W32# ((x -& w43) +& (y -& w37)) + , W32# ((w43 -& x) +& (w37 -& y)) + , W32# ((w43 -& x) +& (y -& w37)) + ] + where + W32# w37 = 37 + W32# w43 = 43 + +{-# NOINLINE testsI #-} +testsI :: Int32# -> Int32# -> [Int32] +testsI x y = + [ I32# (i43 +# (i37 +# x)) + , I32# (i43 +# (i37 -# x)) + , I32# (i43 +# (x -# i37)) + , I32# (i43 -# (i37 +# x)) + , I32# (i43 -# (i37 -# x)) + , I32# (i43 -# (x -# i37)) + , I32# ((i43 +# x) -# i37) + , I32# ((x +# i43) -# i37) + , I32# ((i43 -# x) -# i37) + , I32# ((x -# i43) -# i37) + + , I32# ((x +# i43) +# (y +# i37)) + , I32# ((x +# i43) +# (y -# i37)) + , I32# ((x +# i43) +# (i37 -# y)) + , I32# ((x -# i43) +# (i37 -# y)) + , I32# ((x -# i43) +# (y -# i37)) + , I32# ((i43 -# x) +# (i37 -# y)) + , I32# ((i43 -# x) +# (y -# i37)) + + , I32# ((x +# i43) -# (y +# i37)) + , I32# ((x +# i43) -# (y -# i37)) + , I32# ((x +# i43) -# (i37 -# y)) + , I32# ((x -# i43) -# (y +# i37)) + , I32# ((i43 -# x) -# (i37 +# y)) + , I32# ((x -# i43) -# (y -# i37)) + , I32# ((x -# i43) -# (i37 -# y)) + , I32# ((i43 -# x) -# (y -# i37)) + , I32# ((i43 -# x) -# (i37 -# y)) + + , I32# (i43 *# (i37 *# y)) + , I32# (i43 *# (y *# i37)) + , I32# ((i43 *# x) *# (y *# i37)) + + , I32# (i43 *# (i37 +# y)) + , I32# (i43 *# (i37 -# y)) + , I32# (i43 *# (y -# i37)) + + , I32# (x +# x) + , I32# ((i43 *# x) +# x) + , I32# (x +# (i43 *# x)) + , I32# ((i43 *# x) +# (i37 *# x)) + , I32# ((i43 *# x) +# (x *# i37)) + + , I32# (x -# x) + , I32# ((i43 *# x) -# x) + , I32# (x -# (i43 *# x)) + , I32# ((i43 *# x) -# (i37 *# x)) + , I32# ((i43 *# x) -# (x *# i37)) + + , I32# (x +# (i37 +# y)) + , I32# (x +# (y +# i37)) + , I32# (x +# (i37 -# y)) + , I32# (x +# (y -# i37)) + , I32# (x -# (i37 +# y)) + , I32# (x -# (y +# i37)) + , I32# (x -# (i37 -# y)) + , I32# (x -# (y -# i37)) + , I32# ((i37 +# y) -# x) + , I32# ((y +# i37) -# x) + , I32# ((i37 -# y) -# x) + , I32# ((y -# i37) -# x) + + , I32# (y *# y) + ] + where + I32# i37 = 37 + I32# i43 = 43 + + +main :: IO () +main = do + print (testsW w7 w13) + print (testsI i7 i13) + where + W32# w7 = 7 + W32# w13 = 13 + I32# i7 = 7 + I32# i13 = 13 diff --git a/testsuite/tests/simplCore/should_run/NumConstantFolding32.stdout b/testsuite/tests/simplCore/should_run/NumConstantFolding32.stdout new file mode 100644 index 0000000000..da6f72855f --- /dev/null +++ b/testsuite/tests/simplCore/should_run/NumConstantFolding32.stdout @@ -0,0 +1,2 @@ +[87,73,13,4294967295,13,73,13,13,4294967295,4294967223,100,26,74,4294967284,4294967236,60,12] +[87,73,13,-1,13,73,13,13,-1,-73,100,26,74,-12,-60,60,12,0,74,26,-86,-14,-12,-60,60,12,20683,20683,144781,2150,1032,-1032,14,308,308,560,560,0,294,-294,42,42,57,57,31,-17,-43,-43,-17,31,43,43,17,-31,169] diff --git a/testsuite/tests/simplCore/should_run/NumConstantFolding8.hs b/testsuite/tests/simplCore/should_run/NumConstantFolding8.hs new file mode 100644 index 0000000000..330b711134 --- /dev/null +++ b/testsuite/tests/simplCore/should_run/NumConstantFolding8.hs @@ -0,0 +1,128 @@ +{-# LANGUAGE MagicHash #-} + +import GHC.Exts hiding + ( (+#) + , (-#) + , (*#) + ) + +import GHC.Word +import GHC.Int + +(+&) = plusWord8# +(-&) = subWord8# +(*&) = timesWord8# + +(+#) = plusInt8# +(-#) = subInt8# +(*#) = timesInt8# + +{-# NOINLINE testsW #-} +-- NOINLINE otherwise basic constant folding rules (without +-- variables) are applied +testsW :: Word8# -> Word8# -> [Word8] +testsW x y = + [ W8# (w43 +& (w37 +& x)) + , W8# (w43 +& (w37 -& x)) + , W8# (w43 +& (x -& w37)) + , W8# (w43 -& (w37 +& x)) + , W8# (w43 -& (w37 -& x)) + , W8# (w43 -& (x -& w37)) + , W8# ((w43 +& x) -& w37) + , W8# ((x +& w43) -& w37) + , W8# ((w43 -& x) -& w37) + , W8# ((x -& w43) -& w37) + + , W8# ((x +& w43) +& (y +& w37)) + , W8# ((x +& w43) +& (y -& w37)) + , W8# ((x +& w43) +& (w37 -& y)) + , W8# ((x -& w43) +& (w37 -& y)) + , W8# ((x -& w43) +& (y -& w37)) + , W8# ((w43 -& x) +& (w37 -& y)) + , W8# ((w43 -& x) +& (y -& w37)) + ] + where + W8# w37 = 37 + W8# w43 = 43 + +{-# NOINLINE testsI #-} +testsI :: Int8# -> Int8# -> [Int8] +testsI x y = + [ I8# (i43 +# (i37 +# x)) + , I8# (i43 +# (i37 -# x)) + , I8# (i43 +# (x -# i37)) + , I8# (i43 -# (i37 +# x)) + , I8# (i43 -# (i37 -# x)) + , I8# (i43 -# (x -# i37)) + , I8# ((i43 +# x) -# i37) + , I8# ((x +# i43) -# i37) + , I8# ((i43 -# x) -# i37) + , I8# ((x -# i43) -# i37) + + , I8# ((x +# i43) +# (y +# i37)) + , I8# ((x +# i43) +# (y -# i37)) + , I8# ((x +# i43) +# (i37 -# y)) + , I8# ((x -# i43) +# (i37 -# y)) + , I8# ((x -# i43) +# (y -# i37)) + , I8# ((i43 -# x) +# (i37 -# y)) + , I8# ((i43 -# x) +# (y -# i37)) + + , I8# ((x +# i43) -# (y +# i37)) + , I8# ((x +# i43) -# (y -# i37)) + , I8# ((x +# i43) -# (i37 -# y)) + , I8# ((x -# i43) -# (y +# i37)) + , I8# ((i43 -# x) -# (i37 +# y)) + , I8# ((x -# i43) -# (y -# i37)) + , I8# ((x -# i43) -# (i37 -# y)) + , I8# ((i43 -# x) -# (y -# i37)) + , I8# ((i43 -# x) -# (i37 -# y)) + + , I8# (i43 *# (i37 *# y)) + , I8# (i43 *# (y *# i37)) + , I8# ((i43 *# x) *# (y *# i37)) + + , I8# (i43 *# (i37 +# y)) + , I8# (i43 *# (i37 -# y)) + , I8# (i43 *# (y -# i37)) + + , I8# (x +# x) + , I8# ((i43 *# x) +# x) + , I8# (x +# (i43 *# x)) + , I8# ((i43 *# x) +# (i37 *# x)) + , I8# ((i43 *# x) +# (x *# i37)) + + , I8# (x -# x) + , I8# ((i43 *# x) -# x) + , I8# (x -# (i43 *# x)) + , I8# ((i43 *# x) -# (i37 *# x)) + , I8# ((i43 *# x) -# (x *# i37)) + + , I8# (x +# (i37 +# y)) + , I8# (x +# (y +# i37)) + , I8# (x +# (i37 -# y)) + , I8# (x +# (y -# i37)) + , I8# (x -# (i37 +# y)) + , I8# (x -# (y +# i37)) + , I8# (x -# (i37 -# y)) + , I8# (x -# (y -# i37)) + , I8# ((i37 +# y) -# x) + , I8# ((y +# i37) -# x) + , I8# ((i37 -# y) -# x) + , I8# ((y -# i37) -# x) + + , I8# (y *# y) + ] + where + I8# i37 = 37 + I8# i43 = 43 + + +main :: IO () +main = do + print (testsW w7 w13) + print (testsI i7 i13) + where + W8# w7 = 7 + W8# w13 = 13 + I8# i7 = 7 + I8# i13 = 13 diff --git a/testsuite/tests/simplCore/should_run/NumConstantFolding8.stdout b/testsuite/tests/simplCore/should_run/NumConstantFolding8.stdout new file mode 100644 index 0000000000..c1c0cbd1eb --- /dev/null +++ b/testsuite/tests/simplCore/should_run/NumConstantFolding8.stdout @@ -0,0 +1,2 @@ +[87,73,13,255,13,73,13,13,255,183,100,26,74,244,196,60,12] +[87,73,13,-1,13,73,13,13,-1,-73,100,26,74,-12,-60,60,12,0,74,26,-86,-14,-12,-60,60,12,-53,-53,-115,102,8,-8,14,52,52,48,48,0,38,-38,42,42,57,57,31,-17,-43,-43,-17,31,43,43,17,-31,-87] diff --git a/testsuite/tests/simplCore/should_run/all.T b/testsuite/tests/simplCore/should_run/all.T index ea10cd7914..afedee6bcc 100644 --- a/testsuite/tests/simplCore/should_run/all.T +++ b/testsuite/tests/simplCore/should_run/all.T @@ -93,4 +93,7 @@ test('T17151', [], multimod_compile_and_run, ['T17151', '']) test('T18012', normal, compile_and_run, ['']) test('T17744', normal, compile_and_run, ['']) test('T18638', normal, compile_and_run, ['']) +test('NumConstantFolding8', normal, compile_and_run, ['']) +test('NumConstantFolding16', normal, compile_and_run, ['']) +test('NumConstantFolding32', normal, compile_and_run, ['']) test('NumConstantFolding', normal, compile_and_run, ['']) |