EnzymeAD / Enzyme

High-performance automatic differentiation of LLVM and MLIR.
https://enzyme.mit.edu
Other
1.27k stars 108 forks source link

Unhandled global pointer case in Invert Pointer #1041

Closed wsmoses closed 1 year ago

wsmoses commented 1 year ago

@ZuseZ4 this is what the file you sent me earlier was supposed to reproduce (in debug mode).

I'm having difficulty reproducing the error we saw earlier using the following:

wmoses@beast:~/git/Enzyme/enzyme/build14 ((HEAD detached at origin/main)) $ gdb --args /home/wmoses/llvms/llvm14/buildD/bin/opt -load=Enzyme/LLVMEnzyme-14.so -enable-new-pm=0 -enzyme-max-type-depth=3  -enzyme out4_strict_aliasing_true.ll
wsmoses commented 1 year ago

Never mind, reproduced -- and have a fix!

ZuseZ4 commented 1 year ago

great! I guess you missed the strict-aliasing flag?

wsmoses commented 1 year ago

Actually no, it didn't need that. It just needed the old PM and the type depth 3 flag. USing the new pm led to it finishing extremely fast.

It does however, eventually hit another GlobalAlias issue in invertpointerM -- which we should also add a "invertPointerM of a globalalias should invertPointer of the aliasee".

Can you open a PR for that?

oval=@_ZN14QuantumCircuitD1Ev = dso_local unnamed_addr alias void (%class.QuantumCircuit*), void (%class.QuantumCircuit*)* @_ZN14QuantumCircuitD2Ev
 icv=0
available inversion for   %18 = load void (%class.QuantumGateBase*)**, void (%class.QuantumGateBase*)*** %17, align 8, !dbg !283461 of   %"'il_phi8" = phi void (%class.QuantumGateBase*)** , !dbg !283472
available inversion for   %5 = getelementptr inbounds %class.QuantumCircuit, %class.QuantumCircuit* %0, i32 0, i32 1, !dbg !283447 of   %"'ipg10" = getelementptr inbounds %class.QuantumCircuit, %class.QuantumCircuit* %"'", i32 0, i32 1, !dbg !283452
available inversion for   %9 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.27", %"class.__gnu_cxx::__normal_iterator.27"* %3, i32 0, i32 0, !dbg !283453 of   %"'ipg" = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.27", %"class.__gnu_cxx::__normal_iterator.27"* %"'ipa", i32 0, i32 0, !dbg !283455
available inversion for   %20 = load void (%class.QuantumGateBase*)*, void (%class.QuantumGateBase*)** %19, align 8, !dbg !283461 of   %"'il_phi9" = phi void (%class.QuantumGateBase*)* , !dbg !283472
available inversion for   %14 = load %class.QuantumGateBase*, %class.QuantumGateBase** %13, align 8, !dbg !283459 of   %"'il_phi" = phi %class.QuantumGateBase* , !dbg !283472
available inversion for   %2 = alloca %"class.__gnu_cxx::__normal_iterator.27", align 8 of   %"'ipa11" = alloca %"class.__gnu_cxx::__normal_iterator.27", align 8
available inversion for   %3 = alloca %"class.__gnu_cxx::__normal_iterator.27", align 8 of   %"'ipa" = alloca %"class.__gnu_cxx::__normal_iterator.27", align 8
available inversion for   %7 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.27", %"class.__gnu_cxx::__normal_iterator.27"* %2, i32 0, i32 0, !dbg !283453 of   %"'ipg12" = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.27", %"class.__gnu_cxx::__normal_iterator.27"* %"'ipa11", i32 0, i32 0, !dbg !283455
available inversion for   %8 = call %class.QuantumGateBase** @_ZNSt6vectorIP15QuantumGateBaseSaIS1_EE3endEv(%"class.std::vector.45"* noundef nonnull align 8 dereferenceable(24) %5) #36, !dbg !283453 of   %"'ac" = extractvalue { { i8*, i8* }, %class.QuantumGateBase**, %class.QuantumGateBase** } %_augmented, 2, !dbg !283455
available inversion for %class.QuantumCircuit* %0 of %class.QuantumCircuit* %"'"
available inversion for   %13 = call noundef nonnull align 8 dereferenceable(8) %class.QuantumGateBase** @_ZNK9__gnu_cxx17__normal_iteratorIPP15QuantumGateBaseSt6vectorIS2_SaIS2_EEEdeEv(%"class.__gnu_cxx::__normal_iterator.27"* noundef nonnull align 8 dereferenceable(8) %2) #36, !dbg !283455 of   %"'ip_phi7" = phi %class.QuantumGateBase** , !dbg !283466
available inversion for   %6 = call %class.QuantumGateBase** @_ZNSt6vectorIP15QuantumGateBaseSaIS1_EE5beginEv(%"class.std::vector.45"* noundef nonnull align 8 dereferenceable(24) %5) #36, !dbg !283453 of   %"'ac15" = extractvalue { { i8*, i8* }, %class.QuantumGateBase**, %class.QuantumGateBase** } %_augmented13, 2, !dbg !283455
opt: /home/wmoses/git/Enzyme/enzyme/Enzyme/GradientUtils.cpp:5079: llvm::Value* GradientUtils::invertPointerM(llvm::Value*, llvm::IRBuilder<>&, bool): Assertion `0 && "cannot find deal with ptr that isnt arg"' failed.

Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=140737347917696) at ./nptl/pthread_kill.c:44
44  ./nptl/pthread_kill.c: No such file or directory.
wsmoses commented 1 year ago

Also if you're curious:

(gdb) p I.dump()
  store i32 (...)** bitcast (i8** getelementptr inbounds ({ [52 x i8*] }, { [52 x i8*] }* @_ZTV14QuantumCircuit, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** %4, align 8, !dbg !283446
$1 = void
(gdb) p I.getDebugLoc().dump()
src/cppsim/circuit.cpp:224:35$2 = void
(gdb) 
ZuseZ4 commented 1 year ago

Can I generally switch to the new pm by now? I kept adding the flags, would be nice if I could drop that. I'll write a pr later.

wsmoses commented 1 year ago

As an LLVM pass yes, we haven’t added the clang or lld auto running though. Doing so would be extremely welcome though

On Wed, Mar 22, 2023 at 12:28 AM Manuel Drehwald @.***> wrote:

Can I generally switch to the new pm by now? I kept adding the flags, would be nice if I could drop that. I'll write a pr later.

— Reply to this email directly, view it on GitHub https://github.com/EnzymeAD/Enzyme/issues/1041#issuecomment-1478903588, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJTUXHMPJFMI6H4SZVBG6LW5J5XZANCNFSM6AAAAAAWDJGV6U . You are receiving this because you modified the open/close state.Message ID: @.***>