Simon Jakobi pushed to branch wip/sjakobi/T27448 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/CmmToAsm/CFG.hs
    ... ... @@ -1241,17 +1241,17 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
    1241 1241
                 let !succFreq = f * prob
    
    1242 1242
                 setEdgeFreq block bi succFreq
    
    1243 1243
                 -- traceM $ "SetOut: " ++ show (block, bi, f, prob, succFreq)
    
    1244
    -            when (bi == bhead) $ setBackProb block bi succFreq
    
    1244
    +            when (Just bi == bhead) $ setBackProb block bi succFreq
    
    1245 1245
     
    
    1246 1246
     
    
    1247
    -    let propFreq block head = do
    
    1247
    +    let propFreq block mhead = do
    
    1248 1248
                 -- traceM ("prop:" ++ show (block,head))
    
    1249 1249
                 -- traceShowM block
    
    1250 1250
     
    
    1251 1251
                 !v <- visited block
    
    1252 1252
                 if v then
    
    1253 1253
                     return () --Dont look at nodes twice
    
    1254
    -            else if block == head then
    
    1254
    +            else if Just block == mhead then
    
    1255 1255
                     setFreq block 1.0 -- Loop header frequency is always 1
    
    1256 1256
                 else do
    
    1257 1257
                     let preds = IS.elems $ predecessors block
    
    ... ... @@ -1263,7 +1263,7 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
    1263 1263
                     if irreducible
    
    1264 1264
                     then return () -- Rare we don't care
    
    1265 1265
                     else do
    
    1266
    -                    setFreq block 0
    
    1266
    +                    setFreq block (if block == entry then 1 else 0)
    
    1267 1267
                         !cycleProb <- sum <$> (forM preds $ \pred -> do
    
    1268 1268
                             if isBackEdge pred block
    
    1269 1269
                                 then
    
    ... ... @@ -1283,17 +1283,17 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
    1283 1283
                         setFreq block (f / (1.0 - cycleProb))
    
    1284 1284
     
    
    1285 1285
                 setVisited block
    
    1286
    -            calcOutFreqs head block
    
    1286
    +            calcOutFreqs mhead block
    
    1287 1287
     
    
    1288 1288
         -- Loops, by nesting, inner to outer
    
    1289 1289
         forM_ loops $ \(head, body) -> do
    
    1290 1290
             forM_ [0 .. nodeCount - 1] (\i -> unsafeWrite visitedNodes i True) -- Mark all nodes as visited.
    
    1291 1291
             forM_ body (\i -> unsafeWrite visitedNodes i False) -- Mark all blocks reachable from head as not visited
    
    1292
    -        forM_ body $ \block -> propFreq block head
    
    1292
    +        forM_ body $ \block -> propFreq block (Just head)
    
    1293 1293
     
    
    1294 1294
         -- After dealing with all loops, deal with non-looping parts of the CFG
    
    1295 1295
         forM_ [0 .. nodeCount - 1] (\i -> unsafeWrite visitedNodes i False) -- Everything in revPostOrder is reachable
    
    1296
    -    forM_ revPostOrder $ \block -> propFreq block (head revPostOrder)
    
    1296
    +    forM_ revPostOrder $ \block -> propFreq block Nothing
    
    1297 1297
     
    
    1298 1298
         -- trace ("Final freqs:") $ return ()
    
    1299 1299
         -- let freqString = pprFreqs freqs
    
    ... ... @@ -1304,6 +1304,8 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
    1304 1304
     
    
    1305 1305
         return (freqs', graph')
    
    1306 1306
       where
    
    1307
    +    entry = head revPostOrder
    
    1308
    +
    
    1307 1309
         -- How can these lookups fail? Consider the CFG [A -> B]
    
    1308 1310
         predecessors :: Int -> IS.IntSet
    
    1309 1311
         predecessors b = fromMaybe IS.empty $ IM.lookup b revGraph
    

  • testsuite/tests/cmm/should_compile/T28083.stderr
    1 1
     ==================== CFG Weights - Final ====================
    
    2 2
     stg_loop:
    
    3 3
     digraph {
    
    4
    -	c1 -> c4[label="0.25000",weight="0.25000"];
    
    5
    -	c1 -> c2[label="0.75000",weight="0.75000"];
    
    6
    -	c2 -> c1[label="0.75000",weight="0.75000"];
    
    4
    +	c1 -> c4[label="1.00000",weight="1.00000"];
    
    5
    +	c1 -> c2[label="3.00000",weight="3.00000"];
    
    6
    +	c2 -> c1[label="3.00000",weight="3.00000"];
    
    7 7
     }