[Git][ghc/ghc][ghc-9.12] rts: restore the condition on blackholing originally added in dddf7bea
by Magnus (@MangoIV) 20 Nov '26
by Magnus (@MangoIV) 20 Nov '26
20 Nov '26
Magnus pushed to branch ghc-9.12 at Glasgow Haskell Compiler / GHC
Commits:
6175b02f by mangoiv at 2026-11-18T14:59:46+01:00
rts: restore the condition on blackholing originally added in dddf7bea
dddf7bea and 62f58b9e were applied in the wrong order. Part of the fixes
added in dddf7bea were overwritten and thus a condition was missing.
This commit restores that behaviour.
- - - - -
1 changed file:
- rts/ThreadPaused.c
Changes:
=====================================
rts/ThreadPaused.c
=====================================
@@ -341,14 +341,13 @@ threadPaused(Capability *cap, StgTSO *tso)
// If we have a frame that is already eagerly blackholed, we
// shouldn't overwrite its payload: There may already be a blocking
// queue (see #26324).
- if(frame_info == &stg_bh_upd_frame_info) {
+ if(frame_info == &stg_bh_upd_frame_info
+ || IS_BLACKHOLE_INFO(bh_info)) {
// eager black hole: we do nothing
// it should be a black hole (but we may not own it, as another
// thread could have raced us to claim it)
- ASSERT(bh_info == &stg_BLACKHOLE_info ||
- bh_info == &__stg_EAGER_BLACKHOLE_info ||
- bh_info == &stg_CAF_BLACKHOLE_info);
+ ASSERT(IS_BLACKHOLE_INFO(bh_info));
} else {
// lazy black hole
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6175b02f759cc93c0c62326df067bb0…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6175b02f759cc93c0c62326df067bb0…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc] Pushed new branch wip/sjakobi/calcfreqs-entry-and-loop-order
by Simon Jakobi (@sjakobi) 20 Nov '26
by Simon Jakobi (@sjakobi) 20 Nov '26
20 Nov '26
Simon Jakobi pushed new branch wip/sjakobi/calcfreqs-entry-and-loop-order at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/calcfreqs-entry-and-l…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/sjakobi/T27448] 2 commits: NCG: Rewrite loopInfo.mkDomMap
by Simon Jakobi (@sjakobi) 20 Nov '26
by Simon Jakobi (@sjakobi) 20 Nov '26
20 Nov '26
Simon Jakobi pushed to branch wip/sjakobi/T27448 at Glasgow Haskell Compiler / GHC
Commits:
95b528fd by Simon Jakobi at 2026-11-20T03:05:35+01:00
NCG: Rewrite loopInfo.mkDomMap
mkDomMap used to build an intermediate association list with (++)
and a recursive concatMap before handing it to mapFromList, performing
work proportional to the number of blocks times the depth of the
dominator tree.
The new code builds the LabelMap directly, with one mapInsert per
dominator-tree node. This reduces allocations when compiling the new
CmmDiamondChain test by roughly 27% at -O1 and -O2.
The map now holds each block's dominators, including the block itself
and the procedure entry. This changes which edges loopInfo reports as
back edges in two ways:
- Previously, a self-loop was reported as a back edge only if its block
was a leaf of the dominator tree (#28093).
- Loops headed by the entry block are now detected too (#28083).
Closes #27448, #28083 and #28093.
Metric Decrease:
T26425
Assisted-by: Claude Fable 5.1
- - - - -
339a921d by Simon Jakobi at 2026-11-20T03:24:34+01:00
NCG: Add types and documentation to calcFreqs
Assisted-by: Claude Fable 5.2
- - - - -
10 changed files:
- compiler/GHC/CmmToAsm/CFG.hs
- + testsuite/tests/cmm/should_compile/T28083.cmm
- + testsuite/tests/cmm/should_compile/T28083.stderr
- + testsuite/tests/cmm/should_compile/T28093.cmm
- + testsuite/tests/cmm/should_compile/T28093.stderr
- + testsuite/tests/cmm/should_compile/T28093_cas.cmm
- + testsuite/tests/cmm/should_compile/T28093_cas.stderr
- testsuite/tests/cmm/should_compile/all.T
- testsuite/tests/perf/compiler/all.T
- + testsuite/tests/perf/compiler/genCmmDiamondChain
Changes:
=====================================
compiler/GHC/CmmToAsm/CFG.hs
=====================================
@@ -797,7 +797,7 @@ loopLevels cfg root = liLevels loopInfos
loopInfos = loopInfo cfg root
data LoopInfo = LoopInfo
- { liBackEdges :: [(Edge)] -- ^ List of back edges
+ { liBackEdges :: [(Edge)] -- ^ The edges whose target dominates their source
, liLevels :: LabelMap Int -- ^ BlockId -> LoopLevel mapping
, liLoops :: [(Edge, LabelSet)] -- ^ (backEdge, loopBody), body includes header
}
@@ -840,15 +840,19 @@ loopInfo cfg root = LoopInfo { liBackEdges = backEdges
rooted = coerce (root, graph)
tree = coerce (Dom.domTree rooted) :: Tree BlockId
- -- Map from Nodes to their dominators
+ -- The dominators of each block, including the block itself.
domMap :: LabelMap LabelSet
- domMap = mkDomMap tree
+ domMap = go setEmpty mapEmpty tree
+ where
+ go :: LabelSet -> LabelMap LabelSet -> Tree BlockId -> LabelMap LabelSet
+ go doms acc (Node lbl children)
+ = let !doms' = setInsert lbl doms
+ in foldl' (go doms') (mapInsert lbl doms' acc) children
edges = edgeList cfg :: [(BlockId, BlockId)]
-- We can't recompute nodes from edges, there might be blocks not connected via edges.
nodes = getCfgNodes cfg :: [BlockId]
- -- identify back edges
isBackEdge (from,to)
| Just doms <- mapLookup from domMap
, setMember to doms
@@ -884,19 +888,6 @@ loopInfo cfg root = LoopInfo { liBackEdges = backEdges
loopCount n = length $ nub . map fst . filter (setMember n . snd) $ bodies
in map (\n -> (n, loopCount n)) $ nodes :: [(BlockId, Int)]
- mkDomMap :: Tree BlockId -> LabelMap LabelSet
- mkDomMap root = mapFromList $ go setEmpty root
- where
- go :: LabelSet -> Tree BlockId -> [(Label,LabelSet)]
- go parents (Node lbl [])
- = [(lbl, parents)]
- go parents (Node _ leaves)
- = let nodes = map rootLabel leaves
- entries = map (\x -> (x,parents)) nodes
- in entries ++ concatMap
- (\n -> go (setInsert (rootLabel n) parents) n)
- leaves
-
-- We make the CFG a Hoopl Graph, so we can reuse revPostOrder.
newtype BlockNode (e :: Extensibility) (x :: Extensibility) = BN (BlockId,[BlockId])
@@ -918,6 +909,13 @@ revPostorderFrom cfg root =
toNode bid =
BN (bid,getSuccessors cfg $ bid)
+-- | A block's index in the reverse post order of its procedure, starting at
+-- 0 for the entry.
+type Vertex = Int
+
+type VertexMap = IntMap
+
+type VertexSet = IntSet
-- | We take in a CFG which has on its edges weights which are
-- relative only to other edges originating from the same node.
@@ -952,7 +950,7 @@ mkGlobalWeights root localCfg
blockFreqs' = mapFromList $ map (first fromVertex) (assocs blockFreqs) :: LabelMap Double
edgeFreqs' = fmap fromVertexMap $ fromVertexMap edgeFreqs
- fromVertexMap :: IM.IntMap x -> LabelMap x
+ fromVertexMap :: VertexMap x -> LabelMap x
fromVertexMap m = mapFromList . map (first fromVertex) $ IM.toList m
revOrder = revPostorderFrom localCfg root :: [BlockId]
@@ -972,13 +970,13 @@ mkGlobalWeights root localCfg
calcBody (backedge, blocks) =
(toVertex $ snd backedge, sort . map toVertex $ (setElems blocks))
- vertexMapping = mapFromList $ zip revOrder [0..] :: LabelMap Int
- blockMapping = listArray (0,mapSize vertexMapping - 1) revOrder :: Array Int BlockId
+ vertexMapping = mapFromList $ zip revOrder [0..] :: LabelMap Vertex
+ blockMapping = listArray (0,mapSize vertexMapping - 1) revOrder :: Array Vertex BlockId
-- Map from blockId to indices starting at zero
- toVertex :: BlockId -> Int
+ toVertex :: BlockId -> Vertex
toVertex blockId = expectJust $ mapLookup blockId vertexMapping
-- Map from indices starting at zero to blockIds
- fromVertex :: Int -> BlockId
+ fromVertex :: Vertex -> BlockId
fromVertex vertex = blockMapping ! vertex
{- Note [Static Branch Prediction]
@@ -1162,13 +1160,13 @@ staticBranchPrediction _root (LoopInfo l_backEdges loopLevels l_loops) cfg =
-- We normalize all edge weights as probabilities between 0 and 1.
-- Ignoring rounding errors all outgoing edges sum up to 1.
-cfgEdgeProbabilities :: CFG -> (BlockId -> Int) -> IM.IntMap (IM.IntMap Prob)
+cfgEdgeProbabilities :: CFG -> (BlockId -> Vertex) -> VertexMap (VertexMap Prob)
cfgEdgeProbabilities cfg toVertex
= mapFoldlWithKey foldEdges IM.empty cfg
where
foldEdges = (\m from toMap -> IM.insert (toVertex from) (normalize toMap) m)
- normalize :: (LabelMap EdgeInfo) -> (IM.IntMap Prob)
+ normalize :: (LabelMap EdgeInfo) -> (VertexMap Prob)
normalize weightMap
| edgeCount <= 1 = mapFoldlWithKey (\m k _ -> IM.insert (toVertex k) 1.0 m) IM.empty weightMap
| otherwise = mapFoldlWithKey (\m k _ -> IM.insert (toVertex k) (normalWeight k) m) IM.empty weightMap
@@ -1189,14 +1187,28 @@ cfgEdgeProbabilities cfg toVertex
= w/totalWeight
| otherwise = panic "impossible"
+-- | Compute how often each block runs and each edge is taken per invocation
+-- of the procedure, given the probabilities of the edges.
+--
-- This is the fixpoint algorithm from
-- "Static Branch Prediction and Program Profile Analysis" by Y Wu, JR Larus
-- The adaption to Haskell is my own.
-calcFreqs :: IM.IntMap (IM.IntMap Prob) -> [(Int,Int)] -> [(Int, [Int])] -> [Int]
- -> (Array Int Double, IM.IntMap (IM.IntMap Prob))
+calcFreqs :: VertexMap (VertexMap Prob)
+ -- ^ Edge probabilities, by source and target. The probabilities of
+ -- a block's outgoing edges sum to 1.
+ -> [(Vertex, Vertex)]
+ -- ^ The back edges, as (source, target)
+ -> [(Vertex, [Vertex])]
+ -- ^ For each back edge, its target (the loop header) and the body
+ -- of its loop. The body includes the header and is in reverse post
+ -- order.
+ -> [Vertex]
+ -- ^ All blocks in reverse post order, so the entry comes first
+ -> (Array Vertex Double, VertexMap (VertexMap Prob))
+ -- ^ Block frequencies, and edge frequencies by source and target
calcFreqs graph backEdges loops revPostOrder = runST $ do
- visitedNodes <- newArray (0,nodeCount-1) False :: ST s (STUArray s Int Bool)
- blockFreqs <- newArray (0,nodeCount-1) 0.0 :: ST s (STUArray s Int Double)
+ (visitedNodes :: STUArray s Vertex Bool) <- newArray (0,nodeCount-1) False
+ (blockFreqs :: STUArray s Vertex Double) <- newArray (0,nodeCount-1) 0.0
edgeProbs <- newSTRef graph
edgeBackProbs <- newSTRef graph
@@ -1207,11 +1219,13 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
let -- See #1600, we need to inline or unboxing makes perf worse.
-- {-# INLINE getFreq #-}
{-# INLINE visited #-}
+ visited :: Vertex -> ST s Bool
visited b = unsafeRead visitedNodes b
+ getFreq :: Vertex -> ST s Double
getFreq b = unsafeRead blockFreqs b
- -- setFreq :: forall s. Int -> Double -> ST s ()
+ setFreq :: Vertex -> Double -> ST s ()
setFreq b f = unsafeWrite blockFreqs b f
- -- setVisited :: forall s. Node -> ST s ()
+ setVisited :: Vertex -> ST s ()
setVisited b = unsafeWrite visitedNodes b True
-- Frequency/probability that edge is taken.
getProb' arr b1 b2 = readSTRef arr >>=
@@ -1238,10 +1252,10 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
setBackProb b1 b2 = setProb' edgeBackProbs b1 b2
- let -- calcOutFreqs :: Node -> ST s ()
+ let calcOutFreqs :: Vertex -> Vertex -> ST s ()
calcOutFreqs bhead block = do
!f <- getFreq block
- forM (successors block) $ \bi -> do
+ forM_ (successors block) $ \bi -> do
let !prob = getProb block bi
let !succFreq = f * prob
setEdgeFreq block bi succFreq
@@ -1249,7 +1263,8 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
when (bi == bhead) $ setBackProb block bi succFreq
- let propFreq block head = do
+ let propFreq :: Vertex -> Vertex -> ST s ()
+ propFreq block head = do
-- traceM ("prop:" ++ show (block,head))
-- traceShowM block
@@ -1290,13 +1305,17 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
setVisited block
calcOutFreqs head block
- -- Loops, by nesting, inner to outer
+ -- One pass per loop. Each pass sets the probabilities of its loop's back
+ -- edges, which the passes of the enclosing loops then read.
+ -- FIXME: 'loops' is not ordered inner first.
forM_ loops $ \(head, body) -> do
forM_ [0 .. nodeCount - 1] (\i -> unsafeWrite visitedNodes i True) -- Mark all nodes as visited.
forM_ body (\i -> unsafeWrite visitedNodes i False) -- Mark all blocks reachable from head as not visited
forM_ body $ \block -> propFreq block head
- -- After dealing with all loops, deal with non-looping parts of the CFG
+ -- The whole procedure, using the back edge probabilities from the loop passes.
+ -- FIXME: The entry gets frequency 1 even when an edge leads back to it,
+ -- which makes every frequency too low by the same factor.
forM_ [0 .. nodeCount - 1] (\i -> unsafeWrite visitedNodes i False) -- Everything in revPostOrder is reachable
forM_ revPostOrder $ \block -> propFreq block (head revPostOrder)
@@ -1310,14 +1329,14 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
return (freqs', graph')
where
-- How can these lookups fail? Consider the CFG [A -> B]
- predecessors :: Int -> IS.IntSet
+ predecessors :: Vertex -> VertexSet
predecessors b = fromMaybe IS.empty $ IM.lookup b revGraph
- successors :: Int -> [Int]
+ successors :: Vertex -> [Vertex]
successors b = fromMaybe (lookupError "succ" b graph)$ IM.keys <$> IM.lookup b graph
lookupError s b g = pprPanic ("Lookup error " ++ s) $
( text "node" <+> ppr b $$
text "graph" <+>
- vcat (map (\(k,m) -> ppr (k,m :: IM.IntMap Double)) $ IM.toList g)
+ vcat (map (\(k,m) -> ppr (k,m :: VertexMap Double)) $ IM.toList g)
)
nodeCount = IM.foldl' (\count toMap -> IM.foldlWithKey' countTargets (count + 1) toMap) 0 graph
@@ -1328,7 +1347,7 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do
isBackEdge from to = S.member (from,to) backEdgeSet
backEdgeSet = S.fromList backEdges
- revGraph :: IntMap IntSet
+ revGraph :: VertexMap VertexSet
revGraph = IM.foldlWithKey' (\m from toMap -> addEdges m from toMap) IM.empty graph
where
addEdges m0 from toMap = IM.foldlWithKey' (\m k _ -> addEdge m from k) m0 toMap
=====================================
testsuite/tests/cmm/should_compile/T28083.cmm
=====================================
@@ -0,0 +1,14 @@
+#include "Cmm.h"
+
+// The entry is a bare goto, so the Cmm control-flow optimiser makes L the
+// entry, heading the loop L -> B -> L. Expected: L -> B outweighs the exit
+// edge. Without loop detection they tie.
+stg_loop {
+ goto L;
+L:
+ if (R1 > 0) { goto B; }
+ jump stg_loop [R1];
+B:
+ R1 = R1 - 1;
+ goto L;
+}
=====================================
testsuite/tests/cmm/should_compile/T28083.stderr
=====================================
@@ -0,0 +1,7 @@
+==================== CFG Weights - Final ====================
+stg_loop:
+digraph {
+ c1 -> c4[label="0.25000",weight="0.25000"];
+ c1 -> c2[label="0.75000",weight="0.75000"];
+ c2 -> c1[label="0.75000",weight="0.75000"];
+}
=====================================
testsuite/tests/cmm/should_compile/T28093.cmm
=====================================
@@ -0,0 +1,14 @@
+#include "Cmm.h"
+
+// S is a self-loop that dominates the exit block, so it is not a leaf of
+// the dominator tree. The entry does work, so it isn't merged into S.
+// Expected: the self edge outweighs the exit edge. Without loop detection
+// both get weight 0.
+stg_self {
+ R1 = R1 + 1;
+ goto S;
+S:
+ R1 = R1 - 1;
+ if (R1 > 0) { goto S; }
+ jump stg_self [R1];
+}
=====================================
testsuite/tests/cmm/should_compile/T28093.stderr
=====================================
@@ -0,0 +1,7 @@
+==================== CFG Weights - Final ====================
+stg_self:
+digraph {
+ c1 -> c4[label="1.00000",weight="1.00000"];
+ c5 -> c1[label="1.00000",weight="1.00000"];
+ c1 -> c1[label="7.00000",weight="7.00000"];
+}
=====================================
testsuite/tests/cmm/should_compile/T28093_cas.cmm
=====================================
@@ -0,0 +1,17 @@
+#include "Cmm.h"
+
+// On x86-64 the atomic or is a compare-and-swap loop: a block added by the
+// NCG with a self edge of weight 0. That block dominates the loop L -> B -> L.
+// Expected: the loop's edges outweigh its exit edge. Without the self edge
+// counting as a back edge, every edge after the atomic op gets weight 0.
+stg_cas {
+ W_ old;
+ (old) = prim %fetch_or64(R2, 1 :: I64);
+ goto L;
+L:
+ if (R1 > 0) { goto B; }
+ jump stg_cas [R1, R2];
+B:
+ R1 = R1 - 1;
+ goto L;
+}
=====================================
testsuite/tests/cmm/should_compile/T28093_cas.stderr
=====================================
@@ -0,0 +1,11 @@
+==================== CFG Weights - Final ====================
+stg_cas:
+digraph {
+ c4 -> c7[label="1.00000",weight="1.00000"];
+ c9 -> n1[label="1.00000",weight="1.00000"];
+ n1 -> n2[label="1.00000",weight="1.00000"];
+ n2 -> c4[label="1.00000",weight="1.00000"];
+ c4 -> c5[label="3.00000",weight="3.00000"];
+ c5 -> c4[label="3.00000",weight="3.00000"];
+ n1 -> n1[label="7.00000",weight="7.00000"];
+}
=====================================
testsuite/tests/cmm/should_compile/all.T
=====================================
@@ -2,6 +2,14 @@ setTestOpts(
[ req_cmm
])
+def final_cfg_weights(s):
+ """
+ The edge weights of the final CFG, without the block labels, which
+ depend on uniques.
+ """
+ final = s.split('CFG Weights - Final')[-1]
+ return '\n'.join(re.findall(r'weight="([^"]*)"', final))
+
test('selfloop', [cmm_src], compile, ['-no-hs-main'])
test('cmm_sink_sp', [ only_ways(['optasm']),
grep_errmsg(r'(\[Sp.*\]).*(=).*(\[.*R1.*\]).*;',[1,2,3]),
@@ -11,6 +19,21 @@ test('T16930', normal, makefile_test, ['T16930'])
test('T17442', normal, compile, [''])
test('T20725', normal, compile, ['-package ghc'])
test('T23610', normal, makefile_test, ['T23610'])
+test('T28083', [cmm_src, only_ways(['optasm']),
+ unless(arch('x86_64'), skip),
+ when(leading_underscore(), skip),
+ normalise_errmsg_fun(final_cfg_weights)],
+ compile, ['-no-hs-main -ddump-cfg-weights'])
+test('T28093', [cmm_src, only_ways(['optasm']),
+ unless(arch('x86_64'), skip),
+ when(leading_underscore(), skip),
+ normalise_errmsg_fun(final_cfg_weights)],
+ compile, ['-no-hs-main -ddump-cfg-weights'])
+test('T28093_cas', [cmm_src, only_ways(['optasm']),
+ unless(arch('x86_64'), skip),
+ when(leading_underscore(), skip),
+ normalise_errmsg_fun(final_cfg_weights)],
+ compile, ['-no-hs-main -ddump-cfg-weights'])
test('T24224', [cmm_src, grep_errmsg(r'(F64.*);', [1]), only_ways(['normal'])], compile, ['-no-hs-main -ddump-cmm -dsuppress-all -dsuppress-uniques'])
test('T24474', cmm_src, compile, ['-optc-g3'])
# Grep for a `... = + .. 42 ..;` occurence from within the dead code block in the cmm dump output.
=====================================
testsuite/tests/perf/compiler/all.T
=====================================
@@ -38,6 +38,17 @@ test('T3294',
compile,
[''])
+test('CmmDiamondChain',
+ [ only_ways(['optasm']),
+ unless(have_ncg(), skip),
+ cmm_src,
+ collect_compiler_stats('bytes allocated', 2),
+ pre_cmd('./genCmmDiamondChain'),
+ extra_files(['genCmmDiamondChain']),
+ ],
+ compile,
+ ['-O2 -v0'])
+
test('T4801',
[collect_compiler_runtime(2),
only_ways(['normal']),
=====================================
testsuite/tests/perf/compiler/genCmmDiamondChain
=====================================
@@ -0,0 +1,154 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# Generate a Cmm source file that is heavy on control flow.
+#
+# It produces thousands of basic blocks in a single Cmm graph,
+# stressing the control-flow handling of the NCG and Wasm backends.
+#
+# With the default knobs, the procedure looks like this:
+#
+# entry
+# |
+# v
+# .---> split0 \
+# | / \ |
+# | left0 right0 | stage 0
+# | \ / |
+# | join0 /
+# | |
+# | v
+# | split1 ... join15 stages 1 to 15
+# | |
+# | v
+# '---- latch0 trip0 < 2: back to split0
+# |
+# v
+# .---> split16 ... join31 chunk 1, same shape
+# | |
+# '---- latch1
+# |
+# v
+# ...
+# |
+# v
+# latch127 last chunk returns acc
+#
+# The variables acc and mix stay live through the whole procedure, and
+# every branch condition reads mix, so no stage can be folded away.
+# The two arms of a diamond swap their constants, so that common block
+# elimination cannot merge them.
+#
+# Each trip counter is set in the entry block and read only at its own
+# latch, so all of them start out live and the procedure spills heavily.
+#
+# Tuning knobs:
+# STAGES Number of diamond stages to generate. Default: 2048
+# LOOP_PERIOD Number of stages per loop chunk. Default: 16
+# OUT Output file. Default: CmmDiamondChain.cmm
+#
+# Run with STAGES=2 LOOP_PERIOD=2 for a small example of the output.
+
+: "${STAGES:=2048}"
+: "${LOOP_PERIOD:=16}"
+: "${OUT:=CmmDiamondChain.cmm}"
+
+(( STAGES > 0 && LOOP_PERIOD > 0 )) || {
+ echo "STAGES and LOOP_PERIOD must be positive integers" >&2
+ exit 1
+}
+
+chunk_count=$(( (STAGES + LOOP_PERIOD - 1) / LOOP_PERIOD ))
+block_count=$(( 1 + 4 * STAGES + chunk_count ))
+
+emit() {
+ printf '%s\n' "$*"
+}
+
+{
+ emit "// Generated by genCmmDiamondChain"
+ emit "//"
+ emit "// Parameters:"
+ emit "// STAGES=${STAGES}"
+ emit "// LOOP_PERIOD=${LOOP_PERIOD}"
+ emit "//"
+ emit "// Cmm blocks: ${block_count}"
+ emit "#include \"Cmm.h\""
+ emit
+ emit "diamond_chain (W_ seed) {"
+ emit " W_ acc;"
+ emit " W_ mix;"
+ for ((chunk = 0; chunk < chunk_count; chunk++)); do
+ emit " W_ trip${chunk};"
+ done
+ emit
+ emit "entry:"
+ emit " acc = seed;"
+ emit " mix = seed + (17 :: W_);"
+ for ((chunk = 0; chunk < chunk_count; chunk++)); do
+ emit " trip${chunk} = 0;"
+ done
+ emit " goto split0;"
+ emit
+
+ for ((stage = 0; stage < STAGES; stage++)); do
+ next_stage=$(( stage + 1 ))
+ chunk=$(( stage / LOOP_PERIOD ))
+ k1=$(( 4 * stage + 1 ))
+ k2=$(( 4 * stage + 2 ))
+ k3=$(( 4 * stage + 3 ))
+ k4=$(( 4 * stage + 4 ))
+
+ emit "split${stage}:"
+ emit " mix = mix + (${k1} :: W_);"
+ emit " if (((mix + (${k2} :: W_)) % (7 :: W_)) < (3 :: W_)) {"
+ emit " goto left${stage};"
+ emit " }"
+ emit " goto right${stage};"
+ emit
+
+ emit "left${stage}:"
+ emit " acc = acc + (${k3} :: W_);"
+ emit " mix = mix + (${k4} :: W_);"
+ emit " goto join${stage};"
+ emit
+
+ emit "right${stage}:"
+ emit " acc = acc + (${k4} :: W_);"
+ emit " mix = mix + (${k3} :: W_);"
+ emit " goto join${stage};"
+ emit
+
+ emit "join${stage}:"
+ emit " acc = acc + mix + (${k1} :: W_);"
+ if (( next_stage == STAGES || next_stage % LOOP_PERIOD == 0 )); then
+ emit " goto latch${chunk};"
+ else
+ emit " goto split${next_stage};"
+ fi
+ emit
+ done
+
+ for ((chunk = 0; chunk < chunk_count; chunk++)); do
+ loop_start=$(( chunk * LOOP_PERIOD ))
+ next_stage=$(( (chunk + 1) * LOOP_PERIOD ))
+ latch_mix=$(( 1000000 + chunk ))
+ latch_acc=$(( 2000000 + chunk ))
+
+ emit "latch${chunk}:"
+ emit " trip${chunk} = trip${chunk} + (1 :: W_);"
+ emit " mix = mix + (${latch_mix} :: W_);"
+ emit " acc = acc + (${latch_acc} :: W_);"
+ emit " if (trip${chunk} < (2 :: W_)) {"
+ emit " goto split${loop_start};"
+ emit " }"
+ if (( next_stage < STAGES )); then
+ emit " goto split${next_stage};"
+ else
+ emit " return (acc);"
+ fi
+ emit
+ done
+
+ emit "}"
+} > "$OUT"
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/80120e480e5eca1c31fc5ece1eccaa…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/80120e480e5eca1c31fc5ece1eccaa…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc] Pushed new branch wip/sjakobi/T27559-pap-eta-oneshot
by Simon Jakobi (@sjakobi) 20 Nov '26
by Simon Jakobi (@sjakobi) 20 Nov '26
20 Nov '26
Simon Jakobi pushed new branch wip/sjakobi/T27559-pap-eta-oneshot at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/sjakobi/T27559-pap-eta-oneshot
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/ncg-notes] 10 commits: Fix stale and false comments in the NCG
by Mikolaj Konarski (@Mikolaj) 20 Nov '26
by Mikolaj Konarski (@Mikolaj) 20 Nov '26
20 Nov '26
Mikolaj Konarski pushed to branch wip/ncg-notes at Glasgow Haskell Compiler / GHC
Commits:
5412ba62 by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Fix stale and false comments in the NCG
Of what anyone working with the NCG needs, this commit serves "Comments
and Notes that are true of the code they describe."
Comments and documentation only: the generated code is the same. Each
item names a comment, says what it said, and says what holds instead.
- The comment above genMachCode in GHC.CmmToAsm named stix code
and the UniqSM monad. The code is Cmm, and genMachCode switches
from the UniqDSM monad to NatM.
- NcgImpl's extractUnwindPoints, in GHC.CmmToAsm.Monad, placed
Note [Unwinding information in the NCG] in that module. The Note
is in GHC.CmmToAsm.
- The header of GHC.CmmToAsm.PIC named the modules CLabel, Cmm,
AsmCodeGen and MachCodeGen. It now names the modules and functions
that do what it lists. Two comments further down named MachCodeGen:
as calling cmmMakeDynamicReference for static data, which
the instruction selectors do, and as calling the initialization
of the PIC base register for every procedure that accessed it, which
cmmTopCodeGen in the x86 and PowerPC instruction selectors does,
but not on AIX. They now say so.
- The header of GHC.CmmToAsm.Reg.Target said that the module keeps
the NCG from emitting code for an architecture other than the host's.
Each of its functions dispatches on the target platform's
architecture, and the sentence is deleted.
- Note [CFG based code layout] in GHC.CmmToAsm.BlockLayout ran
optimizeCFG right after instruction selection. cmmNativeGen runs
it after register allocation and shortcutting. The Note presented
the next two steps, loopInfo's loop analysis and mkGlobalWeights'
refinement of the edge weights, as unconditional; optimizeCFG takes
them only under -fcmm-static-pred, which -O implies, and the Note now
says so. It said that the refined weights are normalized relative
to the most often visited node; they are relative to the entry node,
to which calcFreqs gives frequency 1.
- Note [CFG Edge Weights] in GHC.CmmToAsm.CFG gave the default weight
as 20k; defaultWeights has 1000. It said that likely branches
are taken more than 80% of the time and unlikely ones less than 20%;
the default weights give 75% and 25%. It said that the false side
of a regular branch is preferred; getCfg gives both sides the same
weight, the x86-64 instruction selector adds 3 to the false side
of a floating-point comparison, and optHsPatterns' favourFewerPreds
may then prefer one side by its predecessors. It said that calls
are ignored completely; the layout leaves a call's edge out while
it builds chains and while it combines neighbouring chains,
and divides its weight by 64 when it merges the chains.
- Note [Layout relevant edge weights] in GHC.CmmToAsm.BlockLayout also
said that edges constituted by a call are ignored. The layout ignores
them while it builds the chains and while it combines neighbouring
chains, and counts a 64th of their weight when it merges the chains.
- Note [Static Branch Prediction] in GHC.CmmToAsm.CFG named two
heuristics where staticBranchPrediction applies three, ohPredicts
being the third.
- In staticBranchPrediction, in GHC.CmmToAsm.CFG, a comment said that s1
is the branch in the true case; s1 is the successor with the smaller
label. The guard commented "Only backedges" is also reached by a back
edge beside a heap or stack check's edge, and its comment now says so.
- The comment above findBackEdges, in GHC.CmmToAsm.CFG, said
that it finds back edges by BFS. It finds them by a depth-first search
(classifyEdges in GHC.Data.Graph.Directed).
- The Instruction class asked regUsageOfInstr to state precisely
the registers an instruction reads and writes. x86's states them
as the register allocators are to see them, and the comment now says
so, with examples of where that departs from what the hardware does.
- The comment at the last arm of regUsageOfInstr's MOV case,
in GHC.CmmToAsm.X86.Instr, said that the MOV instructions reaching
it zero any remaining upper part of the destination. Some do, such
as a 32-bit MOV into a general register and a load at FF32 or FF64;
others keep it, such as a MOV between registers at FF32 or FF64,
printed movss or movsd, and an 8-bit or 16-bit MOV into a general
register. The comment now also says that the usage of the other MOV
instructions has a register destination written, not read.
- Comments in the liveness pass, in both register allocators and
at the Ord instances of CmmTickScope, LocalReg and VirtualReg said
that deterministic code generation is not supported, which
-fobject-determinism provides. In the liveness pass
and the allocators, each now says whether the order at hand matters
and, where it does, what it decides; at the Ord instances,
that the order compares uniques and so is deterministic only
if the uniques are.
- In GHC.CmmToAsm.Reg.Graph.SpillCost, a comment said that there
are no loops in the code, so that the block frequencies can be 1.
Given a CFG, slurpSpillCostInfo scales the uses and definitions
it counts by the CFG's block frequencies; the comment is deleted.
- linearRegAlloc's haddock and the comment over process said
that a block of an SCC is allocated before a jump into it only
if it is the procedure's first block; any of its entry blocks is.
The comment over process also said that process loops where a block's
assignment never gets set. It stops after a round that allocates
no block, and so drops such a block.
- findPrefRealReg's comment said that the preferred register
is the first one the variable was assigned to. It is the variable's
register in the first entry assignment, in allocation order, that maps
it to a register; a block's entry assignment is recorded at the first
jump into it.
- Two comments in GHC.CmmToAsm.Reg.Graph named the flag -fasm-lint,
which is -dasm-lint.
- Two comments in GHC.CmmToAsm.Reg.Linear.Base named the stats flag
-ddrop-asm-stats, which is -ddump-asm-stats.
- The executable specification of FreeRegs,
in GHC.CmmToAsm.Reg.Linear.FreeRegs, handed out the most recently
released registers first. It now gives noFreeRegs as [] and has
getFreeRegs hand out the registers in each instance's fixed order.
- The header of GHC.CmmToAsm.Reg.Linear.StackMap said that a slot stays
associated with its register to the end of the procedure. A register
that outgrows its slot moves to new ones; what holds is that no other
register gets the old slot.
- The comment at handleComponent's case for a cycle of moves,
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, said that it spills all
the cycle's source registers. It spills one.
- makeRegMovementGraph's comment said that cyclic components seem
to occur only very rarely. They are frequent in some code:
in the benchmark of orthotope, a Haskell array library on Hackage,
compiled by a GHC build of 2026-10 whose linear allocator
was master's, the fixup code breaks 39 register cycles through a stack
slot in $w$s$wequalT1 and 59 in $w$s$w$ccompare1. The two counts
were not taken again on master. The sentence is deleted.
- A comment at expandNode's case for a move from InBoth to InMem,
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, said that the source's slot
is guaranteed to be the destination's. They can differ where
the virtual register has more than one slot, and the value
is then stored from its register; the comment now says that the guard
fails only there.
- GHC.CmmToAsm.X86.Ppr's pprNatCmmDecl cited Note [Internal proc labels]
in GHC.Cmm.Label, across two lines. The Note is in GHC.Cmm.CLabel,
and the citation is now on one line.
- A comment in GHC.CmmToAsm.Reg.Linear.AArch64 said that getFreeRegs
scans the integer registers from 28 down. It starts from x18,
and the comment now also says that it starts from v31 among the v
registers.
- The comment at classOfRealReg in GHC.CmmToAsm.X86.Regs said "On x86"
of what holds on i386 alone, and numbered the registers with 8-bit
versions 1-4, and the allocatable ones among them 1, 3 and 4. It now
says "On i386", and they are 0-3, and 0, 2 and 3.
- The haddock of RegArch's Separate, in GHC.Platform.Reg.Class, gave
RISC-V as an example. registerArch gives RISC-V NoVectors
and no architecture Separate.
- The stmtToInstrs of X86, AArch64, LA64 and RV64 took the condition
of a conditional branch to be likely false, GHC.Cmm.ContFlowOpt having
arranged for the likely side to fall through. ContFlowOpt also inverts
a condition whatever its likelihood where the condition can
be inverted, the true target has one predecessor and the false target
more than one, so the condition may be likely true; none of the four
genCondBranch functions reads the likelihood.
- mkCmmIfThenElse', in GHC.StgToCmm.Monad, said that the NCG does
not know about likely annotations. The PowerPC code generator has
printed them as branch hints since 2017, and since 2018 getCfg has
weighted the CFG's edges by them, which on x86-64 the block layout
and the order of some conditional branches' jumps (invertCondBranches)
follow. Its clause on a fallthrough is replaced by what the swap does:
where the test can be inverted it becomes a likely-true test
of the inverse, and GHC.Cmm.ContFlowOpt swaps the branches back where
the true target, after shortcutting, has one predecessor.
- The users' guide said that -fcmm-static-pred's prediction is used
by the register allocation and code layout passes. The prediction
is made only in the x86-64 native code generator, and is used, after
register allocation and without -finfo-table-map, for the layout
and for the order of some conditional branches' jumps
(invertCondBranches). The entry now also says that on x86-64 the graph
colouring allocators (-fregs-graph, -fregs-iterative) weight the uses
and definitions they count by the same heuristics whatever the flag
says, without -finfo-table-map (slurpSpillCostInfo, mkGlobalWeights),
but choose what to spill by live range length alone (chooseSpill,
spillCost_length), so that the flag does not change their allocation.
- The users' guide's entry of -fcmm-sink said that the sinking pass
attempts to find identical Cmm blocks and eliminate the duplicates.
Those are words of the -fcmm-elim-common-blocks entry, run
into this entry's sentence since the two entries were written;
the sentence now says only that the pass attempts to move variable
bindings closer to their usage sites.
Assisted-by: Claude Opus 5.5
- - - - -
f17564ed by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Define the labels of the NCG's comments
Of what anyone working with the NCG needs, this commit serves "The kind
of each statement in the NCG's comments, shown at the statement: a bug,
half-done work, a likely change or code meant to stay.", "What a comment
that does not show the kind of its statements does and does not claim."
and "How the statements on bugs, half-done work and likely changes
are kept true as the code changes."
Comments only; the generated code is the same.
Note [Labels in NCG comments], added to GHC.CmmToAsm, defines the labels
that the native code generator's comments put at the head
of a statement. The commits that follow label each statement they add,
and are read under this Note:
BUG wrong behaviour, a missing check or misleading code;
the statement says in short what it leads to and where
it is reached
WIP half-done work
TODO what is likely to change, correct or buggy; a bug marked
TODO alone is accepted for now and worked around
BUG TODO both, where both are to be stressed
no label what is meant to stay; a kept trade-off says why
A BUG statement names its consequence: wrong code, wrong debugging
information, a panic or another failed compilation, assembly
the assembler rejects, only slower or larger code, only a warning
from the assembler, only more C stack space, or only a misled reader.
The Note does not reach back to older comments: their TODO, ToDo, FIXME
and XXX predate its meanings, and an older comment that carries no label
makes no claim that the code is meant to stay.
The Note also says how the labels are kept true. A change to what
a labelled statement describes removes or rewrites the statement
in the same change; BUG and TODO gain the issue's number when the issue
is filed; and a git grep given in the Note lists the labelled lines.
Assisted-by: Claude Opus 5.5
- - - - -
ae1de387 by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Document bugs and TODOs in the NCG's CFG and block layout
Of what anyone working with the NCG needs, this commit serves "Where
the code does something other than what reading it suggests.", "Where
the code is known to behave wrongly or is half done.", "What each known
bug leads to, such as wrong code, a compiler panic or only slower code,
and under which flags and on which targets it is reached." and "Where
the code is likely to change, and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments]: BUG
for wrong behaviour, TODO for what is likely to change, none for what
is meant to stay.
What each BUG leads to, where it is reached and what that rests on:
- postRegCFG in GHC.CmmToAsm (BUG: X86's allocMoreStack retargets every
jump into an entry block to the block it adds after it,
but addImmediateSuccessor moves only the entry block's own edges).
The CFG keeps an edge into the entry block from each block that jumps
there, though the code now jumps to the added block, and lacks
those blocks' edges to the added block. This costs only speed.
It is reached on x86-64, the only target with a CFG after register
allocation, where ncgAllocMoreStack adds blocks, that is, where
allocation needs more spill slots than maxSpillSlots. This rests
on master's code read. The linear allocator's fixup blocks were added
to the CFG before postRegCFG, and the added block is reachable,
through the entry block's edge to it. No reader of the CFG after
postRegCFG panics on these edges: shortcutWeightMap has no lookup
that panics; optimizeCFG's lookups take their blocks and edges
from the CFG itself; sanityCheckCfg compares blocks only; sequenceTop
looks up only the blocks the CFG's edges name, all of them blocks
of the code; and invertCondBranches takes an edge's information
as a Maybe and leaves a jump without it alone.
- build_mapping in shortcutBranches, GHC.CmmToAsm (BUG: under -g a block
that holds only its jump also holds the location and unwinding
information that -g adds, so it is kept where without -g
it is shorted). The code under -g jumps through the kept block,
and on x86-64 static prediction and block layout get another CFG
than without -g. This costs only speed and code size, under -g
and -fasm-shortcutting, on x86 and x86-64, not on Darwin. This rests
on master's code read: split matches a block of exactly one
instruction, and under -g on ELF targets other than AArch64
the instruction selectors put a LOCATION at the head of a block
with a source note, and under -g x86's gives a CmmUnwind an UNWIND,
neither of which emits code. On a development branch whose block
layout differed from master's, this changed the code of a probe
under -g.
- Note [Updating the CFG during shortcutting] in GHC.CmmToAsm.CFG (BUG:
with tables next to code too, a block that is only a tail call's jump
to a label is shortcut away, and with it the edge A -> B). A's branch
has one target fewer in the CFG than in the code, and a loop whose
only exit was the lost edge has no exit in the CFG, so calcFreqs caps
its cycle probability. This costs only speed. It is reached on x86-64,
the only target with a CFG after register allocation,
under -fasm-shortcutting, not on Darwin. This rests on master's code
read: the removed block ends in a tail call and has no edges out
in the CFG; it leaves the code and the CFG together, and no block
becomes unreachable; and the readers of the CFG after
shortcutWeightMap, listed above for postRegCFG, do not panic
on a missing edge.
- getCfg in GHC.CmmToAsm.CFG (BUG, ISSUE 28088: the CFG gets only
the blocks reachable from the entry, while instruction selection still
covers the blocks that cmmToCmm makes unreachable when, after the Cmm
pipeline has removed the unreachable blocks, it turns a branch
on a constant into a jump). Where such a block updates the CFG
at its current block, as X86's cmpxchg loop for an atomic and, or, xor
or nand does, the compiler panics with "getSuccessorEdges: Block does
not exist". This is reached on x86 and x86-64, at any optimisation
level: cmmToCmm turns a branch on a literal into a jump under every
flag, and the literal comes at -O0 from cmmToCmm's own constant
folding and at -O from sinking's. For x86-64 this rests on master's
code read and on runs of master's compiler under -dcmm-lint.
A procedure whose if (1 != 0) leaves a block with a fetch-and-and
unreachable panics with that message at -O0 and at -O, and also
at both with -finfo-table-map added, under which no CFG is kept after
instruction selection, as on i386. Where the branch tests a local set
to 1 instead, the procedure panics at -O and compiles at -O0. For i386
it rests on master's code read alone, no i386 compiler having
been run: getCfgProc builds the CFG for every target, i386 runs
the same selector (ncgX86 = ncgX86_64), and updateCfgNat forces each
update, so addImmediateSuccessor's call of getSuccessorEdges panics
during instruction selection whether or not a CFG is kept after it.
It rests also on ISSUE 28088's record.
A TODO citing ISSUE 20428, at livenessCfg
and at ncgEnableDeadCodeElimination, says that -finfo-table-map turns
dead code elimination off, and with it every use of the CFG
from the liveness pass on. No CFG is then kept after register
allocation, so the layout has neither static prediction nor the chains
of -fblock-layout-cfg, and lays the blocks out without weights.
Note [CFG Edge Weights] now says what -fcmm-static-pred changes:
that under it the weights become estimated frequencies before the layout
uses them.
A TODO in Note [Layout relevant edge weights],
in GHC.CmmToAsm.BlockLayout, citing ISSUE 27799, says that the modifier
on the edges of a conditional branch under-prices such an edge where
buildChains skips the branch's other edge because it would close
a cycle, as it can skip a loop latch's back edge.
At getCfg's case for a switch, master's comment says that the weight -1
given to every target of a switch with more than ten targets, a compiler
performance hack, keeps the layout from considering them. A TODO there
now says that the layout considers them nonetheless, and that what
the hack saves has not been measured.
Other TODOs say:
- at the Ord instance of CfgEdge, that edges of equal weight are ordered
by their labels, which carry no meaning for the layout;
- in Note [Updating the CFG during shortcutting], that where
shortcutting redirects an edge onto one already there, only one
EdgeInfo is kept and the weights are not summed;
- at allEdges' relevantWeight in sequenceChain, that it differs
from directEdges';
- at dropJumps, that a block that only jumps to the next one is left
as an empty label and a jump over it is kept.
In X86's genCondBranch', a comment says that the 3 added to the weight
of a floating-point comparison's false edge breaks layout ties toward
the side GHC.Cmm.ContFlowOpt arranges to fall through.
Assisted-by: Claude Opus 5.5
- - - - -
10b1d84c by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Document bugs and TODOs in static branch prediction and loop analysis
Of what anyone working with the NCG needs, this commit serves "The paper
or earlier design each part of the NCG is based on, where there is one,
and which code is no longer used and since which change.", "Where
the code does something other than what reading it suggests.", "Where
the code is known to behave wrongly or is half done.", "What each known
bug leads to, such as wrong code, a compiler panic or only slower code,
and under which flags and on which targets it is reached." and "Where
the code is likely to change, and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments]: BUG
for wrong behaviour, BUG TODO for a bug that is also likely to change,
WIP for half-done work, TODO for what is likely to change, none for what
is meant to stay.
What each BUG leads to, where it is reached and what that rests on:
- getCfg in GHC.CmmToAsm.CFG (BUG: after fixStgRegisters, a test
of CurrentTSO or CurrentNursery reads BaseReg and is tagged
HeapStackCheck). The exemptions of Note [Static Branch Prediction]
for heap and stack checks then apply to such a test, so its weights
are left unpredicted. This costs only speed, on x86-64
under -fcmm-static-pred. This rests on master's code read. The tag
decides the code only through isHeapOrStackCheck, all of whose callers
are in staticBranchPrediction, which runs inside mkGlobalWeights.
mkGlobalWeights reaches the code through staticPredCfg, only
under -fcmm-static-pred, and otherwise only through the graph
allocator's spill costs, whose frequencies no spill choice reads.
- Note [Back edges in loopInfo] in GHC.CmmToAsm.CFG, its BUG citing
ISSUE 28083 (an edge into the entry block is never a back edge,
as mkDomMap leaves the root out of every dominator set). A loop whose
head is the entry block is not found. This costs only speed, on x86-64
under -fcmm-static-pred. This rests on master's code read
and ISSUE 28083's record. loopInfo's result reaches the code only
through static prediction and block layout: of its two callers,
loopLevels is never called, and mkGlobalWeights serves staticPredCfg,
under -fcmm-static-pred, and otherwise only the graph allocator's
spill costs, whose frequencies no spill choice reads.
- Note [Back edges in loopInfo] in GHC.CmmToAsm.CFG, its BUG citing
ISSUE 28093 (a self loop is a back edge only where its block dominates
no other block). A block that jumps to itself and to an exit
it dominates, as cmpxchg_code's retry loop in GHC.CmmToAsm.X86.CodeGen
does, is not a loop. calcFreqs then takes the block for irreducible
and gives frequency 0 to it and to every block it dominates.
This costs only speed, on x86-64 under -fcmm-static-pred, by the same
path as the BUG of ISSUE 28083. This rests on master's code read,
on the record of ISSUE 28093, and on -ddump-cfg-weights of a loop
calling fetchOrIntArray#, compiled by a GHC built from 3d326d7d28
with changes outside the native code generator: the retry block's
edges and the loop's back edge weigh 0. Between 3d326d7d28
and the master commit this branch starts from, GHC.CmmToAsm.CFG
and cmpxchg_code are unchanged, and the dominator code loses only
a `return = pure`.
- Note [Static Branch Prediction] in GHC.CmmToAsm.CFG (BUG: the back
edge rule supersedes a likely annotation in the Cmm as well). A branch
with both a back edge and another edge is predicted to take the back
edge, whatever its annotation says. This costs only speed, on x86-64
under -fcmm-static-pred. This rests on master's code read:
staticBranchPrediction's case for a mix of back edges and other edges
reads no annotation.
- ohPredicts in staticBranchPrediction, GHC.CmmToAsm.CFG (BUG TODO:
a constructor-tag test is predicted like any other comparison,
its equal side unlikely). The prediction is wrong for the trees
of Data.Map and Data.Set, which declare Bin first: in a lookup,
the side that stays in the loop is predicted unlikely. This costs only
speed, on x86-64 under -fcmm-static-pred. It is accepted until
the knowledge of the likely side reaches the CFG, hence TODO as well.
This rests on master's code read.
- ohPredicts in staticBranchPrediction, GHC.CmmToAsm.CFG, its BUG (s1
is taken for the true side only where it is ltrue, the label
the branch was made with, which an edge no longer ends at once
the linear allocator's fixup block, by addNodesBetween,
or shortcutting, by shortcutWeightMap, has redirected it). Where
the redirected true edge's new target has the smaller label
of the two, each side gets the other's prediction, and the layout's
estimate takes the likely side for the unlikely one. This costs only
speed, on x86-64 under -fcmm-static-pred. This rests on master's code
read, and on a count over nofib's modules on a development branch
whose static prediction also predicts an inequality with a literal,
which found such branches inverted at -O2 and none at -O1.
- calcFreqs in GHC.CmmToAsm.CFG (BUG: mkGlobalWeights passes the loops
in the order of loopInfo's back edges, by label, and not by nesting).
An enclosing loop's pass can come before an inner loop's and read
the branch probability of an inner back edge where its cycle
probability belongs, which gives nested loops wrong cycle
probabilities. This costs only speed, on x86-64
under -fcmm-static-pred. This rests on master's code read.
A WIP in Note [Static Branch Prediction] says that the paper's other
heuristics are stubs.
calcFreqs' comment on an irreducible block, "Rare we don't care", now
says what frequency such a block keeps and, as a TODO, that such blocks
are not rare, that the layout then ranks edges by frequencies that do
not add up, with a loop calling fetchOrIntArray#, compiled by the GHC
named under ISSUE 28093 above, for a case, and what summing their inflow
measured on a development branch.
Other TODOs say:
- in Note [Back edges in loopInfo], that findBackEdges, which
optHsPatterns uses for the back edge bonus, disagrees with loopInfo
on edges into the entry block, on back edges of irreducible cycles
and on self loops;
- at ohPredicts, that only MO_Eq is read, so the spelling
GHC.Cmm.ContFlowOpt leaves decides whether a test is predicted,
and that predicting a pointer-tag test spelt with MO_Ne as its MO_Eq
spelling is predicted was tried on a development branch and gained
nothing;
- at lehPredicts, that where a heap or stack check's call to the garbage
collector returns into the procedure, loopInfo takes the cycle through
that call for a loop: the heuristic then says nothing about a branch
into the checking block where that block is the loop's head, and takes
a branch towards a case alternative without such a check for a loop
exit where the head is the block choosing the alternative;
- at calcFreqs, that nothing checks its result, and that a check could
compare each block's frequency with the sum of the frequencies
on its in-edges, which the propagation departs from at some blocks,
among them an irreducible block, a loop head whose cycle probability
is capped, and the entry block;
- at loopMembers, that neither it nor loopLevels has a caller in GHC:
loopMembers since the graph allocator's spill costs, for which
it was added early in 2019, began that year to weight by block
frequencies instead, and loopLevels since it came with the loop
analysis that year.
A comment at optimizeCFG says that static prediction starts
from the weights optHsPatterns leaves, so that their adjustments carry
into the predicted probabilities, except where the back edge rule
replaces them.
Assisted-by: Claude Opus 5.5
- - - - -
5a5fe67b by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Document bugs and TODOs in liveness and the register allocators
Of what anyone working with the NCG needs, this commit serves
"The invariants the code depends on.", "Where the code does something
other than what reading it suggests.", "Where the code is known
to behave wrongly or is half done.", "What each known bug leads to, such
as wrong code, a compiler panic or only slower code, and under which
flags and on which targets it is reached." and "Where the code is likely
to change, and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments].
What each BUG leads to, where it is reached and what that rests on:
- regAlloc in GHC.CmmToAsm.Reg.Graph (BUG: it hands ncgAllocMoreStack
slotsCount', the highest slot number, which counts the preallocated
slots, where the linear allocator gives only the slots beyond
maxSpillSlots): the preallocated slots are reserved a second time.
This costs C stack space, under -fregs-graph or -fregs-iterative,
on every target, and where a target's mkStackAllocInstr needs more
instructions for a larger amount, code at entry and exit: on AArch64
one instruction more for each 4095 bytes, on RISC-V, LoongArch
and PowerPC more past the range of an immediate, and on Windows x86-64
a call of ___chkstk_ms past 4 KB. This rests on master's code read.
Every target's allocMoreStack moves the stack pointer by the slots
it is given times spillSlotSize. The graph allocator can be chosen
for any target, and trivColorable covers x86, x86-64, PowerPC,
AArch64, RISC-V and LoongArch.
- pprSpillCostRecord in GHC.CmmToAsm.Reg.Graph.SpillCost (BUG: it binds
a SpillCostRecord as (reg, uses, defs, life), where the type's
comments give its fields as the writes, the reads and the lifetime).
Only the names are wrong: it prints the two counts in the record's
order, under no names, and their sum divided by the register's node
degree, and nothing in GHC calls it. This rests on master's code read:
slurpSpillCostInfo's incDefs fills the second field and incUses
the third.
- joinToTargets in GHC.CmmToAsm.Reg.Linear.JoinToTargets (BUG: on x86
a floating-point == or /= test's block ends in two jumps that name one
target, genCondBranch's parity jump and a conditional or unconditional
one, and each is joined on its own). Where that target needs a fixup
block, each of the two jumps gets one, with the same moves, and both
are reachable. This costs only code size, on x86 and x86-64
under the linear allocator. This rests on master's code read
and on constructed Cmm compiled by master's compiler; no module
of nofib or of the compile benchmarks was found to show it. A fix
that shares the block where the two jumps' stack deltas agree,
the target's vregs have the same locations at both and no value moves
between two slots was written on a development branch and is left out.
- joinToTargets_again in GHC.CmmToAsm.Reg.Linear.JoinToTargets (BUG:
once it has made a fixup block for a target and patched the jump to go
there, the destinations still to consider keep the target's later
occurrences, as a jump table lists a target once for each entry naming
it). Each later occurrence makes the same moves again, into a block
nothing jumps to, which is given an edge in the CFG, laid out
and emitted: dead code. This costs only code size, under the linear
allocator. This rests on master's code read: x86's jumpDestsOfInstr
lists a jump table's targets with their repetitions, and the other
targets with jump tables do likewise. Such a block was found in GHC's
own GHC.CmmToAsm.Dwarf.Constants and in none of nofib's
or the testsuite's modules.
- makeRegMovementGraph, handleComponent and makeMove
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, and the header
of GHC.CmmToAsm.Reg.Linear.StackMap (BUG, ISSUE 27638: since
ISSUE 26668 a virtual register whose format has outgrown its slot gets
new slots, so a jump can need a move between two slots of one
register): such a move ends in makeMove's panic, "makeMove: we don't
handle mem->mem moves". And where handleComponent's cyclic case moves
to an InBoth destination (BUG, a statement of its own, ISSUE 27638
reporting only the panic), the destination's slot is written only
if it is the slot spillR picks; otherwise it keeps a stale value,
which is wrong code where the slot is reloaded. Both are reached
under the linear allocator, where a virtual register's format grows
past 8 bytes, which only a vector format does, and so only on i386,
x86-64 and AArch64, the targets whose code generators take vectors
(checkVecCompatibility in GHC.StgToCmm.Prim; PowerPC's, RV64's
and LA64's stop with sorry on vectors). The first is reached on x86-64
at -O1 and -O2: master's compiler panics so on a function in which
a Double, also broadcast to a DoubleX2#, is live at a join of two arms
of a case that both load eleven Int#s and seventeen Doubles.
No program reaching the second is known. The first can be reached two
ways, by expandNode, both from a jump at which the virtual register
is in one of its slots only: into a block that holds it in another
of its slots only, and into a block that holds it in a register
and another slot, where makeMove loads the register first. A fix
cannot count on a spare register: nothing keeps one free at a jump,
and the block's entry assignment can hold every allocatable register,
on x86-64 the eleven integer registers (rax, rbx, rcx, rdx, rsi, rdi,
r8 to r11 and r14) and the sixteen vector registers, the others being
the stack pointer and those of STG's Base, Sp, Hp and SpLim (freeReg
in compiler/CodeGen.Platform.h). This rests on master's code read,
ISSUE 27638's record and a run of master's compiler. The cyclic case
drops the InMem half of an InBoth destination (expandNode lists InReg
first) and writes only spillR's slot, which is getStackSlotFor's
newest slot of the virtual register and differs from the destination's
only after the register grew. And allocateRegsAndSpill frees
the register of an InBoth virtual register without a store,
so that its next use reloads the slot.
- livenessSCCs in GHC.CmmToAsm.Reg.Liveness (BUG, ISSUE 27619: Regs' Eq
compares the registers and not their formats, so the fixpoint can stop
before the formats recorded for a cycle's blocks converge): a vector
register can be recorded live at a format narrower than the value
it holds, and a write at that format then kills
it in minusCoveredRegs, which is wrong code. No program giving a wrong
result is known. This rests on master's code read and ISSUE 27619's
record, whose program shows a register recorded so.
- getSlotMap in slurpReloadCoalesce, GHC.CmmToAsm.Reg.Liveness (BUG:
it folds the slot maps of a block's predecessors from the empty map
with mergeSlotMaps, which keeps only the slots both maps hold).
The slot map on entry to a block is always empty, so a reload
is coalesced with a spill only inside one block. This costs only speed
and code size, under -fregs-graph or -fregs-iterative, on every
target. This rests on master's code read; buildGraph
in GHC.CmmToAsm.Reg.Graph is the only caller of slurpReloadCoalesce.
- maxRegWithFormat in GHC.CmmToAsm.Reg.Regs (BUG, ISSUE 27619: Format's
derived Ord compares a VecFormat's number of elements before their
format, ranking VecFormat 16 FmtInt8, 128 bits, above VecFormat 4
FmtDouble, 256 bits): it can keep the narrower of two formats.
Were one register read at both, a write at the narrower would kill
it in minusCoveredRegs, which is wrong code; whether any register
is read so is not known. This rests on master's code read
and ISSUE 27619's record.
The other statements, by part.
The linear allocator:
- Note [The first jump into a block fixes its entry assignment],
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, says that the first jump
into a block that the allocator processes records the block's entry
assignment, spilled values included, and that every later jump
conforms to it by fixup code. Its three TODOs are what follows
from that: a loop head recorded from a preheader that spilled
a loop-carried value has the value reloaded on every iteration,
and stored again by every back edge once the body has written it;
a return continuation and the procedure's entry that enter one loop
at two blocks record incompatible assignments (ISSUE 27800);
and the block that a failed heap or stack check returns to
from the garbage collector can be allocated before the hot path's jump
into the checking block and record that block's entry assignment,
as the order of allocation depends on no frequency. process' comment
cites the Note.
- Note [Unique order in the linear allocator],
in GHC.CmmToAsm.Reg.Linear, says, as a TODO, which decisions take
the order of the vregs' uniques as a ranking: the spill victim,
and the order in which saveClobberedTemps moves values out
of clobbered registers. It also says that the order decides
joinToTargets' fixup moves. The comments at those three folds cite it.
- Issues get labels where the code behaves as they report: TODO
for ISSUE 27980, closed as a duplicate of ISSUE 27800,
at findPrefRealReg, for ISSUE 27981 at joinToTargets_first's release
of registers, and for ISSUE 26631 at saveClobberedTemps' choice
of a register; BUG for ISSUE 27638 at handleComponent, makeMove,
makeRegMovementGraph and StackMap's header, whose comments ruled out
a move between two stack slots, which ISSUE 26668 made possible.
- TODOs without an issue: raInsn's elimination of a move gives
the destination the source's register, whatever register an entry
assignment recorded for a block it is live into expects;
findPrefRealReg's preference is keyed by virtual register, while a Cmm
local is one virtual register over all its live ranges; and expandNode
stores a value InBoth at both ends of a jump into the slot
that already holds it.
- The header of GHC.CmmToAsm.Reg.Linear.StackMap says that a stack slot
belongs to one virtual register for the whole procedure,
as getStackSlotFor takes new slots only at the next free one, which
only grows, and a register that outgrows its slot gets another,
keeping the first; that the fixups at a jump rely on this; and
that it costs stack, the slots of a procedure adding up over every
register spilled in it.
- Step (j) of the outline at the top of GHC.CmmToAsm.Reg.Linear,
re-adding a dead spilled register's stack slot to the free list,
is marked WIP: it is not done, as a StackMap never frees a slot.
- A comment at clobberRegs' filter says that frAllocateReg panics
on a register already allocated on AArch64, RISC-V and LoongArch.
- Three designs that a trial on a development branch found no gain
in are recorded beside the code they would change: handing out
the floating-point registers in descending order (at the TODO
for ISSUE 26631 in saveClobberedTemps), taking the entry block first
and then, after each SCC, an SCC holding a block whose entry
assignment is recorded (at the TODO for ISSUE 27800), and putting
fixup moves before an unconditional jump rather than in a block
of their own (in joinToTargets_again).
Liveness, in GHC.CmmToAsm.Reg.Liveness and GHC.CmmToAsm.Reg.Regs:
- The fixpoint of livenessSCCs says that it compares the whole map
at every round (TODO, ISSUE 27437), and that its steps are monotone,
so that a test comparing the formats too would reach a result
independent of the order in which the blocks are walked. Regs' Eq says
that it ignores formats (TODO, ISSUE 27619).
- The comment on the SCCs' order says that no block may fall through
before allocation, and liveDieRead's haddock that at a branch it also
holds the registers live into its targets only.
- A comment at computeLiveness' panic on SCCs out of reverse dependent
order says that, where sccBlocks has a CFG, a jump to a block missing
from the CFG reaches it too.
The graph allocator: in GHC.CmmToAsm.Reg.Graph.SpillCost, a WIP comment
says that the block frequencies scale only the counts of uses
and definitions, on which no spill choice depends, as spillCost_chaitin,
which would read them, is commented out.
Both allocators: a TODO at patchRegsOfInstr says that, as it maps
a register to a register, both allocators reload a spilled value
into a register for an instruction that reads it, even at its last read,
where an x86 instruction could read the stack slot.
Assisted-by: Claude Opus 5.5
- - - - -
b9c33777 by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Document bugs and TODOs in code generators, DWARF and an unused module
Of what anyone working with the NCG needs, this commit serves "The paper
or earlier design each part of the NCG is based on, where there is one,
and which code is no longer used and since which change.", "Where
the code does something other than what reading it suggests.", "Where
the code is known to behave wrongly or is half done.", "What each known
bug leads to, such as wrong code, a compiler panic or only slower code,
and under which flags and on which targets it is reached." and "Where
the code is likely to change, and how."
Comments only; the generated code is the same.
The statements carry the labels of Note [Labels in NCG comments].
What each BUG leads to, where it is reached and what that rests on:
- getRegister' in GHC.CmmToAsm.AArch64.CodeGen (BUG, ISSUE 28126:
isNbitEncodeable 12 admits label offsets from -2048 to 2047, while
check_off in GHC.CmmToAsm.AArch64.Ppr accepts only 0 to 4095):
on AArch64, compiling a label at an offset from -2048 to -1 stops
with check_off's error, a pgmError,
"GHC.CmmToAsm.AArch64.Ppr.check_off : -8 is out of 12 bit"
for an offset of -8. Below -2048 the guard fails, and the next clause
adds the offset through a register. This rests on master's code read
(litToImm', ImmIndex, check_off), ISSUE 28126's record and a run
of master's x86-64 compiler given an AArch64 target description,
in which a Cmm load from a label less 8, at -O0 and at -O,
and plusAddr# of a string literal and -1#, at -O, stop
with check_off's error; nothing was run on AArch64.
- lower_CmmRegOff in GHC.CmmToAsm.Wasm.FromCmm and the cases
for CmmRegOff of getRegister' in GHC.CmmToAsm.RV64.CodeGen
and GHC.CmmToAsm.LA64.CodeGen, one BUG at each (the sum
is not truncated to a sub-word register's width, as each target's
general lowering of a sub-word MO_Add truncates its result,
and cmmMachOpFoldM in GHC.Cmm.Opt folds a sub-word register plus
a literal into a CmmRegOff at any width validOffsetRep allows). Where
an operation reads the bits above the width, this is wrong code:
on wasm32 a widening MO_UU_Conv of a sub-word value masks nothing,
and on RV64 and LA64 Note [Signed arithmetic on RISCV64] and LA64's
comment "Signed arithmetic on LoongArch64" keep a sub-word value
zero-extended between operations. This rests on master's code read
alone; nothing was run on these targets. On RV64 and LA64 an offset
that fits in 12 bits goes to the case of MO_Add for such a literal,
or on RV64 for an offset from -2047 to -1 to that of MO_Sub, which
does not truncate either (on RV64 ISSUE 28133); on RV64 an offset
of -2048 goes to MO_Sub's general case, which truncates.
- getRegister''s case for CmmRegOff in GHC.CmmToAsm.X86.CodeGen (BUG:
neither mangleIndexTree nor add_int narrows the offset
to the register's width, and cmmMachOpFoldM's folds of literals
into a CmmRegOff sum them unnarrowed). For a 16-bit register whose
offset lies outside 16 bits, add_int's LEA, printed as an ADD
of an immediate where the result takes the operand's register, makes
the assembler warn that it shortened the immediate (addw $90000,%ax
for a 16-bit register plus three times 30000); the shortened immediate
gives the value meant, so this costs only the warning, on x86
and x86-64. An 8-bit register's sum takes an ADD whose immediate
litToImm narrows, an LEA printed as an LEA takes the offset
as a 32-bit displacement without a warning, and a wider register holds
any offset add_int is given. This rests on master's code read
(mangleIndexTree, add_code, add_int and the printing of an LEA
as an ADD in GHC.CmmToAsm.X86.Ppr), on master's compiler, whose
assembly for such a sum in Cmm made the assembler warn so, and on GNU
as given addw and leaw with such an immediate and displacement,
with and without --32: it warned of the addw alone and assembled both.
- getHiVirtualRegFromLo in GHC.Platform.Reg, pointed to from localReg64
and getNewReg64 in GHC.CmmToAsm.Monad and from genByteSwap
in GHC.CmmToAsm.X86.CodeGen (BUG, ISSUE 28125: the high half keeps
the number of the low half's unique): a 64-bit Cmm local and a 64-bit
NCG temporary with the same number share their high half, and where
both are live, writing one overwrites the other's high 32 bits.
This is wrong code on i386; 32-bit PowerPC, which uses the same
functions, was not tried. Equal numbers occur, as the NCG's uniques
count from 0 in each Haskell module (initDUniqSupply 'n' 0
in GHC.Driver.Main.Compile). In genByteSwap, equal high halves
with different low halves can arise so, and the branch for that case
swaps correctly. This rests on master's code read and ISSUE 28125's
record.
- verifyBasicBlock in GHC.CmmToAsm.X86.CodeGen (BUG: nothing checks
that a block of native code ends in a transfer of control;
this checks, in a DEBUG compiler, only that nothing but jumps follows
a jump). A block that did not end in one would run on into whichever
block the layout puts after it, which is wrong code; no instruction
selector is known to make such a block. This rests on master's code
read.
- getAmode in GHC.CmmToAsm.X86.CodeGen, three clauses (BUG, ISSUE 28105:
each can emit a displacement outside the signed 32-bit range: -i where
i = -2^31; an offset left unchecked; and an offset checked only
at shift 3, as && binds tighter than ||): where the displacement does
not fit, the x86-64 assembler rejects the module. This rests
on master's code read and ISSUE 28105's record.
- getAmode in GHC.CmmToAsm.X86.CodeGen, its clause for a register offset
plus a shift (BUG: nor is the offset narrowed to the register's
width). On i386 an offset outside 32 bits reaches the assembler, which
warns and shortens it modulo 2^32, to the address meant, so this costs
only the warning; on x86-64 such an offset is the BUG of ISSUE 28105
at the same clause. This rests on master's code read, nothing having
been compiled for i386, and on GNU as given such displacements
with --32, which it shortened with a warning and assembled.
- genPrim in GHC.CmmToAsm.X86.CodeGen (BUG, ISSUE 27694: MO_UF_Conv's
genWordToFloat does not return the last block it adds, so a later
statement of the same Cmm block that splits its current block in turn,
as a second conversion does, moves the wrong block's edges): the CFG
lacks the edges of the jumps ending the Cmm block, and where
the linear allocator puts a fixup block on one of them,
addNodesBetween panics with "Can't find weight for edge that should
have one", the panic of ISSUE 27915. Where the second conversion's
last block is a lone jump, shortcutting (-fasm-shortcutting,
on at -O2, never on Darwin) cuts it, and shortcutWeightMap drops
its out-edges, which in the CFG are the only edges into the first
conversion's blocks; the blocks stay in the CFG, unreachable
from the entry and with edges, and classifyEdges
in GHC.Data.Graph.Directed, which findBackEdges calls
for optHsPatterns, panics with "Failed to classify edge of CFG -
not not timed" on an edge out of them. Both are reached on x86-64,
the only target for which backendMaintainsCfg holds, and
not under -finfo-table-map, under which no pass after instruction
selection gets a CFG. -dasm-lint does not catch the missing edges
first, as sanityCheckCfg compares the CFG's blocks with the code's
and not its edges. This rests on master's code read, the records
of ISSUE 27694 and ISSUE 27915, a run of master's compiler on a loop
with two word2Double# in one Cmm block: it panics in addNodesBetween
at -O, at -O2 and at -O -dasm-lint, and compiles at -O0
and at -O -fregs-graph, as the graph allocator makes no fixup blocks;
and a run of master's compiler on two word2Double# in one Cmm block
ahead of a loop: it panics in classifyEdges at -O2, at -O2 -dasm-lint,
at -O2 -fregs-graph, at -O1 -fasm-shortcutting
and at -O0 -fasm-shortcutting, and compiles at -O0, at -O1
and at -O2 -fno-asm-shortcutting.
- addDefaultUnwindings in GHC.CmmToAsm.Dwarf (BUG: it gives every
unwinding table that does not name Sp the rule Sp has
at the procedure's entry, and the table that X86's addSpUnwindings
adds where the C stack pointer moves, as around a C call, names MachSp
alone). Up to the next table that names Sp, DWARF gives the canonical
frame address by Sp's rule at entry: after a C call, rbp+0 on x86-64,
where before the call it can be another offset, such as rbp+16.
A debugger unwinding from there finds the wrong frame. This is reached
under -g on ELF targets, on x86 and x86-64, as ncgDwarfUnwindings
holds on ELF targets under -g and addSpUnwindings is X86's. This rests
on master's code read and on readelf's reading of the frame table
of an object that master's compiler made under -g.
The other statements:
- backendMaintainsCfg in GHC.CmmToAsm.BlockLayout said that i386 should
work but is untested. It now says, as WIP, that i386 is left out
because it is untested and its iselExpr64 splits blocks for 64-bit
shifts without adding them to the CFG.
- genPrim's comment says that its remaining cases add no blocks, while
MO_UF_Conv's genWordToFloat adds blocks: the BUG above stands there.
- mkRegRegMoveInstr in GHC.CmmToAsm.X86.Instr says that its move clears
the upper part of the register. A TODO says that for a float
or a double it is MOV FF64, printed movsd, which keeps
the destination's upper half.
- invertCondBranches inverts a jump only after an integer comparison.
A TODO says that maybeInvertCond's complement on the flags is as sound
after a floating-point one.
- pprBasicBlock in GHC.CmmToAsm.X86.Ppr aligns, past a procedure's
start, only a block with an info table (TODO, ISSUE 27668).
- condIntCode' tests a value against zero even on a path where
the instruction computing it has set ZF and SF from it, as on the back
edge of a loop that counts down: it sees only the comparison,
and another path into the test, such as the loop's entry, may set
no flags. Only a condition that reads ZF and SF alone could use
the flags of a dec, which writes OF and leaves CF where TEST clears
both (TODO, ISSUE 27738).
- GHC.CmmToAsm.Reg.Graph.Coalesce says, as a TODO, that no module
imports it, and that its pass, which ran before allocation, has had
no caller since 2007, when it was taken out of the pipeline in favour
of the coalescing that GHC.Data.Graph.Color.colorGraph does.
Assisted-by: Claude Opus 5.5
- - - - -
a369ecae by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
State the NCG's norms and where a branch's likely side is known
Of what anyone working with the NCG needs, this commit serves "The norms
and principles that apply to the NCG, whether each is agreed or only
proposed, and which trade-offs are acceptable."
Comments only; the generated code is the same.
Note [Norms of the NCG], in GHC.CmmToAsm, states two norms that GHC's
own documents and testsuite hold the native code generator to, and what
each means for a change. Under -fobject-determinism the output
is bit-for-bit the same for the same inputs, so an order taken
from uniques is a question for review. The testsuite passes -dcmm-lint
by default, so a test written in Cmm must be one that Cmm lint accepts.
Note [Where a branch's likely side is known], in GHC.CmmToAsm.CFG, says
where the code generator learns which side of a conditional branch
is likely: where the branch is made, as for heap and stack checks;
upstream, and not carried down, for constructor-tag tests; and nowhere,
for the rest, to which static prediction applies its heuristics. It also
states the trade-offs kept with that knowledge, each with its reason:
conditions inverted so that the true side falls through even where
the false side is likely, and edges across calls left out when chains
are built and when neighbouring chains are combined.
Note [Norms of the NCG] points to it.
Assisted-by: Claude Opus 5.5
- - - - -
d4eb261a by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Rewrite the NCG's overview Note
Of what anyone working with the NCG needs, this commit serves "Comments
and Notes that are true of the code they describe.", "Which targets go
through the NCG, which of its parts each target uses, and what the NCG
takes from the Cmm pipeline, StgToCmm and the RTS.", "The NCG's passes
in the order they run, and what each requires of the one before.",
"The invariants the code depends on." and "What the tests cover and what
they do not: which targets CI runs natively, which paths have few
or no tests, and which performance test exercises which pass."
Comments only; the generated code is the same.
Note [Native code generator], the module header of GHC.CmmToAsm, named
CmmStmts, cmmCodeGen, targetDoubleSize and smStablePtrTable, which
no longer exist, and machine-independent optimisations "defined below",
which are in GHC.Cmm.GenericOpt. This commit rewrites it. The Note now
says:
- which targets go through cmmNativeGen, that wasm32 has a generator
of its own, and which back end the other targets get by default;
- what the Cmm pipeline hands over, and what the NCG takes from StgToCmm
and the RTS;
- the interfaces through which the machine-independent parts access
a target, and what only some targets have;
- the passes, in the order cmmNativeGen runs them, with the flags
that turn them on and the dump flags that show their output, and,
at step 4, what instruction selection must ensure;
- where the NCG's uniques come from;
- what the assembler and the linker do after it;
- the flags, testsuite directories and benchmarks for working
on the NCG.
For detail it cites the Notes and labelled statements of the preceding
commits.
Assisted-by: Claude Opus 5.5
- - - - -
8b600b3e by Mikolaj Konarski at 2026-11-20T00:02:40+01:00
Propose two principles for the NCG
Of what anyone working with the NCG needs, this commit serves "The norms
and principles that apply to the NCG, whether each is agreed or only
proposed, and which trade-offs are acceptable."
Comments only; the generated code is the same.
Note [Proposed principles of the NCG], in GHC.CmmToAsm, puts two
principles to GHC's developers and says that the native code generator
does not keep them yet:
- correctness first: semantic correctness is not traded for a measured
gain that an incorrect form gives by accident, until a form with both
has been looked for and the trade agreed in review;
- one TODO set: a departure from correctness that is left in place
is marked TODO, as a member of one set that is accepted for now
and re-investigated together.
No other commit cites the Note, so this commit can be dropped
on its own.
Assisted-by: Claude Opus 5.5
- - - - -
273bc4b2 by Mikolaj Konarski at 2026-11-20T00:02:40+01:00
Add a README to the NCG's directory
Of what anyone working with the NCG needs, this commit serves "An order
in which to read the NCG's Notes.", "One place where the terms the NCG's
comments use are defined.", "One small function followed through
the NCG's dumps, in the order of its passes.", "Which parts of the NCG
were examined for bugs, half-done work and likely changes, and which
were not.", "The invariants the code depends on." and "How to find
the pass at fault for a miscompilation or a compiler panic, and how
to reduce the case to a Cmm test."
Documentation only; the generated code is the same.
compiler/GHC/CmmToAsm/README.md is a way in for anyone working
with the native code generator, whether reading its output and dumps,
tracking a fault to its pass, reviewing or making a change,
or maintaining it. It says what to read and what to do, and for each
fact about the code it cites a Note or a comment by name. Its sections:
- Where to start reading: three Notes of GHC.CmmToAsm, then Notes
on the passes, each with its module, in the overview's order.
- Vocabulary: the terms the NCG's comments use without defining them,
each with where it is defined or used.
- Finding the pass at fault for a wrong result or a panic: the oracles
to compare with, the flags that switch a pass off or swap it,
the lints, and how to cut a case down to a Cmm test.
- One function through the dumps: a small loop compiled at -O on x86-64,
with an excerpt for each dump flag in the overview's list of passes
but -ddump-asm-regalloc-stages, which prints nothing under the linear
allocator.
- Reviewing a change: the invariants the code depends on, as questions
by kind of change, each citing the Note or comment that states it.
- What the labelled statements cover: which parts of the NCG they
were first written from, and which were left out.
The excerpts are cut from the dumps of one compilation by a compiler
built from master: each of their lines but "..." is a line of a dump,
in the dump's order, with tabs replaced by spaces. Every Note, function,
module, flag and path the README names exists at this commit.
The overview, Note [Native code generator], now ends by pointing
to the README.
Assisted-by: Claude Opus 5.5
- - - - -
37 changed files:
- compiler/GHC/Cmm/Node.hs
- compiler/GHC/Cmm/Reg.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Dwarf.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/CodeGen.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PIC.hs
- + compiler/GHC/CmmToAsm/README.md
- compiler/GHC/CmmToAsm/RV64/CodeGen.hs
- compiler/GHC/CmmToAsm/Reg/Graph.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Base.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Coalesce.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Spill.hs
- compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/CmmToAsm/Reg/Linear/AArch64.hs
- compiler/GHC/CmmToAsm/Reg/Linear/Base.hs
- compiler/GHC/CmmToAsm/Reg/Linear/FreeRegs.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/Reg/Linear/StackMap.hs
- compiler/GHC/CmmToAsm/Reg/Liveness.hs
- compiler/GHC/CmmToAsm/Reg/Regs.hs
- compiler/GHC/CmmToAsm/Reg/Target.hs
- compiler/GHC/CmmToAsm/Wasm/FromCmm.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- compiler/GHC/CmmToAsm/X86/Regs.hs
- compiler/GHC/Driver/Config/CmmToAsm.hs
- compiler/GHC/Platform/Reg.hs
- compiler/GHC/Platform/Reg/Class.hs
- compiler/GHC/StgToCmm/Monad.hs
- docs/users_guide/using-optimisation.rst
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ecd8abb4fa8f43ee889b3b7475e622…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/ecd8abb4fa8f43ee889b3b7475e622…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/ncg-comment-fixes] Fix stale and false comments in the NCG
by Mikolaj Konarski (@Mikolaj) 20 Nov '26
by Mikolaj Konarski (@Mikolaj) 20 Nov '26
20 Nov '26
Mikolaj Konarski pushed to branch wip/ncg-comment-fixes at Glasgow Haskell Compiler / GHC
Commits:
5412ba62 by Mikolaj Konarski at 2026-11-20T00:02:39+01:00
Fix stale and false comments in the NCG
Of what anyone working with the NCG needs, this commit serves "Comments
and Notes that are true of the code they describe."
Comments and documentation only: the generated code is the same. Each
item names a comment, says what it said, and says what holds instead.
- The comment above genMachCode in GHC.CmmToAsm named stix code
and the UniqSM monad. The code is Cmm, and genMachCode switches
from the UniqDSM monad to NatM.
- NcgImpl's extractUnwindPoints, in GHC.CmmToAsm.Monad, placed
Note [Unwinding information in the NCG] in that module. The Note
is in GHC.CmmToAsm.
- The header of GHC.CmmToAsm.PIC named the modules CLabel, Cmm,
AsmCodeGen and MachCodeGen. It now names the modules and functions
that do what it lists. Two comments further down named MachCodeGen:
as calling cmmMakeDynamicReference for static data, which
the instruction selectors do, and as calling the initialization
of the PIC base register for every procedure that accessed it, which
cmmTopCodeGen in the x86 and PowerPC instruction selectors does,
but not on AIX. They now say so.
- The header of GHC.CmmToAsm.Reg.Target said that the module keeps
the NCG from emitting code for an architecture other than the host's.
Each of its functions dispatches on the target platform's
architecture, and the sentence is deleted.
- Note [CFG based code layout] in GHC.CmmToAsm.BlockLayout ran
optimizeCFG right after instruction selection. cmmNativeGen runs
it after register allocation and shortcutting. The Note presented
the next two steps, loopInfo's loop analysis and mkGlobalWeights'
refinement of the edge weights, as unconditional; optimizeCFG takes
them only under -fcmm-static-pred, which -O implies, and the Note now
says so. It said that the refined weights are normalized relative
to the most often visited node; they are relative to the entry node,
to which calcFreqs gives frequency 1.
- Note [CFG Edge Weights] in GHC.CmmToAsm.CFG gave the default weight
as 20k; defaultWeights has 1000. It said that likely branches
are taken more than 80% of the time and unlikely ones less than 20%;
the default weights give 75% and 25%. It said that the false side
of a regular branch is preferred; getCfg gives both sides the same
weight, the x86-64 instruction selector adds 3 to the false side
of a floating-point comparison, and optHsPatterns' favourFewerPreds
may then prefer one side by its predecessors. It said that calls
are ignored completely; the layout leaves a call's edge out while
it builds chains and while it combines neighbouring chains,
and divides its weight by 64 when it merges the chains.
- Note [Layout relevant edge weights] in GHC.CmmToAsm.BlockLayout also
said that edges constituted by a call are ignored. The layout ignores
them while it builds the chains and while it combines neighbouring
chains, and counts a 64th of their weight when it merges the chains.
- Note [Static Branch Prediction] in GHC.CmmToAsm.CFG named two
heuristics where staticBranchPrediction applies three, ohPredicts
being the third.
- In staticBranchPrediction, in GHC.CmmToAsm.CFG, a comment said that s1
is the branch in the true case; s1 is the successor with the smaller
label. The guard commented "Only backedges" is also reached by a back
edge beside a heap or stack check's edge, and its comment now says so.
- The comment above findBackEdges, in GHC.CmmToAsm.CFG, said
that it finds back edges by BFS. It finds them by a depth-first search
(classifyEdges in GHC.Data.Graph.Directed).
- The Instruction class asked regUsageOfInstr to state precisely
the registers an instruction reads and writes. x86's states them
as the register allocators are to see them, and the comment now says
so, with examples of where that departs from what the hardware does.
- The comment at the last arm of regUsageOfInstr's MOV case,
in GHC.CmmToAsm.X86.Instr, said that the MOV instructions reaching
it zero any remaining upper part of the destination. Some do, such
as a 32-bit MOV into a general register and a load at FF32 or FF64;
others keep it, such as a MOV between registers at FF32 or FF64,
printed movss or movsd, and an 8-bit or 16-bit MOV into a general
register. The comment now also says that the usage of the other MOV
instructions has a register destination written, not read.
- Comments in the liveness pass, in both register allocators and
at the Ord instances of CmmTickScope, LocalReg and VirtualReg said
that deterministic code generation is not supported, which
-fobject-determinism provides. In the liveness pass
and the allocators, each now says whether the order at hand matters
and, where it does, what it decides; at the Ord instances,
that the order compares uniques and so is deterministic only
if the uniques are.
- In GHC.CmmToAsm.Reg.Graph.SpillCost, a comment said that there
are no loops in the code, so that the block frequencies can be 1.
Given a CFG, slurpSpillCostInfo scales the uses and definitions
it counts by the CFG's block frequencies; the comment is deleted.
- linearRegAlloc's haddock and the comment over process said
that a block of an SCC is allocated before a jump into it only
if it is the procedure's first block; any of its entry blocks is.
The comment over process also said that process loops where a block's
assignment never gets set. It stops after a round that allocates
no block, and so drops such a block.
- findPrefRealReg's comment said that the preferred register
is the first one the variable was assigned to. It is the variable's
register in the first entry assignment, in allocation order, that maps
it to a register; a block's entry assignment is recorded at the first
jump into it.
- Two comments in GHC.CmmToAsm.Reg.Graph named the flag -fasm-lint,
which is -dasm-lint.
- Two comments in GHC.CmmToAsm.Reg.Linear.Base named the stats flag
-ddrop-asm-stats, which is -ddump-asm-stats.
- The executable specification of FreeRegs,
in GHC.CmmToAsm.Reg.Linear.FreeRegs, handed out the most recently
released registers first. It now gives noFreeRegs as [] and has
getFreeRegs hand out the registers in each instance's fixed order.
- The header of GHC.CmmToAsm.Reg.Linear.StackMap said that a slot stays
associated with its register to the end of the procedure. A register
that outgrows its slot moves to new ones; what holds is that no other
register gets the old slot.
- The comment at handleComponent's case for a cycle of moves,
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, said that it spills all
the cycle's source registers. It spills one.
- makeRegMovementGraph's comment said that cyclic components seem
to occur only very rarely. They are frequent in some code:
in the benchmark of orthotope, a Haskell array library on Hackage,
compiled by a GHC build of 2026-10 whose linear allocator
was master's, the fixup code breaks 39 register cycles through a stack
slot in $w$s$wequalT1 and 59 in $w$s$w$ccompare1. The two counts
were not taken again on master. The sentence is deleted.
- A comment at expandNode's case for a move from InBoth to InMem,
in GHC.CmmToAsm.Reg.Linear.JoinToTargets, said that the source's slot
is guaranteed to be the destination's. They can differ where
the virtual register has more than one slot, and the value
is then stored from its register; the comment now says that the guard
fails only there.
- GHC.CmmToAsm.X86.Ppr's pprNatCmmDecl cited Note [Internal proc labels]
in GHC.Cmm.Label, across two lines. The Note is in GHC.Cmm.CLabel,
and the citation is now on one line.
- A comment in GHC.CmmToAsm.Reg.Linear.AArch64 said that getFreeRegs
scans the integer registers from 28 down. It starts from x18,
and the comment now also says that it starts from v31 among the v
registers.
- The comment at classOfRealReg in GHC.CmmToAsm.X86.Regs said "On x86"
of what holds on i386 alone, and numbered the registers with 8-bit
versions 1-4, and the allocatable ones among them 1, 3 and 4. It now
says "On i386", and they are 0-3, and 0, 2 and 3.
- The haddock of RegArch's Separate, in GHC.Platform.Reg.Class, gave
RISC-V as an example. registerArch gives RISC-V NoVectors
and no architecture Separate.
- The stmtToInstrs of X86, AArch64, LA64 and RV64 took the condition
of a conditional branch to be likely false, GHC.Cmm.ContFlowOpt having
arranged for the likely side to fall through. ContFlowOpt also inverts
a condition whatever its likelihood where the condition can
be inverted, the true target has one predecessor and the false target
more than one, so the condition may be likely true; none of the four
genCondBranch functions reads the likelihood.
- mkCmmIfThenElse', in GHC.StgToCmm.Monad, said that the NCG does
not know about likely annotations. The PowerPC code generator has
printed them as branch hints since 2017, and since 2018 getCfg has
weighted the CFG's edges by them, which on x86-64 the block layout
and the order of some conditional branches' jumps (invertCondBranches)
follow. Its clause on a fallthrough is replaced by what the swap does:
where the test can be inverted it becomes a likely-true test
of the inverse, and GHC.Cmm.ContFlowOpt swaps the branches back where
the true target, after shortcutting, has one predecessor.
- The users' guide said that -fcmm-static-pred's prediction is used
by the register allocation and code layout passes. The prediction
is made only in the x86-64 native code generator, and is used, after
register allocation and without -finfo-table-map, for the layout
and for the order of some conditional branches' jumps
(invertCondBranches). The entry now also says that on x86-64 the graph
colouring allocators (-fregs-graph, -fregs-iterative) weight the uses
and definitions they count by the same heuristics whatever the flag
says, without -finfo-table-map (slurpSpillCostInfo, mkGlobalWeights),
but choose what to spill by live range length alone (chooseSpill,
spillCost_length), so that the flag does not change their allocation.
- The users' guide's entry of -fcmm-sink said that the sinking pass
attempts to find identical Cmm blocks and eliminate the duplicates.
Those are words of the -fcmm-elim-common-blocks entry, run
into this entry's sentence since the two entries were written;
the sentence now says only that the pass attempts to move variable
bindings closer to their usage sites.
Assisted-by: Claude Opus 5.5
- - - - -
31 changed files:
- compiler/GHC/Cmm/Node.hs
- compiler/GHC/Cmm/Reg.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/CodeGen.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PIC.hs
- compiler/GHC/CmmToAsm/RV64/CodeGen.hs
- compiler/GHC/CmmToAsm/Reg/Graph.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Base.hs
- compiler/GHC/CmmToAsm/Reg/Graph/Spill.hs
- compiler/GHC/CmmToAsm/Reg/Graph/SpillCost.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/CmmToAsm/Reg/Linear/AArch64.hs
- compiler/GHC/CmmToAsm/Reg/Linear/Base.hs
- compiler/GHC/CmmToAsm/Reg/Linear/FreeRegs.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/Reg/Linear/StackMap.hs
- compiler/GHC/CmmToAsm/Reg/Liveness.hs
- compiler/GHC/CmmToAsm/Reg/Target.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- compiler/GHC/CmmToAsm/X86/Regs.hs
- compiler/GHC/Platform/Reg.hs
- compiler/GHC/Platform/Reg/Class.hs
- compiler/GHC/StgToCmm/Monad.hs
- docs/users_guide/using-optimisation.rst
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5412ba62c88ac7213b1257806c1b54b…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5412ba62c88ac7213b1257806c1b54b…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
19 Nov '26
Simon Peyton Jones pushed to branch wip/case-bndr-unf at Glasgow Haskell Compiler / GHC
Commits:
38b6e0e7 by Simon Peyton Jones at 2026-11-19T23:48:40+00:00
Wibble [skip ci]
- - - - -
1 changed file:
- compiler/GHC/Core/Opt/WorkWrap.hs
Changes:
=====================================
compiler/GHC/Core/Opt/WorkWrap.hs
=====================================
@@ -968,64 +968,96 @@ the form [Demand=<L,1*(C(1,...(C(1,U))))>]
Note [Thunk splitting]
~~~~~~~~~~~~~~~~~~~~~~
-Consider a strict non-recursive let-binding:
- let x* = x-rhs
- in body
-
-(I'll use a '*' to mean "x* is demanded strictly".)
-`splitThunk` transforms like this:
- let x* = case x-rhs of { I# a -> I# a }
- in body
-
-This may seem a little strange: the RHS takes `x` apart and reboxes it.
-But because the outer 'let' is strict, the simplifier uses `StrictBind`
-to float the `case` out, giving
- case x-rhs of I# a ->
- let x* = I# a in body
-
-That is good: in `body` we know the form of `x`, which
- * gives the CPR property, and
- * allows case-of-known-constructor to happen on x
- * can avoid reboxing: see (TS1)
+The worker/wrapper split mainly affects let-bound /functions/. But we can also use
+demand and CPR information to improve let-bound /thunks/. Specifically:
+
+* (A) Demand-led thunk splitting:
+ If a thunk is demanded strictly, perhaps nestedly, we can turn it into a
+ case, perhaps nestedly. For example
+ let x :: (Int, Int)
+ {- Dmd = SP(S,L) -}
+ x = rhs
+ in body
+ We would ultimately like to get
+ case rhs of x { (a,b) ->
+ case a of { I# a# ->
+ body
+
+ This much better: no thunk for `rhs`; and known-data-con unfoldings for `x`
+ and `a` inside `body`.
+
+* (B) CPR-led thunk splitting:
+ If a thunk has the (possibly-nested) CPR property /and/ is demanded strictly
+ at top level, we can again generate a case
+ let x :: (Int, Int)
+ {- Dmd = S, Cpr = (_, I# _) -}
+ x = rhs
+ in body
+ The CPR info says that if `x` is evaluated (which is is), it'll return a pair,
+ whose second component can very cheaply be evaluated to a (I# b#). We would
+ like to end up with
+ case rhs of x { (a,b) ->
+ case b of { I# b# ->
+ body
+ which is good for the same reasons as before. See (TS1) for an example.
+
+Notice that (B) CPR-led thunk splitting can be useful:
+ * If multi-constructor data types are involved, so that the argument-unboxing
+ mechanism (A) is impotent.
+ * If the binder is only demanded at top level, but CPR has nested information.
+
+We might do even better by combinding (A) and (B) but at the moment we try (A)
+first, and then try (B) if (A) is impotent.
+
+Implementation
+~~~~~~~~~~~~~~
+The worker/wrapper pass does not generate these nested case expressions directly.
+Instead it generates a regular let-binding but, since the binder is marked as
+strict, any `case` expessions in the RHS will float out. Specifically;
+
+* For (A), `splitThunkStr` generates the binding
+ let x* = case rhs of { (a,b) ->
+ case a of { I# a# ->
+ (I# a, b)
+ Now when the Simplifier floats the `case` expressions out, we get
+ case rhs of { (a.b) ->
+ case a of { I# a# ->
+ let x = (I# a b)
+ in body
+ which is equivalent to the expression in (A) above.
+
+ Rather cleverly, `splitThunkStr` uses `mkWWstr_one`, the /existing/ function
+ argument w/w splitting function, to do the unpacking. This automatically
+ deals with nested strictness.
+
+* For (B), `splitThunkCpr` behaves exactly analogously, again using `mkWWcpr_one`
+ to do the unpacking.
Wrinkles:
-(T1) Suppose x-rhs is itself a case, so we started with
- let x* = case e of { T -> I# e1; F -> I# e2 }
+(TS1) Here's an example of (B), thunk-splitting based on CPR information, in action.
+ Suppose we have
+ let x* = case e of { T -> Just e1; F -> Just e2 }
in body
- If the Simplifire floats the `case` out, we get
+ If the Simplifier floats the `case` out, we get
join j2 x = body
- in case e of { T -> j2 (I# e1); F -> j (I# e2) }
+ in case e of { T -> j2 (Just e1); F -> j (Just e2) }
which is not good (boxing).
If we first do the thunk-splitting transformation, we get
- let x* = case (case e of { T -> I# e1; F -> I# e2 }) of
- I# a -> I# a
+ let x* = case (case e of { T -> Just e1; F -> Just e2 }) of
+ Just a -> Just a
in body
Now when the Simplifier floats we will get:
- join j a = let x* = I# a in body
+ join j a = let x* = Just a in body
in case e of { T -> j e1; F -> j e2 }
- which is good (no boxing).
+ which is much better (no boxing).
-(TS3) In fact, splitThunk uses the function argument w/w splitting
- function, mkWWstr_one, so in our example we /actually/ get
- let
- x* = let x = x-rhs in
- case x of { I# a -> I# a }
- in body
- Here `x` is used exactly once in the RHS so it'll be inlined.
-
- A big advantage of using `mkWWstr_one` is that if x's demand is deeper
- (say U(U(L,L),L)) then the splitting will go deeper too.
-
-(TS4) For recursive thunks, the Simplifier is unable to float `x-rhs` out of
+(TS2) For recursive thunks, the Simplifier is unable to float `x-rhs` out of
`x*`'s RHS, because `x*` occurs freely in `x-rhs`, and will just change it
back to the original definition, so we just split non-recursive thunks.
-(TS5) We can do thunk-splitting for CPR too, to get stuff that strictness
- cannot. Consider
-
Note [Thunk splitting for top-level binders]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Top-level bindings are never strict. Yet they can be absent, as T14270 shows:
@@ -1076,7 +1108,7 @@ splitThunkStr :: WwOpts -> RecFlag -> Var -> CoreExpr -> UniqSM (Maybe CoreExpr)
splitThunkStr ww_opts is_rec x rhs
= assert (not (isJoinId x)) $
assertPpr (isNonRec is_rec) (ppr x) $ -- The thunk must be non-recursive
- -- See (TS4) in Note [Thunk splitting]
+ -- See (TS2) in Note [Thunk splitting]
do { let x' = localiseId x -- See comment above
; (useful, _transit_vars, wrap_fn, fn_arg) <- mkWWstr_one ww_opts x' NotMarkedStrict
-- Use mkWWstr_one: see (TS3) in Note [Thunk splitting]
@@ -1087,6 +1119,7 @@ splitThunkStr ww_opts is_rec x rhs
else return Nothing }
splitThunkCpr :: WwOpts -> RecFlag -> Var -> CoreExpr -> UniqSM (Maybe CoreExpr)
+-- See Note [Thunk splitting]
-- Given x* = rhs, where x* is used outermost-strictly, and x* has a (nested) CPR
-- property, say Just (Just _), return this new RHS:
-- let x' = rhs in
@@ -1097,7 +1130,7 @@ splitThunkCpr ww_opts is_rec x rhs
| isStrUsedDmd (idDemandInfo x)
= assertPpr (cprTypeArity cpr_type == 0) (ppr x) $ -- It's a thunk
assertPpr (isNonRec is_rec) (ppr x) $ -- The thunk must be non-recursive
- -- See (TS4) in Note [Thunk splitting]
+ -- See (TS2) in Note [Thunk splitting]
do { (useful, _transit_vars, rebuild_result, unpacker) <- mkWWcpr_one ww_opts x' cpr
; if useful
then return (Just (Let (NonRec x' rhs) $
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/38b6e0e797a61b027219ef98309b75d…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/38b6e0e797a61b027219ef98309b75d…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
19 Nov '26
Andreas Klebinger pushed new branch wip/apk/cmm-flow-sink at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/apk/cmm-flow-sink
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc] Deleted branch wip/dcoutts/windows-rts-dll
by David Eichmann (@DavidEichmann) 19 Nov '26
by David Eichmann (@DavidEichmann) 19 Nov '26
19 Nov '26
David Eichmann deleted branch wip/dcoutts/windows-rts-dll at Glasgow Haskell Compiler / GHC
--
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 35 commits: Move idle GC tracking to its own file, step 1 of 2
by Marge Bot (@marge-bot) 19 Nov '26
by Marge Bot (@marge-bot) 19 Nov '26
19 Nov '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
f3f23e0e by Duncan Coutts at 2026-11-18T16:09:16+00:00
Move idle GC tracking to its own file, step 1 of 2
Add a new IdleGC.{c,h} module. Move the RecentActivity type,
recent_activity variable and {get,set}RecentActivity wrappers.
- - - - -
18935093 by Duncan Coutts at 2026-11-18T16:09:16+00:00
Move idle GC functionality to its own file, step 2 of 2
We can now fully encapsulate the recent_activity state, exposing just
three hooks, and one query used in the scheduler and timer tick.
This is a prelude to making changes to the implementation of tracking
when to perform an idle gc.
- - - - -
ca7152b6 by Duncan Coutts at 2026-11-18T16:09:16+00:00
Correct comments in idle GC code
The comments still referred to stopTimer/startTimer. These were
replaced recently by pauseTimer/unpauseTimer, but the comment was not
updated.
- - - - -
dad9bf87 by Duncan Coutts at 2026-11-18T16:09:16+00:00
Make signal handling be a responsibility of the I/O manager(s)
Previously it was scattered between I/O managers and the scheduler, and
especially the scheduler's deadlock detection.
Previously the scheduler would poll for pending signals each iteration
of the scheduler loop. The scheduler also had some hairy signal
functionality in the deadlock detection: in the non-threaded RTS (only)
if there were still no threads running after deadlock detection then it
would block waiting for signals.
But signals can and (in my opinion) should be thought of as just a funny
kind of I/O, and thus should be a responsibility of the I/O manager.
So now we have the I/O managers poll for signals when they are polling
for I/O completion (and removing the separate poll in the scheduler).
And when I/O managers block waiting for I/O then they now also start
signal handlers if they get interrupted by a signal. Crucially, if there
is no pending I/O or timers, the awaitCompletedTimeoutsOrIO will still
block waiting for signals.
This patch puts us into an intermediate state: it temporarily breaks
deadlock detection in the non-threaded RTS. The waiting on I/O currently
happens before deadlock detection. This means we'll now wait forever on
signals before doing deadlock detection. We need to move waiting after
deadlock detection. We'll do that in a later patch.
- - - - -
5fef411b by Duncan Coutts at 2026-11-18T16:20:55+00:00
Clean up the RTS internal signal handling API
Now that the I/O manager is responsible for signals, we can simplify the
API we present for signal handling.
We now just need startPendingSignalHandlers, which is called from the
I/O managers. We can get rid of awaitUserSignals. We also don't need
RtsSignals.h to re-export the platform-specific posix/Signals.h or
win32/ConsoleHandler.h
We can also hide more of the implementation of signals. Less has to be
exposed in posix/Signals.h or win32/ConsoleHandler.h. Indeed,
posix/Signals.h becomes empty and we remove it. Partly this is because
we don't need inline functions (or macros) in the interface.
Also remove signal_handlers from RTS ABI exported symbols list. It does
not appear to have any users in the core libs, and its really an
internal implementation detail. It should not be exposed unless it's
really necessary.
- - - - -
f2edb52c by Duncan Coutts at 2026-11-18T16:20:55+00:00
Narrow the window in which signals might be missed before poll/select
Any signals delivered just before poll/select block will be missed until
they are woken later by unrelated events. This arbitrarily delays the
delivery of signals.
This is not a complete solution. It is a cheap way to narrow but not
close the window. A full solution will have to come later. This issue
existed already, and is documented in issue #27540.
- - - - -
5f6adfe3 by Duncan Coutts at 2026-11-18T16:20:55+00:00
In the scheduler, move I/O blocking after deadlock detection
To make deadlock detection effective in the non-threaded RTS when there
are deadlocked threads and other unrelated threads waiting on I/O, we
need to arrange to do deadlock detection before we block in scheduler
to wait on I/O.
The solution is to:
1. adjust scheduleFindWork, which runs before deadlock detection, to
only poll for I/O and not block; and
2. add a step after deadlock detection to wait on I/O if there are
still no threads to run (and there's any I/O or timeouts outstanding)
The scheduleCheckBlockedThreads is now so simple that it made more sense
to inline it into scheduleFindWork.
- - - - -
a3cbca91 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Remove bogus anyPendingTimeoutsOrIO guard from scheduleDetectDeadlock
The deadlock detection was only invoked if both of these conditions
hold:
1. the run queue is empty
2. there is no pending I/O or timeouts
The second condition is unnecessary. The deadlock detection mechanism
can find deadlocks even if there are other threads waiting on I/O or
timers. Having this extra condition means that we fail to detect
blocked threads if there are any threads waiting on I/O or timers.
Part of fixing issue #26408
- - - - -
7e1b30dc by Duncan Coutts at 2026-11-18T16:20:55+00:00
Don't consider pending I/O for early context switch optimisation
Context switches are normally initiated by the timer signal. If however
the user specifies "context switch as often as possible", with +RTS -C0
then the scheduler arranges for an early context switch (when it's just
about to run a Haskell thread).
Context switching very often is expensive, so as an optimisation there
cases where we do not arrange an early context switch:
1. if there's no other threads to run
2. if there is no pending I/O or timers
This patch eliminates case 2, leaving only case 1.
The rationale is as follows. The use of this was inconsistent across
platforms and threaded/non-threaded RTS ways. It only worked on the
non-threaded RTS and on Windows only worked for the win32-legacy I/O
manager. On all other combinations anyPendingTimeoutsOrIO would always
return false. The fact that nobody noticed and complained about this
inconsistency suggests that the feature is not relied upon.
If however it turns out that applications do rely on this, then the
proper thing to do is not to restore this check, but to add a new I/O
manager hint function that returns if there is any pending events that
are likely to happen *soon*: for example timeouts expiring within one
timeslice, or I/O waits on things likely to complete soon like disk I/O,
but not for example socket/pipe I/O.
The motivation to avoid this use of anyPendingTimeoutsOrIO is to
allow us to eliminate anyPendingTimeoutsOrIO entirely. All other uses
of this are just guards on {await,poll}CompletedTimeoutsOrIO and
the guards can safely be folded into those functions. This will better
cope with some I/O managers having no proper implementation of
anyPendingTimeoutsOrIO.
Ultimately this will let us simplify the scheduler which currently has
to have special #ifdef mingw32_HOST_OS cases to cope with the lack of a
working anyPendingTimeoutsOrIO for some Windows I/O managers
- - - - -
6bcfd2f3 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Remove anyPendingTimeoutsOrIO guarding {poll,await}CompletedTimeoutsOrIO
Previously the API of the I/O manager used a two step process: check
anyPendingTimeoutsOrIO and then call {poll,await}CompletedTimeoutsOrIO.
This was primarily there as a performance thing, to cheaply check if we
need to do anything.
And then because anyPendingTimeoutsOrIO existed, it was used for other
things too. We have now eliminated the other uses, and are just left
with the performance pattern.
But this was problematic because not all I/O managers correctly
implement anyPendingTimeoutsOrIO (specifically the win32 ones), and now
that we also make I/O managers responsible for signals then we need to
poll/await even if there is no pending I/O or timeouts. If there is no
pending I/O or timeouts then await needs to degenerate to just waiting
forever for any signals.
- - - - -
576ca3f0 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Remove anyPendingTimeoutsOrIO, it is no longer used
And this avoids the problems arising from the win32 I/O managers having
had a bogus implementation.
- - - - -
f7ebd534 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Remove second scheduler call to awaitCompletedTimeoutsOrIO
Previously awaitCompletedTimeoutsOrIO was called both before and after
deadlock detection in the scheduler. The reason for that was that the
win32 I/O managers had a bogus implementation of anyPendingTimeoutsOrIO
and this was used to guard the call of awaitCompletedTimeoutsOrIO prior
to deadlock detection. This meant the first call site was never actually
called when using the win32 I/O managers. This was the reason for the
second call: the first one was never used. What a mess.
So now we have a simple design in the scheduler:
1. poll for completed I/O, timers or signals
2. if no runnable threads: do deadlock detection
3. if still no runnable threads: block waiting for I/O, timers or
signals.
- - - - -
6a8304ed by Duncan Coutts at 2026-11-18T16:20:55+00:00
Lift emptyRunQueue guard out of scheduleDetectDeadlock
this improved the clarity of the logic when reading the scheduler code.
And improve the comment about scheduleDoGC that was rather unclear.
- - - - -
d6401467 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Make interruptIOManager work for WinIO (non-threaded)
Fixes #27403
The idle GC scheme now fundamentally relies on interruptIOManager
working, so it's no longer acceptable for it to be missing for WinIO.
Not having it would cause lock ups.
- - - - -
39aa6207 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Make non-threaded deadlock detection also rely on idle GC
Only do deadlock detection GC when idle GC kicks in. This also relies on
using wakeUpRts, so now do this unconditionally. Previously wakeUpRts
was for the threaded rts only.
- - - - -
8730e064 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Enable idle GC by default on non-threaded RTS
The behaviour is now uniform between the threaded and non-threaded RTS
ways. The deadlock detection now relies on idle GC for both threaded
and non-threaded ways. Previously deadlock detection did not rely on
idle GC for the non-threaded way.
Also tweak test T7275 to account for idle GC. This test's output is
sensitive to the number of major GCs run. Since this commit enables idle
GC for the non-threaded RTS, for this test that increases the number of
major GCs, since the test program is frequently idle for more than 300ms.
- - - - -
01a656af by Duncan Coutts at 2026-11-18T16:20:55+00:00
Fix state of idle GC control vars with +RTS -V0
Currently when the user uses +RTS -I0, then doIdleGC is set to false.
But if the master tick interval -V is set to 0 then the idleGCDelayTime
was being set to 0 but doIdleGC was not being set to false, which is
inconsistent, and almost certainly buggy.
- - - - -
197de453 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Add a long Note [Deadlock detection]
It describes the historical and modern designs and their trade-offs.
The point is we've now unified the code for deadlock detection between
the threaded and non-threaded ways, by changing the non-threaded to
follow the same design as the threaded.
- - - - -
f76913f5 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Refactor the utils providing the I/O timeout for different system APIs
We have to provide a timeout in three different time formats (int
milliseconds, struct timeval *, and struct timespec *). These are for
platform APIs including poll, select, ppoll, pselect, epoll_wait,
epoll_wait2 and in future kevent and io_uring.
Previously we had one util for each format that both worked out what
the timeout should be and converted it into the particular format. This
duplicates some logic and it also makes it awkward to modify the timeout
value (since there's no common format).
Modifying the timeout value is exactly what we want to do, in a
subsequent commit, where we want to adjust the timeout to take account
of idle GC.
- - - - -
674dc8db by Duncan Coutts at 2026-11-18T16:20:55+00:00
Update the old select I/O manager to use the new timeout utils
This will make it much easier to adjust the timeout to take account of
idle GC.
- - - - -
7d42fa77 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Add opportunistic deadlock detection without idle GC
Our general design is now that comprehensive deadlock detection relies
on idle GC. This allows us to detect partial deadlocks that are not
system deadlocks. But it's not prompt.
It's a nice to have feature to be able to promptly detect the cases that
are system deadlocks. There's no hope to do this in the threaded RTS
with -N > 1, but it can be done for the non-threaded RTS and _could_ be
done for the threaded RTS with -N1.
We can integrate this feature into the general design without too many
contortions. We just need the I/O managers to check before sleeping if
they would be about to sleep indefinately with no I/O and no registered
signal handlers. If so, they can notify the idle GC that we're
deadlocked and we schedule and idle GC.
- - - - -
8800dbc0 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Add idle GC mode for !HAVE_PREEMPTION
We have to do idle GC (and thus deadlock detection) differently when we
do not have the ticker and the ability to interrupt the I/O manager
when it's blocking.
- - - - -
e107cb85 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Add and use USED_IF_PREEMPTION to avoid warnings
- - - - -
c933a512 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Add performDeadlockDetection and export via ghc-experimental
When documenting the idle GC and deadlock detection behaviour in the
user guide, it becomes obiovus that in some cases one would want manual
control over deadlock detection.
In particular, for applications that disable idle GC, for debugging or
robustness, they may want to invoke deadlock detecting GC manually.
Bind it in ghc-internal GHC.Internal.System.Mem and re-export via
ghc-experimental in System.Mem.Experimental. It is clearly
implementation specific behaviour, especially since in GHC the deadlock
detection is tied to doing a major GC.
- - - - -
1052e38e by Duncan Coutts at 2026-11-18T16:20:55+00:00
Add tests for deadlock detection, issue #26408
We have three tests:
T26408a: make sure that we can detect a /partial deadlock/ that is not
also a /system deadlock/
T26408b: make sure that we can detect a /system deadlock/ promptly
without relying on idle GC
T26408c: make sure that we do not falsely detect a deadlock when there is
nothing to do except wait on signals
T26408d: make sure that we can detect a system deadlock with idle GC
disabled, after the idle GC timeout has elapsed.
- - - - -
583cda03 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Update the user guide with the revised idle GC behaviour
It's now not just for the threaded RTS, but general.
Add a new section in the RTS chapter: Idle GC and deadlock detection.
Provide general documentation on both topics. In particular, document
the behaviour of deadlock detection and how it depends on idle GC.
Move the existing entries for -I and -Iw to this section.
Add a changelog entry.
- - - - -
3a2e7e81 by Duncan Coutts at 2026-11-18T16:20:55+00:00
Remove variable n_haskell_handlers which has become write-only
- - - - -
6fd20c15 by Sylvain Henry at 2026-11-19T11:50:28-05:00
NCG: List each destination of a jump table once
jumpDestsOfInstr listed a block once per jump table entry that named
it. The linear register allocator makes a fixup block per listed
destination, so such a block got several fixup blocks. The patch of
the jump sends every entry to the first one. The other fixup blocks
were dead code, and the CFG had an edge to each of them.
jumpDestsOfInstr now lists each destination once, in every backend.
joinToTargets asserts it in debug builds.
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
9eec9858 by Andreas Klebinger at 2026-11-19T11:50:29-05:00
x86 ncg: Track the current block in NatM to keep the CFG in sync
The x86 NCG uses a CFG for code layout. When instruction selection
makes new blocks (word2Float#, cmpxchg loops, 64-bit shifts on i386),
it must add them to the CFG. Some sites did not. The CFG went out of
sync, the layout was bad, and the register allocator panicked when it
added fixup blocks (#27694, #27915).
NatM now keeps the current block in its state. Combinators update the
CFG and the current block together. See Note [Updating the CFG during
CodeGen] in GHC.CmmToAsm.Monad.
Other changes:
* -dasm-lint checks that the jumps in the code and the edges in the
CFG agree in both directions. This found a second desync: the CFG
did not follow the jumps that allocMoreStack retargets. The new
addPreentryBlock fixes it.
* The code must be emitted in generation order, because the CFG
records new blocks in that order. A store now generates the code of
its value before the code of its address, in the order it emits
them. Atomic operations take their address from the new
getNonClobberedAmode, so the code of their other operands cannot
clobber it.
Fixes #27694, #27915
Co-authored-by: Sylvain Henry <sylvain(a)haskus.fr>
Co-Authored-By: Claude Fable 5.1 <noreply(a)anthropic.com>
- - - - -
c3eaa1b3 by Sylvain Henry at 2026-11-19T11:50:29-05:00
x86 ncg: Maintain the CFG on i386
The i386 NCG now keeps its CFG in sync with the code (see the previous
commit), so backendMaintainsCfg is now True for i386. i386 gets the
CFG based code layout, dead code elimination and the -dasm-lint check,
like x86-64.
The compiler allocates more on i386: the CFG now goes through the
register allocator, branch shortcutting and optimizeCFG, which i386
skipped before. x86-64 already does this work.
Metric Increase:
CoOpt_Read
ManyAlternatives
T10421
T12425
T12707
T13056
T13253
T13253-spj
T13960
T15164
T15304
T15630
T15630a
T15703
T16577
T17516
T17836
T18140
T18282
T18304
T18698a
T18698b
T18730
T18923
T19695
T20049
T21839c
T24471
T26425
T26989
T5642
T6048
T783
T9233
T9630
Co-Authored-By: Claude Opus 5.5 <noreply(a)anthropic.com>
- - - - -
432bfca2 by Ryan Scott at 2026-11-19T11:50:30-05:00
GHC.HsToCore.Quote: Quote \cases with the correct type
Previously, `\cases` expressions inside of Template Haskell quotes would
incorrectly use the `Match` type instead of `Clause` for the element type. We
now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type
automatically. This works because `\cases` has an invariant that the list of
clauses is always non-empty.
Fixes #27826.
- - - - -
b442cb0a by Hannes Siebenhandl at 2026-11-19T11:50:32-05:00
Use Set operations over Foldable operations
Use `O(log n)` operations over `O(n)` for all call-sites of `hsc_all_home_unit_ids`.
- - - - -
e95abc24 by Alan Zimmerman at 2026-11-19T11:50:33-05:00
EPA: Use AnnList in DecBrl
Via updating the TTG extension point payload
- - - - -
f428dec1 by David Eichmann at 2026-11-19T11:50:35-05:00
Fix race condition in IOManager test
- - - - -
c1c8e388 by mangoiv at 2026-11-19T11:50:35-05:00
ci: nightly push can run on any arch
- - - - -
88 changed files:
- .gitlab-ci.yml
- + changelog.d/27694
- + changelog.d/idle-gc-and-deadlock-detection
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/CmmToAsm/BlockLayout.hs
- compiler/GHC/CmmToAsm/CFG.hs
- compiler/GHC/CmmToAsm/Instr.hs
- compiler/GHC/CmmToAsm/LA64/Instr.hs
- compiler/GHC/CmmToAsm/Monad.hs
- compiler/GHC/CmmToAsm/PPC/Instr.hs
- compiler/GHC/CmmToAsm/RV64/Instr.hs
- compiler/GHC/CmmToAsm/Reg/Linear/JoinToTargets.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/Parser.y
- + distrib/configure.ac
- docs/users_guide/profiling.rst
- docs/users_guide/runtime_control.rst
- libraries/ghc-experimental/src/System/Mem/Experimental.hs
- libraries/ghc-internal/src/GHC/Internal/System/Mem.hs
- rts/Capability.c
- rts/IOManager.c
- rts/IOManager.h
- + rts/IdleGC.c
- + rts/IdleGC.h
- rts/Linker.c
- rts/RtsFlags.c
- rts/RtsSignals.h
- rts/RtsStartup.c
- rts/RtsSymbols.c
- rts/Schedule.c
- rts/Schedule.h
- rts/Timer.c
- rts/include/rts/OSThreads.h
- rts/include/rts/storage/GC.h
- rts/posix/Poll.c
- rts/posix/Poll.h
- rts/posix/Select.c
- rts/posix/SelectBis.c
- rts/posix/SelectBis.h
- rts/posix/Signals.c
- − rts/posix/Signals.h
- rts/posix/Timeout.c
- rts/posix/Timeout.h
- rts/rts.cabal
- rts/win32/AsyncMIO.c
- rts/win32/AsyncMIO.h
- rts/win32/AsyncWinIO.c
- rts/win32/AsyncWinIO.h
- rts/win32/AwaitEvent.c
- rts/win32/ConsoleHandler.c
- rts/win32/ConsoleHandler.h
- + testsuite/tests/codeGen/should_compile/T27694.hs
- + testsuite/tests/codeGen/should_compile/T27694c.hs
- + testsuite/tests/codeGen/should_compile/T27694d.hs
- testsuite/tests/codeGen/should_compile/all.T
- + testsuite/tests/codeGen/should_run/T27694b.hs
- + testsuite/tests/codeGen/should_run/T27694b.stdout
- + testsuite/tests/codeGen/should_run/T27915.hs
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-32
- + testsuite/tests/codeGen/should_run/T27915.stdout-ws-64
- testsuite/tests/codeGen/should_run/all.T
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- testsuite/tests/profiling/should_run/Makefile
- testsuite/tests/rts/IOManager.hsc
- testsuite/tests/rts/Makefile
- + testsuite/tests/rts/T26408a.hs
- + testsuite/tests/rts/T26408a.stderr
- + testsuite/tests/rts/T26408b.hs
- + testsuite/tests/rts/T26408b.stderr
- + testsuite/tests/rts/T26408c.hs
- + testsuite/tests/rts/T26408c.stdout
- + testsuite/tests/rts/T26408d.hs
- + testsuite/tests/rts/T26408d.stderr
- testsuite/tests/rts/all.T
- testsuite/tests/rts/symbols/rts-check-symbols.stdout
- + testsuite/tests/th/T27826.hs
- testsuite/tests/th/all.T
- utils/check-exact/ExactPrint.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7f6db9334fee8b8a8cc10871a15780…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/7f6db9334fee8b8a8cc10871a15780…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0