summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2023-01-27 15:07:26 +0100
committerSylvain Henry <sylvain@haskus.fr>2023-03-30 15:33:30 +0200
commit17822d93cd4f5c0cde6453779a8be4267a9cc5a2 (patch)
tree2dbb2f63bc8a40fa05f0303d3e738389795e90bb
parent29ae8fddaa0df13fca9f151e26c9fa0fe9abeb85 (diff)
downloadhaskell-wip/T22152.tar.gz
Make WordQuotRem2Op ok-for-speculation toowip/T22152
-rw-r--r--compiler/GHC/Builtin/PrimOps.hs3
-rw-r--r--compiler/GHC/Core/Utils.hs6
2 files changed, 6 insertions, 3 deletions
diff --git a/compiler/GHC/Builtin/PrimOps.hs b/compiler/GHC/Builtin/PrimOps.hs
index a6faaa09b1..82a35423f0 100644
--- a/compiler/GHC/Builtin/PrimOps.hs
+++ b/compiler/GHC/Builtin/PrimOps.hs
@@ -551,7 +551,6 @@ primOpIsCheap op = primOpOkForSpeculation op
primOpIsDiv :: PrimOp -> Bool
primOpIsDiv op = case op of
- -- TODO: quotRemWord2
IntQuotOp -> True
Int8QuotOp -> True
Int16QuotOp -> True
@@ -588,6 +587,8 @@ primOpIsDiv op = case op of
Word32QuotRemOp -> True
-- Word64QuotRemOp doesn't exist (yet)
+ WordQuotRem2Op -> True
+
FloatDivOp -> True
DoubleDivOp -> True
_ -> False
diff --git a/compiler/GHC/Core/Utils.hs b/compiler/GHC/Core/Utils.hs
index 21ceb2a7bb..565bf698bc 100644
--- a/compiler/GHC/Core/Utils.hs
+++ b/compiler/GHC/Core/Utils.hs
@@ -1615,8 +1615,10 @@ app_ok fun_ok primop_ok fun args
PrimOpId op _
| primOpIsDiv op
- , [arg1, Lit lit] <- args
- -> not (isZeroLit lit) && expr_ok fun_ok primop_ok arg1
+ , Lit divisor <- last args
+ -- there can be 2 args (most div primops) or 3 args
+ -- (WordQuotRem2Op), hence the use of last/init
+ -> not (isZeroLit divisor) && all (expr_ok fun_ok primop_ok) (init args)
-- Special case for dividing operations that fail
-- In general they are NOT ok-for-speculation
-- (which primop_ok will catch), but they ARE OK