8
8
# Based on Julia's optimization pipeline, minus the SLP and loop vectorizers.
9
9
function addOptimizationPasses! (pm, opt_level= 2 )
10
10
# 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.
15
23
16
24
constant_merge! (pm)
17
25
18
26
if opt_level < 2
19
- cfgsimplification! (pm)
27
+ cfgsimplification! (pm; hoist_common_insts = true )
20
28
if opt_level == 1
21
29
scalar_repl_aggregates! (pm)
22
30
instruction_combining! (pm)
@@ -36,7 +44,7 @@ function addOptimizationPasses!(pm, opt_level=2)
36
44
if opt_level >= 3
37
45
basic_alias_analysis! (pm)
38
46
end
39
- cfgsimplification! (pm)
47
+ cfgsimplification! (pm; hoist_common_insts = true )
40
48
dce! (pm)
41
49
scalar_repl_aggregates! (pm)
42
50
@@ -51,7 +59,7 @@ function addOptimizationPasses!(pm, opt_level=2)
51
59
alloc_opt! (pm)
52
60
# consider AggressiveInstCombinePass at optlevel > 2
53
61
instruction_combining! (pm)
54
- cfgsimplification! (pm)
62
+ cfgsimplification! (pm; hoist_common_insts = true )
55
63
scalar_repl_aggregates! (pm)
56
64
instruction_simplify! (pm)
57
65
jump_threading! (pm)
@@ -114,8 +122,12 @@ function addOptimizationPasses!(pm, opt_level=2)
114
122
loop_vectorize! (pm)
115
123
loop_load_elimination! (pm)
116
124
# 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
119
131
120
132
aggressive_dce! (pm)
121
133
end
0 commit comments