Skip to content

Commit 5c0ba31

Browse files
committed
Restore metadata hack.
1 parent 71ed9d9 commit 5c0ba31

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/irgen.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,36 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
413413
end
414414
end
415415

416+
# fixup metadata
417+
#
418+
# Julia emits invariant.load and const TBAA metadta on loads from pointer args,
419+
# which is invalid now that we have materialized the byval.
420+
for (i, param) in enumerate(parameters(f))
421+
if byval[i]
422+
# collect all uses of the argument
423+
worklist = Vector{LLVM.Instruction}(user.(collect(uses(param))))
424+
while !isempty(worklist)
425+
value = popfirst!(worklist)
426+
427+
# remove the invariant.load attribute
428+
md = metadata(value)
429+
if haskey(md, LLVM.MD_invariant_load)
430+
delete!(md, LLVM.MD_invariant_load)
431+
end
432+
if haskey(md, LLVM.MD_tbaa)
433+
delete!(md, LLVM.MD_tbaa)
434+
end
435+
436+
# recurse on the output of some instructions
437+
if isa(value, LLVM.BitCastInst) ||
438+
isa(value, LLVM.GetElementPtrInst) ||
439+
isa(value, LLVM.AddrSpaceCastInst)
440+
append!(worklist, user.(collect(uses(value))))
441+
end
442+
end
443+
end
444+
end
445+
416446
# generate the new function type & definition
417447
new_types = LLVM.LLVMType[]
418448
for (i, param) in enumerate(parameters(ft))

0 commit comments

Comments
 (0)