Skip to content

Improve the pipeline with callbacks#785

Open
maleadt wants to merge 6 commits intomasterfrom
tb/callbacks
Open

Improve the pipeline with callbacks#785
maleadt wants to merge 6 commits intomasterfrom
tb/callbacks

Conversation

@maleadt
Copy link
Copy Markdown
Member

@maleadt maleadt commented Apr 24, 2026

Uses JuliaLLVM/LLVM.jl#524 to improve our pipeline, adding the callbacks needed to e.g. avoid manual NVVMReflect. Also changes the NVVMReflect semantics to match LLVM's, which will need some adaptation in CUDA.jl (though nothing crucial warranting a breaking release). Finally, also align the pipeline with Julia's one more closely.

maleadt added 6 commits April 24, 2026 09:47
Backfills a set of passes and reorderings from Julia's `pipeline.cpp`
that were missing from `buildNewPMPipeline!`:

- Early simplification: add InferFunctionAttrs, move DCE before
  SimplifyCFG, add EarlyCSE after SROA, and the GlobalOpt + Promote +
  InstCombine tail at O>=1.
- Early optimizer: gate the CGSCC AllocOpt/Float2Int/LowerConstantIntrinsics
  adaptor on O>=2, reorder the function-level sequence, add
  AggressiveInstCombine + ConstraintElimination, switch EarlyCSE to MSSA,
  and close with GlobalOpt + GlobalDCE.
- Loop optimizer: merge into a single MSSA-enabled LPM with
  LoopInstSimplify + LoopSimplifyCFG + pre-rotate LICM (no speculation) +
  LoopRotate + LICM + SimpleLoopUnswitch, then run SimplifyCFG +
  InstCombine between the two loop sub-pipelines.
- Scalar optimizer: add MergedLoadStoreMotion, BDCE, ADCE,
  ConstraintElimination and an early VectorCombine at O>=2; add an O>=1
  path mirroring Julia's lighter sequence; replace the
  LoopDeletion/LoopInstSimplify + LoopDistribute tail with an
  LICM/JuliaLICM LPM followed by SimplifyCFG + InstCombine.
- Vector pipeline: prepend a LoopRotate + LoopDeletion LPM, run
  LoopDistribute here instead of in scalar opts, and add the post-vectorize
  LICM + EarlyCSE + CVP + InstCombine cleanup plus the
  SROA(PreserveCFG) + InstSimplify tail.
- Add LibCallsShrinkWrapPass in the early-optimizer O>=2 function
  sequence (between CorrelatedValuePropagation and Reassociate),
  matching Julia. A no-op on modules without libc-shaped calls, but
  beneficial on libdevice-using PTX code.
- Gate the cleanup-pipeline GVN tail on opt_level >= 2 to match Julia
  (was opt_level >= 1).
Set the `nvvm-reflect-ftz` module flag from `target.fastmath` in
`finish_module!` — the same channel Clang uses for
`-fcuda-flush-denormals-to-zero`, and the only `__nvvm_reflect` key that
LLVM's upstream NVVMReflectPass honors besides `__CUDA_ARCH`. On LLVM
17+, that pass now runs via the PipelineStart EP callback we wire up
in `buildEarlySimplificationPipeline`.

Simplify the custom `nvvm_reflect!` fallback (LLVM < 17) to match
upstream semantics: `__CUDA_ARCH` from the target capability, `__CUDA_FTZ`
from the module flag, every other key folds to 0. The previous
fastmath-derived handling of `__CUDA_PREC_DIV` / `__CUDA_PREC_SQRT` /
`__CUDA_FMAD` is dropped; callers that want those behaviors should rely
on LLVM fast-math flags on the FP ops themselves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant