Simon Peyton Jones pushed to branch wip/T28169 at Glasgow Haskell Compiler / GHC Commits: 666b92a6 by Simon Peyton Jones at 2026-11-29T22:53:46+00:00 Fix evaluated-ness bug in Simplifier (#26548) `adjustFieldsIdInfo` decided whether to attach evaluated-ness to the pattern-bound variables of a case alternative by testing whether the data constructor has a wrapper (`dataConWrapId_maybe`). But a constructor can have strict fields and yet no wrapper, so we failed to mark its strict fields as evaluated. Main change: * Drive `addFieldsIdInfo` from the strictness signature its worker. Fixing this gives many more variables an OtherCon [] unfolding, which disturbs the inlining heuristics. So also: * `interestingArg` returns TrivArg (rather than NonTrivArg) for an argument with an OtherCon [] unfolding: knowing only that an argument is evaluated rarely makes inlining worthwhile (e.g. maMB in T18140). See (IA2) in Note [Interesting arguments]. * `interestingCallContext` treats a StrictBind continuation as RhsCtxt NonRecursive rather than BoringCtxt. * A lambda argument remains a `ValueArg`; new (IA5) in Note [Interesting arguments] explains why, and discusses T17516. * In some benchmarks (notably T9233) `addFieldsIdInfo` seems to be quite a hot path, so I optimised it a bit: (a) build the result list strictly; it is consumed in full right away (b) update each field binder's IdInfo at most once, rather than once for evaluated-ness and once more for occ-info (c) leave alone a field binder that is dead and will stay dead I factored out `fieldOccInfoStable`; and make the `seq#` case simpler too. New test T26548. T26615.stderr is regenerated (only its fEqList lines are checked). Authored with help from Claude. - - - - - 9 changed files: - compiler/GHC/Core/Opt/Simplify/Inline.hs - compiler/GHC/Core/Opt/Simplify/Iteration.hs - compiler/GHC/Core/Opt/Simplify/Utils.hs - compiler/GHC/Types/Demand.hs - libraries/ghc-internal/src/GHC/Internal/IO.hs - + testsuite/tests/simplCore/should_compile/T26548.hs - + testsuite/tests/simplCore/should_compile/T26548.stderr - testsuite/tests/simplCore/should_compile/T26615.stderr - testsuite/tests/simplCore/should_compile/all.T Changes: ===================================== compiler/GHC/Core/Opt/Simplify/Inline.hs ===================================== @@ -385,7 +385,7 @@ tryUnfolding env logger id lone_variable arg_infos -- be *something* interesting about some argument, or the -- result context, to make it worth inlining calc_some_benefit :: Arity -> Bool -> Bool -- The Arity is the number of args - -- expected by the unfolding + -- expected by the unfolding calc_some_benefit uf_arity is_inline | not saturated = interesting_args -- Under-saturated -- Note [Unsaturated applications] ===================================== compiler/GHC/Core/Opt/Simplify/Iteration.hs ===================================== @@ -3557,7 +3557,8 @@ life" in one of two ways: Thus, when we are simply reconstructing a case (the common case), and the case binder is not dead, or the scrutinee is a variable, we zap the -occurrence info on DataAlt field binders. See `adjustFieldOccInfo`. +occurrence info on DataAlt field binders. See `fieldOccInfoStable` +and `adjustFieldsIdInfo`. Note [Improving seq] ~~~~~~~~~~~~~~~~~~~~ @@ -3765,70 +3766,90 @@ do it here). The right thing is to do some kind of binder-swap; see #15226 for discussion. -} -adjustFieldsIdInfo :: Maybe OutExpr -> OutId -> BinderSwapDecision -> DataCon -> [Id] -> [Id] +adjustFieldsIdInfo :: Maybe OutExpr -> OutId -> BinderSwapDecision + -> DataCon -> [InBndr] -> [InBndr] -- See Note [Adding evaluatedness info to pattern-bound variables] -- and Note [DataAlt occ info] +-- +-- This can be a hot path in the compiler (e.g. T9233 which has a large strict record) +-- Hence +-- (a) we build the result list strictly: it is consumed in full right away, +-- so thunks for the elements or the spine are pure waste +-- (b) we update each field binder's IdInfo at most once +-- (c) we leave alone a field binder that is dead and will stay dead +-- (see `fieldOccInfoStable`); its evaluated-ness is irrelevant adjustFieldsIdInfo scrut case_bndr bndr_swap con vs + -- Deal with seq# applications + -- See (SEQ3) in Note [seq# magic] in GHC.Types.Id.Make + -- case (seq# a b) of (# _, x' #) -> .... + -- we can mark x' as evaluated | Just scr <- scrut , isUnboxedTupleDataCon con - , [s,x] <- vs -- Use stripNArgs rather than collectArgsTicks to avoid building -- a list of arguments only to throw it away immediately. , Just (Var f) <- stripNArgs 4 scr , f `hasKey` seqHashKey - , let x' = setCaseBndrEvald MarkedStrict x - = map (adjustFieldOccInfo case_bndr bndr_swap) [s, x'] - - -- Deal with banged datacon fields - -- This case is quite allocation sensitive to T9233 which has a large record - -- with strict fields. Hence we try not to update vs twice! -adjustFieldsIdInfo _scrut case_bndr bndr_swap con vs - | Nothing <- dataConWrapId_maybe con - -- A common fast path; no need to allocate the_strs when they are all lazy - -- anyway! It shaves off 2% in T9675 - = map (adjustFieldOccInfo case_bndr bndr_swap) vs + = go vs [topDmd, evalDmd] -- seq# returns an evaluated x + + -- We could have a short-cut for when occ_stable is True (uncommon), + -- and the data construtor has no bangs (common) + -- General case | otherwise = go vs wkr_dmds where -- The demand signature of the worker has a strict demand for exactly the - -- strict (banged) fields; one demand for each value argument, including + -- strict (banged) fields; one demand for each value argument, /including/ -- existential CoVars. See GHC.Types.Id.Make.mkDataConWorkId. - -- NB: we do /not/ mark an unlifted field as evaluated: that gains nothing, - -- and an OtherCon[] unfolding makes `interestingArg` say NonTrivArg, - -- which changes inlining decisions (we saw this in compiler/perf/T19695). + -- + -- An /unlifted/ field has a lazy demand, and hence won't be marked as + -- evaluated: doing so gains nothing. This doesn't matter much, if at all; + -- in the past OtherCon[] have affected inlining decision, but not now + -- since `interestingArg` says `TrivArg` for OtherCon[]. + -- (compiler/perf/T19695 is an example of this delicacy) + -- + -- We could use `dataConRepArgCbvInfos`, but that has ArgCbv for unlifted DmdSig (DmdType _ wkr_dmds) = idDmdSig (dataConWorkId con) - - go [] [] = [] - go (v:vs') dmds | isTyVar v = v : go vs' dmds - go (v:vs') (dmd:dmds) = adjustFieldOccInfo case_bndr bndr_swap (set_evald dmd v) : go vs' dmds - go _ _ = pprPanic "Simplify.adjustFieldsIdInfo" - (ppr con $$ - ppr vs $$ - ppr_with_length wkr_dmds $$ - ppr_with_length (dataConRepArgTys con)) - where - ppr_with_length list - = ppr list <+> parens (text "length =" <+> ppr (length list)) - - set_evald dmd v | isStrDataConDmd dmd = setCaseBndrEvald MarkedStrict v - | otherwise = v - -adjustFieldOccInfo :: OutId -> BinderSwapDecision -> CoreBndr -> CoreBndr --- Kill occ info if we do binder swap and the case binder is alive; --- see Note [DataAlt occ info] -adjustFieldOccInfo case_bndr bndr_swap field_bndr - | isTyVar field_bndr - = field_bndr - - | not (isDeadBinder case_bndr) -- (1) in the Note: If the case binder is alive, - = zapIdOccInfo field_bndr -- the field binders might come back alive - - | DoBinderSwap{} <- bndr_swap -- (2) in the Note: If binder swap might take place, - = zapIdOccInfo field_bndr -- the case binder might come back alive - - | otherwise - = field_bndr -- otherwise the field binders stay dead + occ_stable = fieldOccInfoStable case_bndr bndr_swap + + go :: [Var] -> [Demand] -> [Var] + -- This loop works strictly because the result is always consumed strictly + go (v:vs') dmds + | isTyVar v = let !vs'' = go vs' dmds in v : vs'' + | (d:ds') <- dmds = let !v' = adjust d v + !vs'' = go vs' ds' + in v' : vs'' + go [] [] = [] + go vs' ds = pprPanic "Simplify.adjustFieldsIdInfo" (ppr con $$ ppr vs $$ ppr vs' $$ ppr ds) + + -- Set evaluated-ness (if dmd is strict) and zap occ-info + -- (if not occ_stable), with at most one IdInfo update + adjust :: Demand -> Id -> Id + adjust dmd v + = case isStrDataConDmd dmd of + True | occ_stable -> if isDeadBinder v then nop v else set_evald v + | otherwise -> set_evald_zap_occ v + False | occ_stable -> nop v + | otherwise -> zap_occ v + + -- The four different possibilities; each modifies the IdInfo once + nop v = v + set_evald v = v `setIdUnfolding` evaldUnfolding + zap_occ v = zapIdOccInfo v + set_evald_zap_occ v = modifyIdInfo (\info -> info `setUnfoldingInfo` evaldUnfolding + `setOccInfo` noOccInfo) v + +fieldOccInfoStable :: OutId -> BinderSwapDecision -> Bool +-- True <=> the occ-info on the field binders of a DataAlt remains valid; +-- in particular a dead field binder will stay dead. +-- False <=> we must zap the field binders' occ-info. +-- See Note [DataAlt occ info] +fieldOccInfoStable case_bndr bndr_swap + | not (isDeadBinder case_bndr) = False -- (1) in the Note: If the case binder is alive, + -- the field binders might come back alive + | DoBinderSwap{} <- bndr_swap = False -- (2) in the Note: If binder swap might take place, + -- the case binder might come back alive + | otherwise = True -- Otherwise the field binders stay dead addDefaultUnfoldings :: SimplEnv -> OutId -> BinderSwapDecision -> [AltCon] -> SimplEnv addDefaultUnfoldings env case_bndr bndr_swap imposs_deflt_cons ===================================== compiler/GHC/Core/Opt/Simplify/Utils.hs ===================================== @@ -1123,7 +1123,7 @@ interestingCallContext env cont -- in GHC.Core.Unfold interesting (StrictArg { sc_fun = fun }) = strictArgContext fun - interesting (StrictBind {}) = BoringCtxt + interesting (StrictBind {}) = RhsCtxt NonRecursive interesting (Stop _ cci _) = cci interesting (TickIt _ k) = interesting k interesting (ApplyToTy { sc_cont = k }) = interesting k @@ -1208,13 +1208,21 @@ Wrinkles: (IA2) OtherCon. interestingArg returns - (a) NonTrivArg for an arg with an OtherCon [] unfolding + (a) TrivArg for an arg with an OtherCon [] unfolding (b) ValueArg for an arg with an OtherCon [c1,c2..] unfolding. - Reason for (a): I found (in the GHC.Internal.Bignum.Integer module) that I was - inlining a pretty big function when all we knew was that its arguments - were evaluated, nothing more. That in turn make the enclosing function - too big to inline elsewhere. + Reason for (a): knowing only that an argument is evaluated, but not which + constructor it is, rarely makes inlining worthwhile. For example, in test + T18140 we have + data D = D !(Maybe Bool) ... !(Maybe Bool) + maMB :: Maybe Bool -> Maybe Bool -> Maybe Bool + maD (D x1 ... x18) (D y1 ... y18) = D (maMB x1 y1) ... (maMB x18 y18) + The xi and yi come from strict fields, so they have OtherCon [] unfoldings. + If that made them interesting we would inline maMB 18 times, to no benefit, + just bloating maD. (Similarly, in GHC.Internal.Bignum.Integer I found that + I was inlining a pretty big function when all we knew was that its + arguments were evaluated. That in turn made the enclosing function too big + to inline elsewhere.) But this choice is delicate. Sometimes inlining a tiny function applied to an evaluated argument /is/ very beneficial, because the /result/ is @@ -1255,6 +1263,25 @@ Wrinkles: Conclusion: `interestingArg` should give some encouragement (NonTrivArg) to `f` when the argument is expandable. Hence `uf_expandable` in the `Var` case. +(IA5) We are keen to inline a higher-order function applied to lambda, e.g. + f (\x. blah) + where + f h = ...(h xs)... + Doing so specialises `f` to the particular argument which can make a + big difference. Note, however, that we don't want to be defeated if + the lambda is let-bound: + let h = (\x.blah) + in ...f h... + So we need to look through h's unfolding. + + This makes parser combinators, which are usually applied to functions, + rather keen to inline, so whether they do so is mostly decided by their + size. Test T17516 is a delicate example: if `max` on positions inlines + into the combinators in T17516A, the combinators are too big to inline into + the client module T17516; if not (because max's arguments are merely + evaluated, see (IA2)), they are small and do inline, making T17516 itself + slower to compile. But inlining makes the code better too, with fewer + unknown calls. -} interestingArg :: SimplEnv -> StaticEnv -> CoreExpr -> ArgSummary @@ -1283,7 +1310,7 @@ interestingArg env se e go env n (Lam v e) | isTyVar v = go env n e | n>0 = NonTrivArg -- (\x.b) e is NonTriv - | otherwise = ValueArg + | otherwise = ValueArg -- (\x.b) is Value: see (IA5) go _ _ (Case {}) = NonTrivArg go env n (Let b e) = case go env' n e of ValueArg -> ValueArg @@ -1293,17 +1320,16 @@ interestingArg env se e go_var n v | isConLikeId v = ValueArg -- Experimenting with 'conlike' rather that - -- data constructors here - -- DFuns are con-like; + -- data constructors here (includes DFuns) -- see (IA1) in Note [Interesting arguments] - | idArity v > n = ValueArg -- Catches (eg) primops with arity but no unfolding + | idArity v > n = ValueArg -- See (IA5) in Note [Interesting arguments] | n > 0 = NonTrivArg -- Saturated or unknown call | otherwise -- n==0, no value arguments; look for an interesting unfolding = case idUnfolding v of - OtherCon [] -> NonTrivArg -- It's evaluated, but that's all we know + OtherCon [] -> TrivArg -- It's evaluated, but that's all we know OtherCon _ -> ValueArg -- Evaluated and we know it isn't these constructors - -- See (IA2) in Note [Interesting arguments] - DFunUnfolding {} -> ValueArg -- We konw that idArity=0 + -- See (IA2) in Note [Interesting arguments] + DFunUnfolding {} -> ValueArg -- We know that idArity=0 CoreUnfolding{ uf_cache = cache } | uf_is_conlike cache -> ValueArg -- Includes constructor applications | uf_expandable cache -> NonTrivArg -- See (IA4) ===================================== compiler/GHC/Types/Demand.hs ===================================== @@ -1003,9 +1003,10 @@ isStrUsedDmd :: Demand -> Bool isStrUsedDmd (n :* _) = isStrict n && not (isAbs n) -- | Is this demand, taken from the demand signature of a data constructor --- /worker/, the demand for a strict field? The demands in a worker's --- signature are never absent (see GHC.Types.Id.Make.mkDataConWorkId), so --- unlike 'isStrUsedDmd' we don't need to check for absence. +-- /worker/, the demand for a strict field? It would be more obviously correct +-- to use isStrUsedDmd, in case the dmd is Absent. But data constructor workers +-- never have absent arguments, and isStrictDmd is more efficient. +-- See GHC.Types.Id.Make.mkDataConWorkId. isStrDataConDmd :: Demand -> Bool isStrDataConDmd = isStrictDmd @@ -1475,23 +1476,21 @@ arguments. That is the job of dmdTransformDataConSig. More precisely, * it returns the demands on the arguments; in the above example that is [SL, A] -When the data constructor worker has strict fields, an additional seq -will be inserted for each field (see (SFC3) in Note [Strict fields in Core]). -Hence we add an additional `seqDmd` for each strict field to emulate -field eval insertion. We find the strict fields from the demand signature -of the worker (built by GHC.Types.Id.Make.mkDataConWorkId), which has a -strict demand for exactly the strict fields (bangs). - -NB: we must /not/ add a `seqDmd` for a field that is lazy but has an unlifted -type: such an argument is evaluated before the call, not by the constructor, -and adding `seqDmd` would turn an absent field into a used one, defeating -absent-argument worker/wrapper (e.g. test T25177). - -For example, consider `data SP a b = MkSP !a !b` and expression `MkSP x y`, -with the same sub-demand P(SL,A). -The strict fields bump up the strictness; we'd get [SL,1!A] for the field -demands. Note that the first demand was unaffected by the seq, whereas -the second, previously absent demand became `seqDmd` exactly. +(DTC1) When the data constructor worker has strict fields, an additional seq will + be inserted for each field (see (SFC3) in Note [Strict fields in Core]). Hence + we add an additional `seqDmd` for each strict field to emulate field eval + insertion. We find the strict fields from the demand signature of the worker + (built by GHC.Types.Id.Make.mkDataConWorkId), which has a strict demand for + exactly the strict fields (bangs). + + For example, consider `data SP a b = MkSP !a !b` and expression `MkSP x y`, with + the same sub-demand P(SL,A). The strict fields bump up the strictness; we'd get + [SL,1!A] for the field demands. Note that the first demand was unaffected by the + seq, whereas the second, previously absent demand became `seqDmd` exactly. + +(DTC2) An additional `seq` will /not/ be inserted for an unlifted field, so we must + correspondingly not add a `seqDmd` for them. Adding `seqDmd` would turn an absent + field into a used one, defeating absent-argument worker/wrapper (e.g. test T25177). -} {- ********************************************************************* @@ -2530,11 +2529,13 @@ dmdTransformDataConSig (DmdSig (DmdType _ sig_dmds)) sd arity = length sig_dmds (n, body_sd) = peelManyCalls arity sd mk_body_ty n dmds = DmdType nopDmdEnv (zipWith (bump n) sig_dmds dmds) + + -- See (DTC1) in Note [Demand transformer for data constructors] + -- NB (DTC2): isStrDataConDmd is false for unlifted fields; + -- it is true only for fields with strictness annotations. bump n sig_dmd dmd - | isStrDataConDmd sig_dmd = multDmd n (plusDmd str_field_dmd dmd) -- A strict field + | isStrDataConDmd sig_dmd = multDmd n (plusDmd seqDmd dmd) | otherwise = multDmd n dmd - str_field_dmd = seqDmd -- See the bit about strict fields - -- in Note [Demand transformer for data constructors] -- | A special 'DmdTransformer' for dictionary selectors that feeds the demand -- on the result into the indicated dictionary component (if saturated). ===================================== libraries/ghc-internal/src/GHC/Internal/IO.hs ===================================== @@ -483,7 +483,7 @@ a `finally` sequel = -- | The primitive used to implement 'GHC.IO.evaluate'. -- Prefer to use 'GHC.IO.evaluate' whenever possible! seq# :: forall a s. a -> State# s -> (# State# s, a #) --- See Note [seq# magic] in GHC.Types.Id.Make +-- See Note [seq# magic] in GHC.Builtin.WiredIn.Ids {-# NOINLINE seq# #-} -- seq# is inlined manually in CorePrep seq# a s = let !a' = lazy a in (# s, a' #) ===================================== testsuite/tests/simplCore/should_compile/T26548.hs ===================================== @@ -0,0 +1,7 @@ +module T26548 where + +newtype N a = MkN (Maybe a) +data T = MkT !(N Int) !(N Bool) + +f x = case x of { MkT a b -> + case x of { MkT c d -> MkT a d } } ===================================== testsuite/tests/simplCore/should_compile/T26548.stderr ===================================== @@ -0,0 +1,19 @@ + +==================== Tidy Core ==================== +Result size of Tidy Core + = {terms: 3, types: 3, coercions: 0, joins: 0/0} + +-- RHS size: {terms: 2, types: 1, coercions: 0, joins: 0/0} +f :: T -> T +[GblId, + Arity=1, + Str=<1!P(L,L)>, + Cpr=1, + Unf=Unf{Src=StableSystem, TopLvl=True, + Value=True, ConLike=True, WorkFree=True, Expandable=True, + Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=True) + Tmpl= \ (x [Occ=Once1] :: T) -> x}] +f = \ (x :: T) -> x + + + ===================================== testsuite/tests/simplCore/should_compile/T26615.stderr ===================================== @@ -2,7 +2,7 @@ ==================== Tidy Core ==================== Result size of Tidy Core - = {terms: 1,229, types: 1,163, coercions: 18, joins: 17/29} + = {terms: 1,220, types: 1,160, coercions: 18, joins: 17/29} -- RHS size: {terms: 6, types: 8, coercions: 0, joins: 0/0} unArray :: forall a. Array a -> SmallArray# a @@ -107,7 +107,7 @@ T26615a.$tcLeaf T26615a.$trModule $tcLeaf2 0# - GHC.Internal.Types.krep$*->*->* + krepStarArrStarArr -- RHS size: {terms: 3, types: 2, coercions: 0, joins: 0/0} $krep7 :: [GHC.Internal.Types.KindRep] @@ -181,7 +181,7 @@ T26615a.$tcArray T26615a.$trModule $tcArray2 0# - GHC.Internal.Types.krep$*Arr* + krepStarArr -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} $krep12 :: GHC.Internal.Types.KindRep @@ -251,7 +251,7 @@ T26615a.$tcHashMap T26615a.$trModule $tcHashMap2 0# - GHC.Internal.Types.krep$*->*->* + krepStarArrStarArr -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} $krep16 :: GHC.Internal.Types.KindRep @@ -612,7 +612,7 @@ lvl1 = GHC.Internal.Control.Exception.Base.patError @LiftedRep @() lvl Rec { --- RHS size: {terms: 136, types: 130, coercions: 0, joins: 1/2} +-- RHS size: {terms: 133, types: 129, coercions: 0, joins: 1/2} T26615a.disjointSubtrees_$s$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] :: forall k a b. @@ -635,7 +635,6 @@ T26615a.disjointSubtrees_$s$wdisjointSubtrees Empty -> GHC.Internal.Types.True; Leaf bx ds -> case ds of { L kB ds1 -> - case kB of k0 { __DEFAULT -> case eqWord# bx sc2 of { __DEFAULT -> GHC.Internal.Types.True; 1# -> @@ -668,8 +667,7 @@ T26615a.disjointSubtrees_$s$wdisjointSubtrees } }; } in jump $wlookupInArrayCont_ - sc k0 sc3 0# (sizeofSmallArray# @Lifted @(Leaf k a) sc3) - } + sc kB sc3 0# (sizeofSmallArray# @Lifted @(Leaf k a) sc3) } }; Collision bx bx1 -> @@ -710,7 +708,7 @@ T26615a.disjointSubtrees_$s$wdisjointSubtrees end Rec } Rec { --- RHS size: {terms: 719, types: 748, coercions: 18, joins: 13/23} +-- RHS size: {terms: 713, types: 746, coercions: 18, joins: 13/23} T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] :: forall k a b. Eq k => Int# -> HashMap k a -> HashMap k b -> Bool [GblId[StrictWorker([~, ~, !])], @@ -740,7 +738,6 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] Empty -> GHC.Internal.Types.True; Leaf bx [Occ=Once1] ds2 [Occ=Once1!] -> case ds2 of { L kB [Occ=Once1] _ [Occ=Dead] -> - case kB of k0 [Occ=Once1] { __DEFAULT -> joinrec { lookupCont_ [Occ=LoopBreakerT[5]] :: Eq k => Word -> k -> Int -> HashMap k a -> Bool @@ -868,8 +865,7 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] } }; } in jump lookupCont_ - $dEq (GHC.Internal.Types.W# bx) k0 (GHC.Internal.Types.I# ww) ds - } + $dEq (GHC.Internal.Types.W# bx) kB (GHC.Internal.Types.I# ww) ds }; Collision _ [Occ=Dead] _ [Occ=Dead] -> T26615a.$wdisjointSubtrees @k @b @a $dEq ww wild ds @@ -880,7 +876,6 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] case ds1 of { L kA [Occ=Once2] _ [Occ=Dead] -> case _b of wild2 [Occ=Once1] { __DEFAULT -> - case kA of k0 [Occ=Once1] { __DEFAULT -> joinrec { lookupCont_ [Occ=LoopBreakerT[5]] :: Eq k => Word -> k -> Int -> HashMap k b -> Bool @@ -1004,8 +999,11 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] } }; } in jump lookupCont_ - $dEq (GHC.Internal.Types.W# bx) k0 (GHC.Internal.Types.I# ww) wild2 - }; + $dEq + (GHC.Internal.Types.W# bx) + kA + (GHC.Internal.Types.I# ww) + wild2; Leaf bx1 [Occ=Once1] ds3 [Occ=Once1!] -> case ds3 of { L kB [Occ=Once1] _ [Occ=Dead] -> case GHC.Internal.Classes.neWord @@ -1091,13 +1089,14 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] [LclId[JoinId(1)(Nothing)], Arity=1, Str=<L>, Unf=OtherCon []] go (ds1 [Occ=Once1!] :: Word) = case ds1 of { W# ds2 [Occ=Once1!] -> - case ds2 of ds3 { + case ds2 of wild5 { __DEFAULT -> let { m :: Word# [LclId] m = and# - ds3 (int2Word# (negateInt# (word2Int# ds3))) } in + wild5 + (int2Word# (negateInt# (word2Int# wild5))) } in case indexSmallArray# @Lifted @(HashMap k a) @@ -1118,7 +1117,7 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] of { False -> GHC.Internal.Types.False; True -> - jump go (GHC.Internal.Types.W# (and# ds3 (not# m))) + jump go (GHC.Internal.Types.W# (and# wild5 (not# m))) } } }; @@ -1137,12 +1136,12 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] [LclId[JoinId(1)(Nothing)], Arity=1, Str=<L>, Unf=OtherCon []] go (ds1 [Occ=Once1!] :: Word) = case ds1 of { W# ds2 [Occ=Once1!] -> - case ds2 of ds3 { + case ds2 of wild3 { __DEFAULT -> let { m :: Word# [LclId] - m = and# ds3 (int2Word# (negateInt# (word2Int# ds3))) } in + m = and# wild3 (int2Word# (negateInt# (word2Int# wild3))) } in case indexSmallArray# @Lifted @(HashMap k a) @@ -1161,7 +1160,7 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] case T26615a.$wdisjointSubtrees @k @a @b $dEq (+# ww 5#) ipv ipv1 of { False -> GHC.Internal.Types.False; - True -> jump go (GHC.Internal.Types.W# (and# ds3 (not# m))) + True -> jump go (GHC.Internal.Types.W# (and# wild3 (not# m))) } } }; @@ -1179,12 +1178,12 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] [LclId[JoinId(1)(Nothing)], Arity=1, Str=<L>, Unf=OtherCon []] go (ds1 [Occ=Once1!] :: Word) = case ds1 of { W# ds2 [Occ=Once1!] -> - case ds2 of ds3 { + case ds2 of wild3 { __DEFAULT -> let { m :: Word# [LclId] - m = and# ds3 (int2Word# (negateInt# (word2Int# ds3))) } in + m = and# wild3 (int2Word# (negateInt# (word2Int# wild3))) } in case indexSmallArray# @Lifted @(HashMap k a) @@ -1203,7 +1202,7 @@ T26615a.$wdisjointSubtrees [InlPrag=INLINABLE[2], Occ=LoopBreaker] case T26615a.$wdisjointSubtrees @k @a @b $dEq (+# ww 5#) ipv ipv1 of { False -> GHC.Internal.Types.False; - True -> jump go (GHC.Internal.Types.W# (and# ds3 (not# m))) + True -> jump go (GHC.Internal.Types.W# (and# wild3 (not# m))) } } }; @@ -1277,7 +1276,6 @@ T26615a.$wdisjointSubtrees Empty -> GHC.Internal.Types.True; Leaf bx ds2 -> case ds2 of { L kB ds3 -> - case kB of k0 { __DEFAULT -> join { exit [Dmd=LC(S,C(1,C(1,C(1,L))))] :: Word# -> k -> Word# -> Leaf k a -> Bool @@ -1392,8 +1390,7 @@ T26615a.$wdisjointSubtrees } } }; } in - jump $wlookupCont_ $dEq bx k0 ww ds - } + jump $wlookupCont_ $dEq bx kB ww ds }; Collision bx bx1 -> T26615a.disjointSubtrees_$s$wdisjointSubtrees @@ -1405,7 +1402,6 @@ T26615a.$wdisjointSubtrees case ds1 of { L kA ds2 -> case _b of wild2 { __DEFAULT -> - case kA of k0 { __DEFAULT -> join { exit [Dmd=LC(S,C(1,C(1,C(1,L))))] :: Word# -> k -> Word# -> Leaf k b -> Bool @@ -1519,8 +1515,7 @@ T26615a.$wdisjointSubtrees } } }; } in - jump $wlookupCont_ $dEq bx k0 ww wild2 - }; + jump $wlookupCont_ $dEq bx kA ww wild2; Leaf bx1 ds3 -> case ds3 of { L kB ds4 -> case neWord# bx bx1 of { @@ -1604,12 +1599,12 @@ T26615a.$wdisjointSubtrees $wgo [InlPrag=[2], Occ=LoopBreaker, Dmd=SC(S,L)] :: Word# -> Bool [LclId[JoinId(1)(Nothing)], Arity=1, Str=<1L>, Unf=OtherCon []] $wgo (ww1 :: Word#) - = case ww1 of ds1 { + = case ww1 of wild4 { __DEFAULT -> let { m :: Word# [LclId] - m = and# ds1 (int2Word# (negateInt# (word2Int# ds1))) } in + m = and# wild4 (int2Word# (negateInt# (word2Int# wild4))) } in case indexSmallArray# @Lifted @(HashMap k a) @@ -1626,7 +1621,7 @@ T26615a.$wdisjointSubtrees { (# ipv1 #) -> case T26615a.$wdisjointSubtrees @k @a @b $dEq lvl2 ipv ipv1 of { False -> GHC.Internal.Types.False; - True -> jump $wgo (and# ds1 (not# m)) + True -> jump $wgo (and# wild4 (not# m)) } } }; @@ -1647,12 +1642,12 @@ T26615a.$wdisjointSubtrees $wgo [InlPrag=[2], Occ=LoopBreaker, Dmd=SC(S,L)] :: Word# -> Bool [LclId[JoinId(1)(Nothing)], Arity=1, Str=<1L>, Unf=OtherCon []] $wgo (ww1 :: Word#) - = case ww1 of ds1 { + = case ww1 of wild2 { __DEFAULT -> let { m :: Word# [LclId] - m = and# ds1 (int2Word# (negateInt# (word2Int# ds1))) } in + m = and# wild2 (int2Word# (negateInt# (word2Int# wild2))) } in case indexSmallArray# @Lifted @(HashMap k a) @@ -1669,7 +1664,7 @@ T26615a.$wdisjointSubtrees { (# ipv1 #) -> case T26615a.$wdisjointSubtrees @k @a @b $dEq lvl2 ipv ipv1 of { False -> GHC.Internal.Types.False; - True -> jump $wgo (and# ds1 (not# m)) + True -> jump $wgo (and# wild2 (not# m)) } } }; @@ -1689,12 +1684,12 @@ T26615a.$wdisjointSubtrees $wgo [InlPrag=[2], Occ=LoopBreaker, Dmd=SC(S,L)] :: Word# -> Bool [LclId[JoinId(1)(Nothing)], Arity=1, Str=<1L>, Unf=OtherCon []] $wgo (ww1 :: Word#) - = case ww1 of ds1 { + = case ww1 of wild2 { __DEFAULT -> let { m :: Word# [LclId] - m = and# ds1 (int2Word# (negateInt# (word2Int# ds1))) } in + m = and# wild2 (int2Word# (negateInt# (word2Int# wild2))) } in case indexSmallArray# @Lifted @(HashMap k a) @@ -1711,7 +1706,7 @@ T26615a.$wdisjointSubtrees { (# ipv1 #) -> case T26615a.$wdisjointSubtrees @k @a @b $dEq lvl2 ipv ipv1 of { False -> GHC.Internal.Types.False; - True -> jump $wgo (and# ds1 (not# m)) + True -> jump $wgo (and# wild2 (not# m)) } } }; @@ -1845,32 +1840,7 @@ disjointSubtrees ==================== Tidy Core ==================== Result size of Tidy Core - = {terms: 622, types: 674, coercions: 18, joins: 8/14} - --- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} -$trModule1 :: GHC.Internal.Prim.Addr# -[GblId, Unf=OtherCon []] -$trModule1 = "T26615"# - --- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} -$trModule2 :: GHC.Internal.Types.TrName -[GblId, Unf=OtherCon []] -$trModule2 = GHC.Internal.Types.TrNameS $trModule1 - --- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} -$trModule3 :: GHC.Internal.Prim.Addr# -[GblId, Unf=OtherCon []] -$trModule3 = "main"# - --- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} -$trModule4 :: GHC.Internal.Types.TrName -[GblId, Unf=OtherCon []] -$trModule4 = GHC.Internal.Types.TrNameS $trModule3 - --- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} -T26615.$trModule [InlPrag=[~]] :: GHC.Internal.Types.Module -[GblId, Unf=OtherCon []] -T26615.$trModule = GHC.Internal.Types.Module $trModule4 $trModule2 + = {terms: 603, types: 666, coercions: 18, joins: 8/14} -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} lvl :: GHC.Internal.Prim.Addr# @@ -2029,7 +1999,7 @@ $wpoly_lookupCont_ end Rec } Rec { --- RHS size: {terms: 450, types: 507, coercions: 18, joins: 8/13} +-- RHS size: {terms: 445, types: 504, coercions: 18, joins: 8/13} T26615.$s$wdisjointSubtrees [InlPrag=[~], Occ=LoopBreaker] :: forall a b. GHC.Internal.Prim.Int# @@ -2067,11 +2037,7 @@ T26615.$s$wdisjointSubtrees T26615a.Leaf bx1 ds3 -> case ds3 of { T26615a.L kB ds4 -> case GHC.Internal.Prim.neWord# bx bx1 of { - __DEFAULT -> - case GHC.Internal.Classes.$fEqList_$s$c==1 kA kB of { - False -> GHC.Internal.Types.True; - True -> GHC.Internal.Types.False - }; + __DEFAULT -> GHC.Internal.Classes.$fEqList_$s$c/=1 kA kB; 1# -> GHC.Internal.Types.True } } @@ -2094,14 +2060,14 @@ T26615.$s$wdisjointSubtrees $s$wfoldr_ [InlPrag=[2], Occ=LoopBreaker, Dmd=SC(S,C(1,C(1,C(1,L))))] - :: GHC.Internal.Prim.SmallArray# (T26615a.Leaf [Char] a) + :: GHC.Internal.Prim.SmallArray# (T26615a.Leaf String a) -> GHC.Internal.Prim.Int# -> GHC.Internal.Prim.Int# -> Bool -> Bool [LclId[JoinId(4)(Nothing)], Arity=4, Str=<L><L><L><L>, Unf=OtherCon []] $s$wfoldr_ (sc - :: GHC.Internal.Prim.SmallArray# (T26615a.Leaf [Char] a)) + :: GHC.Internal.Prim.SmallArray# (T26615a.Leaf String a)) (sc1 :: GHC.Internal.Prim.Int#) (sc2 :: GHC.Internal.Prim.Int#) (sc3 :: Bool) @@ -2243,16 +2209,16 @@ T26615.$s$wdisjointSubtrees :: GHC.Internal.Prim.Word# -> Bool [LclId[JoinId(1)(Nothing)], Arity=1, Str=<1L>, Unf=OtherCon []] $wgo (ww1 :: GHC.Internal.Prim.Word#) - = case ww1 of ds3 { + = case ww1 of wild5 { __DEFAULT -> let { m :: GHC.Internal.Prim.Word# [LclId] m = GHC.Internal.Prim.and# - ds3 + wild5 (GHC.Internal.Prim.int2Word# (GHC.Internal.Prim.negateInt# - (GHC.Internal.Prim.word2Int# ds3))) } in + (GHC.Internal.Prim.word2Int# wild5))) } in case GHC.Internal.Prim.indexSmallArray# @GHC.Internal.Types.Lifted @(HashMap String a) @@ -2279,7 +2245,7 @@ T26615.$s$wdisjointSubtrees False -> GHC.Internal.Types.False; True -> jump $wgo - (GHC.Internal.Prim.and# ds3 (GHC.Internal.Prim.not# m)) + (GHC.Internal.Prim.and# wild5 (GHC.Internal.Prim.not# m)) } } }; @@ -2297,16 +2263,16 @@ T26615.$s$wdisjointSubtrees :: GHC.Internal.Prim.Word# -> Bool [LclId[JoinId(1)(Nothing)], Arity=1, Str=<1L>, Unf=OtherCon []] $wgo (ww1 :: GHC.Internal.Prim.Word#) - = case ww1 of ds3 { + = case ww1 of wild3 { __DEFAULT -> let { m :: GHC.Internal.Prim.Word# [LclId] m = GHC.Internal.Prim.and# - ds3 + wild3 (GHC.Internal.Prim.int2Word# (GHC.Internal.Prim.negateInt# - (GHC.Internal.Prim.word2Int# ds3))) } in + (GHC.Internal.Prim.word2Int# wild3))) } in case GHC.Internal.Prim.indexSmallArray# @GHC.Internal.Types.Lifted @(HashMap String a) @@ -2332,7 +2298,7 @@ T26615.$s$wdisjointSubtrees of { False -> GHC.Internal.Types.False; True -> - jump $wgo (GHC.Internal.Prim.and# ds3 (GHC.Internal.Prim.not# m)) + jump $wgo (GHC.Internal.Prim.and# wild3 (GHC.Internal.Prim.not# m)) } } }; @@ -2349,16 +2315,16 @@ T26615.$s$wdisjointSubtrees :: GHC.Internal.Prim.Word# -> Bool [LclId[JoinId(1)(Nothing)], Arity=1, Str=<1L>, Unf=OtherCon []] $wgo (ww1 :: GHC.Internal.Prim.Word#) - = case ww1 of ds3 { + = case ww1 of wild3 { __DEFAULT -> let { m :: GHC.Internal.Prim.Word# [LclId] m = GHC.Internal.Prim.and# - ds3 + wild3 (GHC.Internal.Prim.int2Word# (GHC.Internal.Prim.negateInt# - (GHC.Internal.Prim.word2Int# ds3))) } in + (GHC.Internal.Prim.word2Int# wild3))) } in case GHC.Internal.Prim.indexSmallArray# @GHC.Internal.Types.Lifted @(HashMap String a) @@ -2384,7 +2350,7 @@ T26615.$s$wdisjointSubtrees of { False -> GHC.Internal.Types.False; True -> - jump $wgo (GHC.Internal.Prim.and# ds3 (GHC.Internal.Prim.not# m)) + jump $wgo (GHC.Internal.Prim.and# wild3 (GHC.Internal.Prim.not# m)) } } }; ===================================== testsuite/tests/simplCore/should_compile/all.T ===================================== @@ -602,6 +602,7 @@ test('T26615', [grep_errmsg(r'fEqList')], multimod_compile, ['T26615', '-O -fsp # T26722: there should be no reboxing in $wg test('T26722', [grep_errmsg(r'SPEC')], compile, ['-O -dno-typeable-binds']) +test('T26548', normal, compile, ['-O -ddump-simpl -dsuppress-uniques -dno-typeable-binds']) test('T26805', [grep_errmsg(r'fromInteger')], compile, ['-O -dno-typeable-binds -ddump-simpl -dsuppress-uniques']) test('T26826', normal, compile, ['-O']) test('T26903', [grep_errmsg(r'reverse')], compile, ['-O -dno-typeable-binds -ddump-simpl -dsuppress-uniques -dsuppress-all']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/666b92a68ad854f95be44c1edb5a89dd... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/666b92a68ad854f95be44c1edb5a89dd... 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