Skip to content

Commit 0aff8bb

Browse files
committed
Make add_input_arguments! resilient to constant expressions.
1 parent b19f241 commit 0aff8bb

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/driver.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,6 @@ const __llvm_initialized = Ref(false)
290290
end
291291
run!(pb, ir, llvm_machine(job.config.target))
292292
end
293-
## XXX: LLVM often leaves behind unused constant expressions containing function
294-
## pointer bitcasts we just optimized away, so prune those manually.
295-
for f in functions(ir)
296-
prune_constexpr_uses!(f)
297-
end
298293
end
299294

300295
# all deferred compilations should have been resolved

src/irgen.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -935,12 +935,24 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
935935
while worklist_length != length(worklist)
936936
# iteratively discover functions that use an intrinsic or any function calling it
937937
worklist_length = length(worklist)
938-
additions = LLVM.Function[]
939-
for f in worklist, use in uses(f)
940-
inst = user(use)::Instruction
941-
bb = LLVM.parent(inst)
942-
new_f = LLVM.parent(bb)
943-
in(new_f, worklist) || push!(additions, new_f)
938+
additions = Set{LLVM.Function}()
939+
function scan_uses(val)
940+
for use in uses(val)
941+
candidate = user(use)
942+
if isa(candidate, Instruction)
943+
bb = LLVM.parent(candidate)
944+
new_f = LLVM.parent(bb)
945+
in(new_f, worklist) || push!(additions, new_f)
946+
elseif isa(candidate, ConstantExpr)
947+
@safe_info candidate
948+
scan_uses(candidate)
949+
else
950+
error("Don't know how to check uses of $candidate. Please file an issue.")
951+
end
952+
end
953+
end
954+
for f in worklist
955+
scan_uses(f)
944956
end
945957
for f in additions
946958
push!(worklist, f)

0 commit comments

Comments
 (0)