@@ -413,6 +413,36 @@ function lower_byval(@nospecialize(job::CompilerJob), mod::LLVM.Module, f::LLVM.
413
413
end
414
414
end
415
415
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
+
416
446
# generate the new function type & definition
417
447
new_types = LLVM. LLVMType[]
418
448
for (i, param) in enumerate (parameters (ft))
0 commit comments