diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2018-03-13 13:54:53 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-03-13 13:57:17 -0400 |
commit | adc3415f14aa090c54c68149dcb1d99f19132a83 (patch) | |
tree | ff40375cbd41de0d0087c73cea3de15f3843d592 /compiler/codeGen/StgCmmPrim.hs | |
parent | abfe10487d2dba49bf511297f14575f9089cc5b1 (diff) | |
download | haskell-wip/D4327.tar.gz |
WIP: Add likelyhood to alternatives from stg onwardswip/D4327
Summary:
Adds a Freq value to Stg/Cmm cases/switches/conditionals.
Currently only generates these values by checking alternatives for
bottom expressions.
They are passed along to the backend where they affect conditional generation
slightly.
As it stands runtime improvements seem to be less than expected. This might only be worth merging once we have more branch weights available.
Reviewers: hvr, goldfire, bgamari, simonmar, simonpj, erikd
Reviewed By: simonpj
Subscribers: simonpj, rwbarton, thomie, carter
GHC Trac Issues: #14672
Differential Revision: https://phabricator.haskell.org/D4327
Diffstat (limited to 'compiler/codeGen/StgCmmPrim.hs')
-rw-r--r-- | compiler/codeGen/StgCmmPrim.hs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/compiler/codeGen/StgCmmPrim.hs b/compiler/codeGen/StgCmmPrim.hs index b5cd267c6b..fa2e7d2b6c 100644 --- a/compiler/codeGen/StgCmmPrim.hs +++ b/compiler/codeGen/StgCmmPrim.hs @@ -1127,9 +1127,8 @@ genericFabsOp w [res_r] [aa] let g3 = catAGraphs [mkAssign res_t aa, mkAssign (CmmLocal res_r) (neg (CmmReg res_t))] - g4 <- mkCmmIfThenElse (gt aa zero) g2 g3 - - emit =<< mkCmmIfThenElse (eq aa zero) g1 g4 + g4 <- mkCmmIfThenElse (gt aa zero) g2 g3 Nothing + emit =<< mkCmmIfThenElse (eq aa zero) g1 g4 Nothing genericFabsOp _ _ _ = panic "genericFabsOp" @@ -1821,14 +1820,17 @@ doCopyMutableByteArrayOp = emitCopyByteArray copy where -- The only time the memory might overlap is when the two arrays -- we were provided are the same array! - -- TODO: Optimize branch for common case of no aliasing. + -- The common case is no aliasing so we set the likly value to `Just False`. copy src dst dst_p src_p bytes = do dflags <- getDynFlags [moveCall, cpyCall] <- forkAlts [ getCode $ emitMemmoveCall dst_p src_p bytes 1, getCode $ emitMemcpyCall dst_p src_p bytes 1 ] - emit =<< mkCmmIfThenElse (cmmEqWord dflags src dst) moveCall cpyCall + emit =<< mkCmmIfThenElse + (cmmEqWord dflags src dst) + moveCall cpyCall + (Just False) emitCopyByteArray :: (CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr -> FCode ()) @@ -1965,7 +1967,8 @@ doCopyMutableArrayOp = emitCopyArray copy where -- The only time the memory might overlap is when the two arrays -- we were provided are the same array! - -- TODO: Optimize branch for common case of no aliasing. + -- Optimize branch for common case of no aliasing by setting likely + -- to `Just False`. copy src dst dst_p src_p bytes = do dflags <- getDynFlags [moveCall, cpyCall] <- forkAlts [ @@ -1974,7 +1977,10 @@ doCopyMutableArrayOp = emitCopyArray copy getCode $ emitMemcpyCall dst_p src_p (mkIntExpr dflags bytes) (wORD_SIZE dflags) ] - emit =<< mkCmmIfThenElse (cmmEqWord dflags src dst) moveCall cpyCall + emit =<< mkCmmIfThenElse + (cmmEqWord dflags src dst) + moveCall cpyCall + (Just False) emitCopyArray :: (CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr -> ByteOff -> FCode ()) -- ^ copy function @@ -2028,7 +2034,8 @@ doCopySmallMutableArrayOp = emitCopySmallArray copy where -- The only time the memory might overlap is when the two arrays -- we were provided are the same array! - -- TODO: Optimize branch for common case of no aliasing. + -- Optimize branch for common case of no aliasing by setting likelyhood + -- to `Just False`. copy src dst dst_p src_p bytes = do dflags <- getDynFlags [moveCall, cpyCall] <- forkAlts @@ -2037,7 +2044,10 @@ doCopySmallMutableArrayOp = emitCopySmallArray copy , getCode $ emitMemcpyCall dst_p src_p (mkIntExpr dflags bytes) (wORD_SIZE dflags) ] - emit =<< mkCmmIfThenElse (cmmEqWord dflags src dst) moveCall cpyCall + emit =<< mkCmmIfThenElse + (cmmEqWord dflags src dst) + moveCall cpyCall + (Just False) emitCopySmallArray :: (CmmExpr -> CmmExpr -> CmmExpr -> CmmExpr -> ByteOff -> FCode ()) -- ^ copy function |