https://bugs.llvm.org/show_bug.cgi?id=44388

            Bug ID: 44388
           Summary: memcpyopt adds incorrect align to memset
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

Created attachment 22966
  --> https://bugs.llvm.org/attachment.cgi?id=22966&action=edit
memset.src.ll

```
$ cat memset.src.ll 
; Transforms/MemCpyOpt/form-memset.ll

define void @test6(i32* nocapture %P) nounwind ssp {
entry:
  %0 = bitcast i32* %P to i8*
  tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 12, i1 false)
  %add.ptr = getelementptr inbounds i32, i32* %P, i64 3
  %1 = bitcast i32* %add.ptr to i8*
  tail call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 12, i1 false)
  ret void
}

declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
$ ../llvm/build/bin/opt -memcpyopt memset.src.ll -S -o -
; ModuleID = 'memset.src.ll'
source_filename = "memset.src.ll"
; Function Attrs: nounwind ssp
define void @test6(i32* nocapture %P) #0 {
entry:
  %0 = bitcast i32* %P to i8*
  %add.ptr = getelementptr inbounds i32, i32* %P, i64 3
  %1 = bitcast i32* %add.ptr to i8*
  %2 = bitcast i32* %P to i8*
  call void @llvm.memset.p0i8.i64(i8* align 4 %2, i8 0, i64 24, i1 false)
  ret void
}
; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
#1

attributes #0 = { nounwind ssp }
attributes #1 = { argmemonly nounwind willreturn }
```

memcpyopt merges two memsets if they overlap and write the same value.
After merging, align 4 is added, which is incorrect because %P is not
guaranteed to have alignment 4.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to