Issue 120932
Summary [FuncAttrs] volatile memcpy should not be eliminated
Labels miscompilation, llvm::Attributor
Assignees
Reporter dtcxzyw
    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)`.


_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to