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

[MemcpyOpt] Infinite loops when forwarding memcpy on globals #102994

Closed
dtcxzyw opened this issue Aug 13, 2024 · 0 comments · Fixed by #103218
Closed

[MemcpyOpt] Infinite loops when forwarding memcpy on globals #102994

dtcxzyw opened this issue Aug 13, 2024 · 0 comments · Fixed by #103218
Assignees
Labels
llvm:hang Compiler hang (infinite loop) llvm:transforms

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Aug 13, 2024

Reproducer: https://godbolt.org/z/GKzGEKE18

; bin/opt -passes=memcpyopt reduced.ll -S
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.S1 = type { i64, i16, i32, %struct.S0, i8, i32, i8, i32, i8 }
%struct.S0 = type { i32, i32, i32, i32, i16 }

@g = external global i8
@g_265 = external global %struct.S1

define void @func() {
entry:
  call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr @g_265, i64 24), i64 1, i1 false)
  ret void
}
Found roots: %entry 
Clobber starting at access 1 = MemoryDef(liveOnEntry)
  for instruction   call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  is 0 = MemoryDef(liveOnEntry)
Clobber starting at access 1 = MemoryDef(liveOnEntry)
  for instruction   call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  is 1 = MemoryDef(liveOnEntry)
Clobber starting at access 1 = MemoryDef(liveOnEntry)
  for instruction   call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  is 1 = MemoryDef(liveOnEntry)
MemCpyOptPass: Forwarding memcpy->memcpy src:
  call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr @g_265, i64 24), i64 1, i1 false)
Clobber starting at access 1 = MemoryDef(liveOnEntry)
  for instruction   call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  is 0 = MemoryDef(liveOnEntry)
Clobber starting at access 1 = MemoryDef(liveOnEntry)
  for instruction   call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  is 1 = MemoryDef(liveOnEntry)
Clobber starting at access 1 = MemoryDef(liveOnEntry)
  for instruction   call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  is 1 = MemoryDef(liveOnEntry)
MemCpyOptPass: Forwarding memcpy->memcpy src:
  call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g_265, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 20, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr @g, ptr getelementptr inbounds (i8, ptr getelementptr inbounds nuw (i8, ptr @g_265, i64 16), i64 8), i64 1, i1 false)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:hang Compiler hang (infinite loop) llvm:transforms
Projects
None yet
2 participants