Skip to content

Conversation

wsmoses
Copy link
Member

@wsmoses wsmoses commented Aug 31, 2025

No description provided.

@wsmoses
Copy link
Member Author

wsmoses commented Aug 31, 2025

currently this results in an inserted instruction (bitcast) without a parent -- and is used in a memset:

Thread 2 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1354226.1354226]
<signal handler called>
(rr) bt
#0  <signal handler called>
#1  llvm::Instruction::insertBefore (this=0x644400c31e10, InsertPos=0x0)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/Instruction.h:91
#2  0x00007adc233fd6d7 in propagateJuliaAddrspaces (F=...) at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:290
#3  0x00007adc233fd7f4 in PropagateJuliaAddrspacesPass::run (this=0x644402a23778, F=..., AM=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:300
#4  0x00007adc2348b136 in llvm::detail::PassModel<llvm::Function, PropagateJuliaAddrspacesPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (this=0x644402a23770, IR=..., AM=...)
    at /home/wmoses/git/julia11/usr/include/llvm/IR/PassManagerInternal.h:89
#5  0x00007adc1fe12405 in llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (AM=..., IR=..., this=<optimized out>) at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/PassManager.h:517
#6  llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (this=<optimized out>, IR=..., AM=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/PassManagerInternal.h:89
#7  0x00007adc1da89901 in llvm::ModuleToFunctionPassAdaptor::run (this=<optimized out>, M=..., AM=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/PassManager.cpp:124
#8  0x00007adc1fe03515 in llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (this=<optimized out>, IR=..., AM=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/PassManagerInternal.h:89
#9  0x00007adc1676b1ca in llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (
    AM=..., IR=..., this=0x7ffed0db39b0) at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/PassManager.h:517
#10 runJuliaPasses (Mod=0x644401cb21d0, Fun=<optimized out>, Passes=<optimized out>, Machine=<optimized out>, PassOpts=<optimized out>, 
    PassExts=<optimized out>) at /workspace/srcdir/LLVM.jl/deps/LLVMExtra/lib/NewPM.cpp:217
#11 0x00007adbf1bb11d1 in julia_LLVMRunJuliaPasses_18057 (M=..., Passes=<error reading variable: Cannot access memory at address 0x0>, TM=<optimized out>, 
    Options=135085088173584, Extensions=110243209596432) at /home/wmoses/.julia/packages/LLVM/UFrs4/lib/16/libLLVM_extra.jl:397
#12 0x00007adbf1ac4547 in macro expansion () at /home/wmoses/.julia/packages/LLVM/UFrs4/src/executionengine/utils.jl:25
#13 julia_run!_17968 (pb=..., target=..., tm=...) at /home/wmoses/.julia/packages/LLVM/UFrs4/src/newpm.jl:291
#14 0x00007adbe956d89b in run! () at /home/wmoses/.julia/packages/LLVM/UFrs4/src/newpm.jl:252
#15 macro expansion () at /mnt3/wmoses/git/Enzyme.jl/src/compiler/optimize.jl:111
#16 macro expansion () at /home/wmoses/.julia/packages/LLVM/UFrs4/src/base.jl:97
#17 julia_prop_julia_addr_29938 (mod=...) at /mnt3/wmoses/git/Enzyme.jl/src/compiler/optimize.jl:105
#18 0x00007adbe943d03f in jfptr_prop_julia_addr_29939 () from /home/wmoses/.julia/compiled/v1.11/Enzyme/G1p5n_AGSw1.so
#19 0x00007adc24454141 in _jl_invoke (F=0x7adbe9918b60 <jl_system_image_data+1787296>, args=0x7ffed0db5168, nargs=1, 
    mfunc=0x7adbe9e0b6c0 <jl_system_image_data+6975744>, world=26770) at /home/wmoses/git/julia11/src/gf.c:2929
#20 0x00007adc24454ca9 in ijl_apply_generic (F=0x7adbe9918b60 <jl_system_image_data+1787296>, args=0x7ffed0db5168, nargs=1)
    at /home/wmoses/git/julia11/src/gf.c:3125
#21 0x00007adc241ced9a in julia_module_pass_callback_12823 (ptr=110243250643408, data=<optimized out>)
    at /home/wmoses/.julia/packages/LLVM/UFrs4/src/pass.jl:19
#22 0x00007adc241cee61 in jfptr_module_pass_callback_12824 ()
#23 0x00007adc24454141 in _jl_invoke (F=0x7adbfc01b270 <jl_system_image_data+4149808>, args=0x7ffed0db52e0, nargs=2, mfunc=0x7adc19c9e310, world=26770)
    at /home/wmoses/git/julia11/src/gf.c:2929
#24 0x00007adc24454ca9 in ijl_apply_generic (F=0x7adbfc01b270 <jl_system_image_data+4149808>, args=0x7ffed0db52e0, nargs=2)
    at /home/wmoses/git/julia11/src/gf.c:3125
#25 0x00007adbe95f01bf in jlcapi_module_pass_callback_30225 () from /home/wmoses/.julia/compiled/v1.11/Enzyme/G1p5n_AGSw1.so
#26 0x00007adc1675c6a1 in (anonymous namespace)::JuliaModulePass::runOnModule (this=<optimized out>, M=...)
    at /workspace/srcdir/LLVM.jl/deps/LLVMExtra/lib/Core.cpp:195
#27 0x00007adc1da3febe in (anonymous namespace)::MPPassManager::runOnModule (M=..., this=<optimized out>)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/LegacyPassManager.cpp:1545
#28 llvm::legacy::PassManagerImpl::run (this=0x644401c6e0d0, M=...)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/LegacyPassManager.cpp:535
#29 0x00007adc1d95dd62 in LLVMRunPassManager (PM=<optimized out>, M=<optimized out>)
--Type <RET> for more, q to quit, c to continue without paging--q
Quit
(rr) b propagateJuliaAddrspaces
Breakpoint 1 at 0x7adc233fd63a: file /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp, line 287.
(rr) rc
Continuing.

instruction was created here

(rr) finish
Run till exit from #0  0x00007adc233fd06b in PropagateJuliaAddrspacesVisitor::LiftPointer (this=0x7ffed0db3520, M=0x644401cb21d0, V=0x6444000c3f80, 
    InsertPt=0x0) at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:216
0x00007adc233fd2f7 in PropagateJuliaAddrspacesVisitor::visitMemSetInst (this=0x7ffed0db3520, MI=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:250
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
Value returned is $11 = (llvm::Value *) 0x644400c31e10
(rr) n
251	    if (!Replacement)
(rr) p Replacement->dump()
  <badref> = bitcast i64* <badref> to i8*
$12 = void
(rr) b LiftPointer
Breakpoint 3 at 0x7adc233fc660: file /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp, line 83.
(rr) rc
Continuing.

Thread 2 hit Hardware watchpoint 2: *((llvm::BasicBlock **) 0x644400c31e38)

Old value = (llvm::BasicBlock *) 0x0
New value = (llvm::BasicBlock *) 0x7adc2314ccec <(anonymous namespace)::BreakCriticalEdges::ID>
llvm::Instruction::Instruction (this=0x644400c31e10, ty=<optimized out>, it=<optimized out>, Ops=<optimized out>, NumOps=<optimized out>, InsertBefore=0x0)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/Instruction.cpp:26
26	  : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
(rr) up
#1  0x00007adc1da0e765 in llvm::UnaryInstruction::UnaryInstruction (IB=<optimized out>, V=<optimized out>, iType=49, Ty=<optimized out>, 
    this=0x644400c31e10) at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/OperandTraits.h:31
31	  static Use *op_begin(SubClass* U) {
(rr) 
#2  llvm::CastInst::CastInst (InsertBefore=<optimized out>, NameStr=..., S=<optimized out>, iType=49, Ty=<optimized out>, this=0x644400c31e10)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/include/llvm/IR/InstrTypes.h:433
433	    : UnaryInstruction(Ty, iType, S, InsertBefore) {
(rr) 
#3  llvm::BitCastInst::BitCastInst (this=0x644400c31e10, S=0x6444023f23a0, Ty=0x6443fa3b7b80, Name=..., InsertBefore=<optimized out>)
    at /home/wmoses/git/julia11/deps/srccache/llvm-julia-16.0.6-3/llvm/lib/IR/Instructions.cpp:3971
3971	) : CastInst(Ty, BitCast, S, Name, InsertBefore) {
(rr) 
#4  0x00007adc233fc5cc in operator() (__closure=0x7ffed0db3230, CurrentV=0x6444023f23a0, InsertPt=0x0)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:190
190	            auto *BCI = new BitCastInst(CurrentV, TargetType);
(rr) 
#5  0x00007adc233fd06b in PropagateJuliaAddrspacesVisitor::LiftPointer (this=0x7ffed0db3520, M=0x644401cb21d0, V=0x6444000c3f80, InsertPt=0x0)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:216
216	    return CollapseCastsAndLift(V, InsertPt);
(rr) l
211	        } else {
212	            assert(false && "Shouldn't have reached here");
213	        }
214	    }
215	
216	    return CollapseCastsAndLift(V, InsertPt);
217	}
218	
219	void PropagateJuliaAddrspacesVisitor::visitMemop(Instruction &I, Type *T, unsigned OpIndex) {
220	    Value *Original = I.getOperand(OpIndex);
(rr) p InsertPt
$13 = (llvm::Instruction *) 0x0
(rr) up
#6  0x00007adc233fd2f7 in PropagateJuliaAddrspacesVisitor::visitMemSetInst (this=0x7ffed0db3520, MI=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:250
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
(rr) down
#5  0x00007adc233fd06b in PropagateJuliaAddrspacesVisitor::LiftPointer (this=0x7ffed0db3520, M=0x644401cb21d0, V=0x6444000c3f80, InsertPt=0x0)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:216
216	    return CollapseCastsAndLift(V, InsertPt);
(rr) up
#6  0x00007adc233fd2f7 in PropagateJuliaAddrspacesVisitor::visitMemSetInst (this=0x7ffed0db3520, MI=...)
    at /home/wmoses/git/julia11/src/llvm-propagate-addrspaces.cpp:250
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
(rr) l
245	
246	void PropagateJuliaAddrspacesVisitor::visitMemSetInst(MemSetInst &MI) {
247	    unsigned AS = MI.getDestAddressSpace();
248	    if (!isSpecialAS(AS))
249	        return;
250	    Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest());
251	    if (!Replacement)
252	        return;
253	    Function *TheFn = Intrinsic::getDeclaration(MI.getModule(), Intrinsic::memset,
254	        {Replacement->getType(), MI.getOperand(1)->getType()});
(rr) l
255	    MI.setCalledFunction(TheFn);
256	    MI.setArgOperand(0, Replacement);
257	}
258	
259	void PropagateJuliaAddrspacesVisitor::visitMemTransferInst(MemTransferInst &MTI) {
260	    unsigned DestAS = MTI.getDestAddressSpace();
261	    unsigned SrcAS = MTI.getSourceAddressSpace();
262	    if (!isSpecialAS(DestAS) && !isSpecialAS(SrcAS))
263	        return;
264	    Value *Dest = MTI.getRawDest();

@wsmoses wsmoses added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Aug 31, 2025
@vchuravy
Copy link
Member

Can you audit other uses of LiftPointer and perhaps we could remove the default Nullpointer argument and always require an insertion point?

@gbaraldi
Copy link
Member

gbaraldi commented Sep 1, 2025

It also could do with a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants