PrelRules: Fix constant folding for WordRemOp
authorBen Gamari <bgamari.foss@gmail.com>
Mon, 14 Mar 2016 12:27:00 +0000 (13:27 +0100)
committerBen Gamari <ben@smart-cactus.org>
Sun, 20 Mar 2016 15:05:43 +0000 (16:05 +0100)
Test Plan: Validate with testcase in D2002

Reviewers: austin, simonpj

Reviewed By: simonpj

Subscribers: simonpj, thomie

Differential Revision: https://phabricator.haskell.org/D2004

GHC Trac Issues: #11702

compiler/prelude/PrelRules.hs
testsuite/tests/numeric/should_run/all.T

index 314dd85..a57609a 100644 (file)
@@ -134,7 +134,12 @@ primOpRules nm WordMulOp   = mkPrimOpRule nm 2 [ binaryLit (wordOp2 (*))
 primOpRules nm WordQuotOp  = mkPrimOpRule nm 2 [ nonZeroLit 1 >> binaryLit (wordOp2 quot)
                                                , rightIdentityDynFlags onew ]
 primOpRules nm WordRemOp   = mkPrimOpRule nm 2 [ nonZeroLit 1 >> binaryLit (wordOp2 rem)
-                                               , rightIdentityDynFlags onew ]
+                                               , leftZero zerow
+                                               , do l <- getLiteral 1
+                                                    dflags <- getDynFlags
+                                                    guard (l == onew dflags)
+                                                    retLit zerow
+                                               , equalArgs >> retLit zerow ]
 primOpRules nm AndOp       = mkPrimOpRule nm 2 [ binaryLit (wordOp2 (.&.))
                                                , idempotent
                                                , zeroElem zerow ]
index 515005f..8c80305 100644 (file)
@@ -66,4 +66,4 @@ test('T9407', normal, compile_and_run, [''])
 test('T9810', normal, compile_and_run, [''])
 test('T10011', normal, compile_and_run, [''])
 test('T10962', omit_ways(['ghci']), compile_and_run, [''])
-test('T11702', expect_broken(11702), compile_and_run, [''])
+test('T11702', normal, compile_and_run, [''])