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

[FuncAttrs] volatile memcpy should not be eliminated #120932

Open
dtcxzyw opened this issue Dec 23, 2024 · 0 comments
Open

[FuncAttrs] volatile memcpy should not be eliminated #120932

dtcxzyw opened this issue Dec 23, 2024 · 0 comments

Comments

@dtcxzyw
Copy link
Member

dtcxzyw commented Dec 23, 2024

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

; bin/opt -O3 test.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.S0 = type { i32, i32, i64, i16 }

@g_148 = constant %struct.S0 { i32 568401685, i32 -1, i64 -1, i16 -1 }

define i32 @main() {
entry:
  %call2 = call i32 @func_127()
  ret i32 0
}

define i32 @func_127() {
entry:
  %call241 = call ptr @func_144(ptr null)
  %call58 = call i32 @func_139(ptr %call241)
  ret i32 0
}

define internal i32 @func_139(ptr %p_140) {
entry:
  ret i32 0
}

define ptr @func_144(ptr %p_145) {
entry:
  %agg.tmp.ensured = alloca %struct.S0, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr %agg.tmp.ensured, ptr @g_148, i64 24, i1 true)
  ret ptr %p_145
}

Output:

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

define noundef i32 @main() local_unnamed_addr #0 {
  ret i32 0
}

define noundef i32 @func_127() local_unnamed_addr #0 {
  ret i32 0
}

define ptr @func_144(ptr readnone returned %p_145) local_unnamed_addr #0 {
  %agg.tmp.ensured = alloca %struct.S0, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull %agg.tmp.ensured, ptr @g_148, i64 24, i1 true)
  ret ptr %p_145
}

declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

The memory effect of func_144 should not be memory(none).

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

No branches or pull requests

1 participant