Skip to content

Commit 3f07eb3

Browse files
authored
Merge pull request #231 from JuliaGPU/tb/cfg_simplification_options
Use CFGSimplifyOptions to get closer to Base's optimization pipeline.
2 parents 111afc4 + e91dae7 commit 3f07eb3

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

Manifest.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ version = "1.3.0"
3939

4040
[[LLVM]]
4141
deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Printf", "Unicode"]
42-
git-tree-sha1 = "733abcbdc67337bb6aaf873c6bebbe1e6440a5df"
42+
git-tree-sha1 = "d6041ad706cf458b2c9f3e501152488a26451e9c"
4343
uuid = "929cbde3-209d-540e-8aea-75f648917ca0"
44-
version = "4.1.1"
44+
version = "4.2.0"
4545

4646
[[LLVMExtra_jll]]
4747
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
48-
git-tree-sha1 = "b36c0677a0549c7d1dc8719899a4133abbfacf7d"
48+
git-tree-sha1 = "a9b1130c4728b0e462a1c28772954650039eb847"
4949
uuid = "dad2f222-ce93-54a1-a47d-0025e8a3acab"
50-
version = "0.0.6+0"
50+
version = "0.0.7+0"
5151

5252
[[LibCURL]]
5353
deps = ["LibCURL_jll", "MozillaCACerts_jll"]

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1414

1515
[compat]
1616
ExprTools = "0.1"
17-
LLVM = "4.0"
17+
LLVM = "4.2"
1818
TimerOutputs = "0.5"
1919
julia = "1.6"
2020

src/optim.jl

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ end
88
# Based on Julia's optimization pipeline, minus the SLP and loop vectorizers.
99
function addOptimizationPasses!(pm, opt_level=2)
1010
# compare with the using Julia's optimization pipeline directly:
11-
#ccall(:jl_add_optimization_passes, Cvoid,
12-
# (LLVM.API.LLVMPassManagerRef, Cint, Cint),
13-
# pm, opt_level, #=lower_intrinsics=# 0)
14-
#return
11+
ccall(:jl_add_optimization_passes, Cvoid,
12+
(LLVM.API.LLVMPassManagerRef, Cint, Cint),
13+
pm, opt_level, #=lower_intrinsics=# 0)
14+
return
15+
16+
# NOTE: LLVM 12 disabled the hoisting of common instruction
17+
# before loop vectorization (https://reviews.llvm.org/D84108).
18+
#
19+
# This is re-enabled with calls to cfg_simplify here,
20+
# to merge allocations and sometimes eliminate them,
21+
# since AllocOpt does not handle PhiNodes.
22+
# Enable this instruction hoisting because of this and Union benchmarks.
1523

1624
constant_merge!(pm)
1725

1826
if opt_level < 2
19-
cfgsimplification!(pm)
27+
cfgsimplification!(pm; hoist_common_insts=true)
2028
if opt_level == 1
2129
scalar_repl_aggregates!(pm)
2230
instruction_combining!(pm)
@@ -36,7 +44,7 @@ function addOptimizationPasses!(pm, opt_level=2)
3644
if opt_level >= 3
3745
basic_alias_analysis!(pm)
3846
end
39-
cfgsimplification!(pm)
47+
cfgsimplification!(pm; hoist_common_insts=true)
4048
dce!(pm)
4149
scalar_repl_aggregates!(pm)
4250

@@ -51,7 +59,7 @@ function addOptimizationPasses!(pm, opt_level=2)
5159
alloc_opt!(pm)
5260
# consider AggressiveInstCombinePass at optlevel > 2
5361
instruction_combining!(pm)
54-
cfgsimplification!(pm)
62+
cfgsimplification!(pm; hoist_common_insts=true)
5563
scalar_repl_aggregates!(pm)
5664
instruction_simplify!(pm)
5765
jump_threading!(pm)
@@ -114,8 +122,12 @@ function addOptimizationPasses!(pm, opt_level=2)
114122
loop_vectorize!(pm)
115123
loop_load_elimination!(pm)
116124
# Cleanup after LV pass
117-
cfgsimplification!(pm)
118-
# TODO: aggressive CFG simplificaton options
125+
cfgsimplification!(pm; # Aggressive CFG simplification
126+
forward_switch_cond_to_phi=true,
127+
convert_switch_to_lookup_table=true,
128+
need_canonical_loop=true,
129+
hoist_common_insts=true,
130+
sink_common_insts=true) # FIXME: Causes assertion in llvm-late-lowering
119131

120132
aggressive_dce!(pm)
121133
end

0 commit comments

Comments
 (0)