Rewrite optimize pipeline for NewPM - #2713
Conversation
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/compiler/optimize.jl b/src/compiler/optimize.jl
index 027f1b22..11846c06 100644
--- a/src/compiler/optimize.jl
+++ b/src/compiler/optimize.jl
@@ -73,89 +73,89 @@ function optimize!(mod::LLVM.Module, tm::LLVM.TargetMachine)
run!(pb, mod, tm)
end
- function middle_optimize!(second_stage=false)
- @dispose pb = NewPMPassBuilder() begin
- registerEnzymeAndPassPipeline!(pb)
- register!(pb, RewriteGenericMemoryPass())
- add!(pb, NewPMAAManager()) do aam
- add!(aam, ScopedNoAliasAA())
- add!(aam, TypeBasedAA())
- add!(aam, BasicAA())
+ function middle_optimize!(second_stage = false)
+ return @dispose pb = NewPMPassBuilder() begin
+ registerEnzymeAndPassPipeline!(pb)
+ register!(pb, RewriteGenericMemoryPass())
+ add!(pb, NewPMAAManager()) do aam
+ add!(aam, ScopedNoAliasAA())
+ add!(aam, TypeBasedAA())
+ add!(aam, BasicAA())
end
- add!(pb, NewPMModulePassManager()) do mpm
- add!(mpm, RewriteGenericMemoryPass())
- add!(mpm, CPUFeaturesPass()) # why is this duplicated?
-
- add!(mpm, NewPMFunctionPassManager()) do fpm
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- add!(fpm, SimplifyCFGPass())
- add!(fpm, SROAPass())
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- add!(fpm, JumpThreadingPass())
- add!(fpm, CorrelatedValuePropagationPass())
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- add!(fpm, ReassociatePass())
- add!(fpm, EarlyCSEPass())
- add!(fpm, AllocOptPass())
-
- add!(fpm, NewPMLoopPassManager(use_memory_ssa=true)) do lpm
- add!(lpm, LoopIdiomRecognizePass())
- add!(lpm, LoopRotatePass())
- add!(lpm, LowerSIMDLoopPass())
- add!(lpm, LICMPass())
- add!(lpm, JuliaLICMPass())
- add!(lpm, SimpleLoopUnswitchPass())
- end
-
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- add!(fpm, NewPMLoopPassManager()) do lpm
- add!(lpm, IndVarSimplifyPass())
- add!(lpm, LoopDeletionPass())
+ add!(pb, NewPMModulePassManager()) do mpm
+ add!(mpm, RewriteGenericMemoryPass())
+ add!(mpm, CPUFeaturesPass()) # why is this duplicated?
+
+ add!(mpm, NewPMFunctionPassManager()) do fpm
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ add!(fpm, SimplifyCFGPass())
+ add!(fpm, SROAPass())
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ add!(fpm, JumpThreadingPass())
+ add!(fpm, CorrelatedValuePropagationPass())
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ add!(fpm, ReassociatePass())
+ add!(fpm, EarlyCSEPass())
+ add!(fpm, AllocOptPass())
+
+ add!(fpm, NewPMLoopPassManager(use_memory_ssa = true)) do lpm
+ add!(lpm, LoopIdiomRecognizePass())
+ add!(lpm, LoopRotatePass())
+ add!(lpm, LowerSIMDLoopPass())
+ add!(lpm, LICMPass())
+ add!(lpm, JuliaLICMPass())
+ add!(lpm, SimpleLoopUnswitchPass())
+ end
+
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ add!(fpm, NewPMLoopPassManager()) do lpm
+ add!(lpm, IndVarSimplifyPass())
+ add!(lpm, LoopDeletionPass())
+ end
+ add!(fpm, LoopUnrollPass(opt_level = 2)) # what opt level?
+ add!(fpm, AllocOptPass())
+ add!(fpm, SROAPass())
+ add!(fpm, GVNPass())
+
+ # This InstCombine needs to be after GVN
+ # Otherwise it will generate load chains in GPU code...
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ add!(fpm, MemCpyOptPass())
+ add!(fpm, SCCPPass())
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ add!(fpm, JumpThreadingPass())
+ add!(fpm, DSEPass())
+ add!(fpm, AllocOptPass())
+ add!(fpm, SimplifyCFGPass())
+
+
+ add!(fpm, NewPMLoopPassManager()) do lpm
+ add!(lpm, LoopIdiomRecognizePass())
+ add!(lpm, LoopDeletionPass())
end
- add!(fpm, LoopUnrollPass(opt_level=2)) # what opt level?
- add!(fpm, AllocOptPass())
- add!(fpm, SROAPass())
- add!(fpm, GVNPass())
-
- # This InstCombine needs to be after GVN
- # Otherwise it will generate load chains in GPU code...
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- add!(fpm, MemCpyOptPass())
- add!(fpm, SCCPPass())
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- add!(fpm, JumpThreadingPass())
- add!(fpm, DSEPass())
- add!(fpm, AllocOptPass())
- add!(fpm, SimplifyCFGPass())
-
-
- add!(fpm, NewPMLoopPassManager()) do lpm
- add!(lpm, LoopIdiomRecognizePass())
- add!(lpm, LoopDeletionPass())
+ add!(fpm, JumpThreadingPass())
+ add!(fpm, CorrelatedValuePropagationPass())
+ if second_stage
+
+ add!(fpm, ADCEPass())
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+
+ # GC passes
+ add!(fpm, GCInvariantVerifierPass(strong = false))
+ add!(fpm, SimplifyCFGPass())
+ add!(fpm, InstCombinePass())
+ add!(fpm, JLInstSimplifyPass())
+ end # second_stage
end
- add!(fpm, JumpThreadingPass())
- add!(fpm, CorrelatedValuePropagationPass())
- if second_stage
-
- add!(fpm, ADCEPass())
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
-
- # GC passes
- add!(fpm, GCInvariantVerifierPass(strong=false))
- add!(fpm, SimplifyCFGPass())
- add!(fpm, InstCombinePass())
- add!(fpm, JLInstSimplifyPass())
- end # second_stage
- end
end
- run!(pb, mod, tm)
+ run!(pb, mod, tm)
end
end # middle_optimize!
diff --git a/src/llvm/transforms.jl b/src/llvm/transforms.jl
index 5462fd43..67255c3a 100644
--- a/src/llvm/transforms.jl
+++ b/src/llvm/transforms.jl
@@ -2372,7 +2372,7 @@ end
function rewrite_generic_memory!(mod::LLVM.Module)
@static if VERSION < v"1.11-"
return false
- else
+ else
for f in functions(mod), bb in blocks(f)
iter = LLVM.API.LLVMGetFirstInstruction(bb)
while iter != C_NULL
@@ -2381,7 +2381,7 @@ function rewrite_generic_memory!(mod::LLVM.Module)
if !isa(inst, LLVM.LoadInst)
continue
end
-
+
if isa(operands(inst)[1], LLVM.ConstantExpr)
legal2, obj = absint(inst)
if legal2 && obj isa Memory && obj == typeof(obj).instance |
7e06ee7 to
b5ef19c
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## vc/split_newpm2 #2713 +/- ##
==================================================
Coverage ? 72.38%
==================================================
Files ? 58
Lines ? 18628
Branches ? 0
==================================================
Hits ? 13483
Misses ? 5145
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Benchmark Results
Benchmark PlotsA plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/18921523721/artifacts/4410793269. |
|
@wsmoses this now shows the same failure as before, but is just the rewrite of |
|
It turns out that Enzyme.jl/src/compiler/optimize.jl Lines 441 to 458 in 107b327 |
dcbfa45 to
00c7c44
Compare
|
oh interesting. that said, can we keep exact equivalent for the current new pm change, and then we can do pass pipeline tuning as a separate follow up? |
|
that way itll be easier to debug (e.g. git blame/figure out) if anything else goes awry/differently that wasnt caught by the CI tests |
3efc99b to
3f881e2
Compare
00c7c44 to
06460fb
Compare
No description provided.