Skip to content

Commit 3c994c1

Browse files
committed
Add a dead code elimination pass before lowering ptls
Make sure dead ptls references are removed at LLVM IR level and add test for it. This is mostly for test purpose. LLVM is usually smart enough to remove it later but it's much harder to test and the present of a dead call in the IR makes many other tests harder.
1 parent 236e486 commit 3c994c1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/jitlayers.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level)
148148
#if JL_LLVM_VERSION < 50000
149149
PM->add(createLowerExcHandlersPass());
150150
PM->add(createLateLowerGCFramePass());
151+
PM->add(createDeadCodeEliminationPass());
151152
PM->add(createLowerPTLSPass(imaging_mode));
152153
#endif
153154

@@ -240,6 +241,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level)
240241
PM->add(createLowerExcHandlersPass());
241242
PM->add(createGCInvariantVerifierPass(false));
242243
PM->add(createLateLowerGCFramePass());
244+
PM->add(createDeadCodeEliminationPass());
243245
PM->add(createLowerPTLSPass(imaging_mode));
244246
#endif
245247
}

test/choosetests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function choosetests(choices = [])
3535
"enums", "cmdlineargs", "i18n", "workspace", "libdl", "int",
3636
"checked", "intset", "floatfuncs", "compile", "distributed", "inline",
3737
"boundscheck", "error", "ambiguous", "cartesian", "asmvariant", "osutils",
38-
"channels", "iostream", "specificity"
38+
"channels", "iostream", "specificity", "codegen"
3939
]
4040
profile_skipped = false
4141
if startswith(string(Sys.ARCH), "arm")

test/codegen.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
# tests for codegen and optimizations
4+
5+
const opt_level = Base.JLOptions().opt_level
6+
7+
# `_dump_function` might be more efficient but it doesn't really matter here...
8+
get_llvm(f::ANY, t::ANY, strip_ir_metadata=true, dump_module=false) =
9+
sprint(code_llvm, f, t, strip_ir_metadata, dump_module)
10+
11+
if opt_level > 0
12+
# Make sure getptls call is removed at IR level with optimization on
13+
@test !contains(get_llvm(identity, Tuple{String}), " call ")
14+
end

0 commit comments

Comments
 (0)