LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 44388 - memcpyopt adds incorrect align to memset
Summary: memcpyopt adds incorrect align to memset
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-27 08:46 PST by Juneyoung Lee
Modified: 2020-02-05 13:45 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
memset.src.ll (449 bytes, text/plain)
2019-12-27 08:46 PST, Juneyoung Lee
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Juneyoung Lee 2019-12-27 08:46:06 PST
Created attachment 22966 [details]
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.
Comment 1 Juneyoung Lee 2020-02-05 13:45:40 PST
Fixed (https://reviews.llvm.org/D74083)