Cheng Shao pushed to branch wip/fix-use-std-ap-thunk at Glasgow Haskell Compiler / GHC Commits: d5444d78 by Cheng Shao at 2026-07-14T11:18:52+00:00 compiler: fix redundant AP thunk codegen when not using -ticky-ap-thunk This patch fixes a double negation confusion in !7525 that results in some redundant AP thunk code generation when not using -ticky-ap-thunk. Now, we use `stgToCmmUseStdApThunk` to indicate whether precomputed AP thunks in the RTS should be used, which defaults to `True`, unless `-ticky-ap-thunk` is passed. `-finfo-table-map` now also implies `-ticky-ap-thunk`, since when doing IPE profiling we want the generated AP thunks to be unique. Fixes #27502. ------------------------- Metric Decrease: T3064 ------------------------- Co-authored-by: Codex <codex@openai.com> - - - - - 5 changed files: - + changelog.d/fix-use-std-ap-thunk - compiler/GHC/Driver/Config/StgToCmm.hs - compiler/GHC/Driver/Flags.hs - compiler/GHC/StgToCmm/Bind.hs - compiler/GHC/StgToCmm/Config.hs Changes: ===================================== changelog.d/fix-use-std-ap-thunk ===================================== @@ -0,0 +1,4 @@ +section: codegen +synopsis: Fix redundant AP thunk codegen when not using -ticky-ap-thunk +issues: #27502 +mrs: !16340 ===================================== compiler/GHC/Driver/Config/StgToCmm.hs ===================================== @@ -87,7 +87,7 @@ initStgToCmmConfig dflags mod = StgToCmmConfig , stgToCmmAvx = isAvxEnabled dflags , stgToCmmAvx2 = isAvx2Enabled dflags , stgToCmmAvx512f = isAvx512fEnabled dflags - , stgToCmmTickyAP = gopt Opt_Ticky_AP dflags + , stgToCmmUseStdApThunk = not $ gopt Opt_Ticky_AP dflags -- See Note [Saving foreign call target to local] , stgToCmmSaveFCallTargetToLocal = any (callerSaves platform) $ activeStgRegs platform } where profile = targetProfile dflags ===================================== compiler/GHC/Driver/Flags.hs ===================================== @@ -379,6 +379,7 @@ impliedGFlags = [(Opt_DeferTypeErrors, turnOn, Opt_DeferTypedHoles) ,(Opt_ByteCodeAndObjectCode, turnOn, Opt_WriteByteCode) ,(Opt_InfoTableMap, turnOn, Opt_InfoTableMapWithStack) ,(Opt_InfoTableMap, turnOn, Opt_InfoTableMapWithFallback) + ,(Opt_InfoTableMap, turnOn, Opt_Ticky_AP) ] ++ validHoleFitsImpliedGFlags -- | General flags that are switched on/off when other general flags are switched ===================================== compiler/GHC/StgToCmm/Bind.hs ===================================== @@ -280,7 +280,7 @@ cgRhs id (StgRhsClosure fvs cc upd_flag args body _typ) = do profile <- getProfile check_tags <- stgToCmmDoTagCheck <$> getStgToCmmConfig - use_std_ap_thunk <- stgToCmmTickyAP <$> getStgToCmmConfig + use_std_ap_thunk <- stgToCmmUseStdApThunk <$> getStgToCmmConfig mkRhsClosure profile use_std_ap_thunk check_tags id cc (nonVoidIds (dVarSetElems fvs)) upd_flag args body ------------------------------------------------------------------------ ===================================== compiler/GHC/StgToCmm/Config.hs ===================================== @@ -73,7 +73,7 @@ data StgToCmmConfig = StgToCmmConfig , stgToCmmAllowWordMul2Instr :: !Bool -- ^ Allowed to generate WordMul2 instruction , stgToCmmAllowFMAInstr :: FMASign -> Bool -- ^ Allowed to generate FMA instruction , stgToCmmAllowIntWord64X2MinMax :: !Bool -- ^ Allowed to generate min/max instructions for Int64X2/Word64X2 - , stgToCmmTickyAP :: !Bool -- ^ Disable use of precomputed standard thunks. + , stgToCmmUseStdApThunk :: !Bool -- ^ Use precomputed standard AP thunks in the RTS. , stgToCmmSaveFCallTargetToLocal :: !Bool -- ^ Save a foreign call target to a Cmm local, see -- Note [Saving foreign call target to local] for details ------------------------------ SIMD flags ------------------------------------ View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d5444d78c358a9d6bccca5634e3f9a3a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d5444d78c358a9d6bccca5634e3f9a3a... 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