Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 16: Opaque pointer failure at rustc #33

Closed
bytesnake opened this issue May 24, 2023 · 6 comments
Closed

LLVM 16: Opaque pointer failure at rustc #33

bytesnake opened this issue May 24, 2023 · 6 comments

Comments

@bytesnake
Copy link

Part of #29.

#[autodiff(cos_inplace, Reverse, Const)]
fn sin_inplace(#[dup] x: &f32, #[dup_noneed] y: &mut f32) {
    *y = x.sin();
}

Results in:

rustc: /home/losch/Documents/rust-ml/rustc2/src/llvm-project/llvm/include/llvm/IR/Type.h:418: llvm::Type* llvm::Type::getNonOpaquePointerElementType() const: Assertion `NumContainedTys && "Attempting to get element type of opaque pointer"' failed.

I'm currently rebuilding LLVM with RelWithDebInfo for more information, here is a preliminary trace:

after simplification :
; Function Attrs: mustprogress nofree noinline nosync nounwind nonlazybind willreturn memory(argmem: readwrite) uwtable
define internal void @preprocess__ZN3sin11sin_inplace17h49beadd84ee4eb97E(ptr noalias nocapture noundef readonly align 4 dereferenceable(4) %0, ptr noalias nocapture noundef writeonly align 4 dereferenceable(4) %1) unnamed_addr EnzymeAD/Enzyme#1 {
  %3 = load float, ptr %0, align 4, !noundef !4
  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
  store float %4, ptr %1, align 4
  ret void
}

in new function diffe_ZN3sin11sin_inplace17h49beadd84ee4eb97E nonconstant arg ptr %0
in new function diffe_ZN3sin11sin_inplace17h49beadd84ee4eb97E nonconstant arg ptr %2
analyzing function preprocess__ZN3sin11sin_inplace17h49beadd84ee4eb97E
 + knowndata: ptr %0 : {[-1]:Pointer, [-1,-1]:Float@float} - {}
 + knowndata: ptr %1 : {[-1]:Pointer, [-1,-1]:Float@float} - {}
 + retdata: {}
updating analysis of val: ptr %0 current: {} new {[-1]:Pointer, [-1,-1]:Float@float} from ptr %0 Changed=1 legal=1
updating analysis of val: ptr %1 current: {} new {[-1]:Pointer, [-1,-1]:Float@float} from ptr %1 Changed=1 legal=1
updating analysis of val: ptr %0 current: {[-1]:Pointer, [-1,-1]:Float@float} new {[-1]:Pointer, [-1,-1]:Float@float} from ptr %0 Changed=0 legal=1
updating analysis of val: ptr %1 current: {[-1]:Pointer, [-1,-1]:Float@float} new {[-1]:Pointer, [-1,-1]:Float@float} from ptr %1 Changed=0 legal=1
updating analysis of val: ptr %0 current: {[-1]:Pointer, [-1,-1]:Float@float} new {[-1]:Pointer} from   %3 = load float, ptr %0, align 4, !noundef !4 Changed=0 legal=1
updating analysis of val:   %3 = load float, ptr %0, align 4, !noundef !4 current: {} new {[-1]:Float@float} from   %3 = load float, ptr %0, align 4, !noundef !4 Changed=1 legal=1
updating analysis of val:   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 current: {} new {[-1]:Float@float} from   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 Changed=1 legal=1
updating analysis of val:   %3 = load float, ptr %0, align 4, !noundef !4 current: {[-1]:Float@float} new {[-1]:Float@float} from   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 Changed=0 legal=1
updating analysis of val: ptr %1 current: {[-1]:Pointer, [-1,-1]:Float@float} new {[-1]:Pointer, [-1,0]:Float@float} from   store float %4, ptr %1, align 4 Changed=0 legal=1
updating analysis of val:   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 current: {[-1]:Float@float} new {[-1]:Float@float} from   store float %4, ptr %1, align 4 Changed=0 legal=1
updating analysis of val: ptr %0 current: {[-1]:Pointer, [-1,-1]:Float@float} new {[-1]:Pointer, [-1,0]:Float@float} from   %3 = load float, ptr %0, align 4, !noundef !4 Changed=0 legal=1
updating analysis of val:   %3 = load float, ptr %0, align 4, !noundef !4 current: {[-1]:Float@float} new {[-1]:Float@float} from   %3 = load float, ptr %0, align 4, !noundef !4 Changed=0 legal=1
checking if is constant[3]   %3 = load float, ptr %0, align 4, !noundef !4
 < UPSEARCH1>  %3 = load float, ptr %0, align 4, !noundef !4
nonconstant(1)  up-inst   %3 = load float, ptr %0, align 4, !noundef !4 op ptr %0
 <Value USESEARCH2>  %3 = load float, ptr %0, align 4, !noundef !4 UA=None
      considering use of   %3 = load float, ptr %0, align 4, !noundef !4 -   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
      considering use of   %3 = load float, ptr %0, align 4, !noundef !4 -   store float %4, ptr %1, align 4
Value nonconstant inst (uses):  %3 = load float, ptr %0, align 4, !noundef !4 user   store float %4, ptr %1, align 4
 </Value USESEARCH2 const=0>  %3 = load float, ptr %0, align 4, !noundef !4
 Value nonconstant (couldn't disprove)[3]  %3 = load float, ptr %0, align 4, !noundef !4
 <Value USESEARCH2>  %3 = load float, ptr %0, align 4, !noundef !4 UA=None
      considering use of   %3 = load float, ptr %0, align 4, !noundef !4 -   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
      considering use of   %3 = load float, ptr %0, align 4, !noundef !4 -   store float %4, ptr %1, align 4
Value nonconstant inst (uses):  %3 = load float, ptr %0, align 4, !noundef !4 user   store float %4, ptr %1, align 4
 </Value USESEARCH2 const=0>  %3 = load float, ptr %0, align 4, !noundef !4
 < UPSEARCH1>  %3 = load float, ptr %0, align 4, !noundef !4
nonconstant(1)  up-inst   %3 = load float, ptr %0, align 4, !noundef !4 op ptr %0
couldnt decide fallback as nonconstant instruction(3):  %3 = load float, ptr %0, align 4, !noundef !4
  %3 = load float, ptr %0, align 4, !noundef !4 cv=0 ci=0
checking if is constant[3]   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
 < UPSEARCH1>  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
nonconstant(1)  up-call   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 op   %3 = load float, ptr %0, align 4, !noundef !4
 <Value USESEARCH2>  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 UA=None
      considering use of   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 -   store float %4, ptr %1, align 4
Value nonconstant inst (uses):  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 user   store float %4, ptr %1, align 4
 </Value USESEARCH2 const=0>  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
 Value nonconstant (couldn't disprove)[3]  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
 <Value USESEARCH2>  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 UA=None
      considering use of   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 -   store float %4, ptr %1, align 4
Value nonconstant inst (uses):  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 user   store float %4, ptr %1, align 4
 </Value USESEARCH2 const=0>  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
 < UPSEARCH1>  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
nonconstant(1)  up-call   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 op   %3 = load float, ptr %0, align 4, !noundef !4
couldnt decide fallback as nonconstant instruction(3):  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
  %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100 cv=0 ci=0
checking if is constant[3]   store float %4, ptr %1, align 4
 < UPSEARCH1>  store float %4, ptr %1, align 4
nonconstant(1)  up-inst   store float %4, ptr %1, align 4 op   %4 = tail call float @llvm.sin.f32(float %3) EnzymeAD/Enzyme#100
couldnt decide fallback as nonconstant instruction(3):  store float %4, ptr %1, align 4
  store float %4, ptr %1, align 4 cv=1 ci=0
  ret void cv=1 ci=1
; Function Attrs: mustprogress nofree noinline nosync nounwind nonlazybind willreturn memory(argmem: readwrite) uwtable
define internal void @diffe_ZN3sin11sin_inplace17h49beadd84ee4eb97E(ptr noalias nocapture noundef readonly align 4 dereferenceable(4) %0, ptr nocapture %1, ptr noalias nocapture writeonly align 4 dereferenceable(4) %2, ptr nocapture %3) unnamed_addr EnzymeAD/Enzyme#1 {
  %5 = load float, ptr %0, align 4, !alias.scope !47843, !noalias !47846, !noundef !4
  %6 = load float, ptr %3, align 4, !alias.scope !47848, !noalias !47851
  store float 0.000000e+00, ptr %3, align 4, !alias.scope !47848, !noalias !47851
  %7 = call fast float @llvm.cos.f32(float %5)
  %8 = fmul fast float %6, %7
  %9 = load float, ptr %1, align 4, !alias.scope !47846, !noalias !47843
  %10 = fadd fast float %9, %8
  store float %10, ptr %1, align 4, !alias.scope !47846, !noalias !47843
  ret void
}
@wsmoses
Copy link
Member

wsmoses commented May 24, 2023

can you show the backtrace of the error assertion.

@bytesnake
Copy link
Author

got none but I'm rebuilding with RelWithDebInfo now, or do I need to activate something else?

@ZuseZ4
Copy link
Member

ZuseZ4 commented May 24, 2023

That should be enough. Pure Debug build would probably be even slightly better since we have small testcases, but both should work I think.

@wsmoses
Copy link
Member

wsmoses commented May 24, 2023

Yeah I just need to see what line of Enzyme code triggers it.

@bytesnake
Copy link
Author

bytesnake commented May 25, 2023

Setting RelWithDebInfo or debug mode did not help, I will rebuild the compiler from scratch

@bytesnake
Copy link
Author

EnzymeAD/Enzyme#4  0x00007fffe74b99f8 in llvm::Type::getNonOpaquePointerElementType (this=0x7fffdc627bd0)
    at /home/losch/Documents/rust-ml/rustc2/src/llvm-project/llvm/include/llvm/IR/Type.h:418
EnzymeAD/Enzyme#5  0x00007fffe75d1c16 in LLVMGetElementType (WrappedTy=0x7fffdc627bd0)
    at /home/losch/Documents/rust-ml/rustc2/src/llvm-project/llvm/lib/IR/Core.cpp:815
EnzymeAD/Enzyme#6  0x00007ffff464d45a in _RNvNtNtCs8k9sJ7haxZX_18rustc_codegen_llvm4back5write13differentiate ()
   from /home/losch/Documents/rust-ml/rustc2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-2de1a356481e0f08.so
EnzymeAD/Enzyme#7  0x00007ffff4586408 in _RINvNtNtCsaXwx0AdOzVa_17rustc_codegen_ssa4back5write17generate_lto_workNtCs8k9sJ7haxZX_18rustc_codegen_llvm18LlvmCodegenBackendEB19_ ()
   from /home/losch/Documents/rust-ml/rustc2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-2de1a356481e0f08.so
EnzymeAD/Enzyme#8  0x00007ffff4663d64 in _RINvNtNtCsfR9V8ySqyK8_3std10sys_common9backtrace28___rust_begin_short_backtraceNCINvXs0_Cs8k9sJ7haxZX_18rustc_codegen_llvmNtB1o_18LlvmCodegenBackendNtNtNtCsaXwx0AdOzVa_17rustc_codegen_ssa6traits7backend19ExtraBackendMethods12spawn_threadNCINvNtNtB2s_4back5write20start_executing_workB1W_Es2_0INtNtCsfYALMPu6VcR_4core6result6ResultNtB3S_15CompiledModulesuEE0B4G_EB1o_ ()
   from /home/losch/Documents/rust-ml/rustc2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-2de1a356481e0f08.so
EnzymeAD/Enzyme#9  0x00007ffff4668997 in _RNSNvYNCINvMNtCsfR9V8ySqyK8_3std6threadNtBa_7Builder16spawn_unchecked_NCINvXs0_Cs8k9sJ7haxZX_18rustc_codegen_llvmNtB1f_18LlvmCodegenBackendNtNtNtCsaXwx0AdOzVa_17rustc_codegen_ssa6traits7backend19ExtraBackendMethods12spawn_threadNCINvNtNtB2j_4back5write20start_executing_workB1N_Es2_0INtNtCsfYALMPu6VcR_4core6result6ResultNtB3J_15CompiledModulesuEE0B4x_Es_0INtNtNtB4C_3ops8function6FnOnceuE9call_once6vtableB1f_ ()
   from /home/losch/Documents/rust-ml/rustc2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc_driver-2de1a356481e0f08.so
EnzymeAD/Enzyme#10 0x00007ffff3b85fc5 in std::sys::unix::thread::Thread::new::thread_start ()
   from /home/losch/Documents/rust-ml/rustc2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/libstd-bce0a345943e55b3.so
EnzymeAD/Enzyme#11 0x00007fffe4568609 in start_thread (arg=<optimized out>) at pthread_create.c:477
EnzymeAD/Enzyme#12 0x00007ffff39bb133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

@ZuseZ4 ZuseZ4 transferred this issue from EnzymeAD/Enzyme May 25, 2023
@ZuseZ4 ZuseZ4 closed this as completed May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants