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

julia.loopinfo_marker can be attaced to wrong loop. #50660

Closed
vchuravy opened this issue Jul 24, 2023 · 0 comments · Fixed by #50663
Closed

julia.loopinfo_marker can be attaced to wrong loop. #50660

vchuravy opened this issue Jul 24, 2023 · 0 comments · Fixed by #50663
Labels
compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM compiler:simd instruction-level vectorization

Comments

@vchuravy
Copy link
Member

Noticed by @lcw in JuliaGPU/KernelAbstractions.jl#411

Using the snippet in the PR above we see:

➜  julia JULIA_LLVM_ARGS="-debug-only=lower_simd_loop" ./julia --project=~/src/KernelAbstractions ~/src/KernelAbstractions/codegen.jl
LSL: loopinfo marker found
LSL: loop header: 
L2:                                               ; preds = %L2, %top
  %value_phi = phi i64 [ 1, %top ], [ %7, %L2 ]
  %2 = sitofp i64 %value_phi to double, !dbg !30
  %3 = add i64 %value_phi, -1, !dbg !37
  %4 = bitcast {} addrspace(10)* %"a::Array" to double addrspace(13)* addrspace(10)*, !dbg !37
  %5 = addrspacecast double addrspace(13)* addrspace(10)* %4 to double addrspace(13)* addrspace(11)*, !dbg !37
  %.data10 = load double addrspace(13)*, double addrspace(13)* addrspace(11)* %5, align 8, !dbg !37, !tbaa !46, !alias.scope !49, !noalias !52, !nonnull !11
  %6 = getelementptr inbounds double, double addrspace(13)* %.data10, i64 %3, !dbg !37
  store double %2, double addrspace(13)* %6, align 8, !dbg !37, !tbaa !57, !alias.scope !60, !noalias !61
  call void @julia.loopinfo_marker(), !dbg !62, !julia.loopinfo !63
  %.not.not = icmp eq i64 %value_phi, 1000, !dbg !65
  %7 = add i64 %value_phi, 1, !dbg !68
  br i1 %.not.not, label %L20, label %L2, !dbg !71

LSL: has julia.loopinfo metadata with 1 operands
LSL: simd: 0 ivdep: 0

The Loop is not in in idiom form (e.g loop header and latch are collapsed into one BB) and simplifycfg eliminated the inner loop.

This issue could also occur with @simd and thus cause miscompilations.

@vchuravy vchuravy added compiler:codegen Generation of LLVM IR and native code compiler:simd instruction-level vectorization compiler:llvm For issues that relate to LLVM labels Jul 24, 2023
vchuravy added a commit that referenced this issue Aug 14, 2023
We used a loop-marker intrinsic because the LoopID used to
be dropped by optimization passes (this seems no longer true).

#50660 is an example of a miscompilation where a loop of length 1
got optimized by simplifycfg to the point where the loop-marker
is now attached to the wrong back-edge.

This PR drops the loop-marker and uses the LoopID metadata node
directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM compiler:simd instruction-level vectorization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant