Skip to content

Improve the pipeline with callbacks#785

Merged
maleadt merged 6 commits into
mainfrom
tb/callbacks
May 21, 2026
Merged

Improve the pipeline with callbacks#785
maleadt merged 6 commits into
mainfrom
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 maleadt force-pushed the tb/callbacks branch 2 times, most recently from d4f2382 to ad6df50 Compare May 20, 2026 05:40
maleadt added 6 commits May 21, 2026 14:58
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.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 78.30189% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.32%. Comparing base (b57a0e1) to head (b9ceb18).

Files with missing lines Patch % Lines
src/ptx.jl 29.41% 12 Missing ⚠️
src/optim.jl 87.64% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #785      +/-   ##
==========================================
+ Coverage   76.23%   76.32%   +0.09%     
==========================================
  Files          25       25              
  Lines        4077     4144      +67     
==========================================
+ Hits         3108     3163      +55     
- Misses        969      981      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt maleadt merged commit 3b00453 into main May 21, 2026
37 checks passed
@maleadt maleadt deleted the tb/callbacks branch May 21, 2026 15:24
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