diff options
author | Alex Biehl <alexbiehl@gmail.com> | 2016-11-16 18:16:39 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-11-17 11:04:02 -0500 |
commit | 20fb781ed1825578c5428ff4ae408be034c6a1d8 (patch) | |
tree | 998a0d24f5ea9c1d196e0c431f37d879f9db1f2a /compiler/cmm/CmmContFlowOpt.hs | |
parent | 9a4983dab9893f616db1c9be551ff9112084f887 (diff) | |
download | haskell-20fb781ed1825578c5428ff4ae408be034c6a1d8.tar.gz |
LLVM generate llvm.expect for conditional branches
This patch adds likeliness annotations to heap and and stack checks and
modifies the llvm codegen to recognize those to help it generate better
code.
So with this patch
```
...
if ((Sp + 8) - 24 < SpLim) (likely: False) goto c23c; else goto c23d;
...
```
roughly generates:
```
%ln23k = icmp ult i64 %ln23j, %SpLim_Arg
%ln23m = call ccc i1 (i1, i1) @llvm.expect.i1( i1 %ln23k, i1 0 )
br i1 %ln23m, label %c23c, label %c23d
```
Note the call to `llvm.expect` which denotes the expected result for
the comparison.
Test Plan: Look at assembler code with and without this patch. If the
heap-checks moved out of the way we are happy.
Reviewers: austin, simonmar, bgamari
Reviewed By: bgamari
Subscribers: michalt, thomie
Differential Revision: https://phabricator.haskell.org/D2688
GHC Trac Issues: #8321
Diffstat (limited to 'compiler/cmm/CmmContFlowOpt.hs')
-rw-r--r-- | compiler/cmm/CmmContFlowOpt.hs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/cmm/CmmContFlowOpt.hs b/compiler/cmm/CmmContFlowOpt.hs index 455422b47b..ed953ac5a8 100644 --- a/compiler/cmm/CmmContFlowOpt.hs +++ b/compiler/cmm/CmmContFlowOpt.hs @@ -282,19 +282,24 @@ blockConcat splitting_procs g@CmmGraph { g_entry = entry_id } -- This helps the native codegen a little bit, and probably has no -- effect on LLVM. It's convenient to do it here, where we have the -- information about predecessors. - -- - -- NB., only do this if the branch does not have a - -- likeliness annotation. swapcond_last - | CmmCondBranch cond t f Nothing <- shortcut_last + | CmmCondBranch cond t f l <- shortcut_last + , likelyFalse l , numPreds f > 1 , hasOnePredecessor t , Just cond' <- maybeInvertCmmExpr cond - = CmmCondBranch cond' f t Nothing + = CmmCondBranch cond' f t (invertLikeliness l) | otherwise = shortcut_last + likelyFalse (Just False) = True + likelyFalse Nothing = True + likelyFalse _ = False + + invertLikeliness (Just b) = Just (not b) + invertLikeliness Nothing = Nothing + -- Number of predecessors for a block numPreds bid = mapLookup bid backEdges `orElse` 0 |