summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorMichal Terepeta <michal.terepeta@gmail.com>2019-03-30 18:36:36 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-04-08 14:29:34 -0400
commit63b7d5fb9d695dafc243cbf6f9f70b06030c0dea (patch)
tree468304a4f8f6083c367a34ccf50142357e6db311 /compiler
parent3a38ea4487173f0f8e3693a75d1c5c7d33f12f05 (diff)
downloadhaskell-63b7d5fb9d695dafc243cbf6f9f70b06030c0dea.tar.gz
Generate straightline code for inline array allocation
GHC has an optimization for allocating arrays when the size is statically known -- it'll generate the code allocating and initializing the array inline (instead of a call to a procedure from `rts/PrimOps.cmm`). However, the generated code uses a loop to do the initialization. Since we already check that the requested size is small (we check against `maxInlineAllocSize`), we can generate faster straightline code instead. This brings about 15% improvement for `newSmallArray#` in my testing and slightly simplifies the code in GHC. Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
Diffstat (limited to 'compiler')
-rw-r--r--compiler/codeGen/StgCmmPrim.hs16
1 files changed, 5 insertions, 11 deletions
diff --git a/compiler/codeGen/StgCmmPrim.hs b/compiler/codeGen/StgCmmPrim.hs
index ae73f0af04..4a07c7893e 100644
--- a/compiler/codeGen/StgCmmPrim.hs
+++ b/compiler/codeGen/StgCmmPrim.hs
@@ -2105,17 +2105,11 @@ doNewArrayOp res_r rep info payload n init = do
-- Initialise all elements of the array
p <- assignTemp $ cmmOffsetB dflags (CmmReg arr) (hdrSize dflags rep)
- for <- newBlockId
- emitLabel for
- let loopBody =
- [ mkStore (CmmReg (CmmLocal p)) init
- , mkAssign (CmmLocal p) (cmmOffsetW dflags (CmmReg (CmmLocal p)) 1)
- , mkBranch for ]
- emit =<< mkCmmIfThen
- (cmmULtWord dflags (CmmReg (CmmLocal p))
- (cmmOffsetW dflags (CmmReg arr)
- (hdrSizeW dflags rep + n)))
- (catAGraphs loopBody)
+ let initialization =
+ [ mkStore (cmmOffsetW dflags (CmmReg (CmmLocal p)) off) init
+ | off <- [0.. n - 1]
+ ]
+ emit (catAGraphs initialization)
emit $ mkAssign (CmmLocal res_r) (CmmReg arr)