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 adds incorrect align to memset #43733

Closed
aqjune opened this issue Dec 27, 2019 · 1 comment
Closed

memcpyopt adds incorrect align to memset #43733

aqjune opened this issue Dec 27, 2019 · 1 comment
Labels
bugzilla Issues migrated from bugzilla

Comments

@aqjune
Copy link
Contributor

aqjune commented Dec 27, 2019

Bugzilla Link 44388
Resolution FIXED
Resolved on Feb 05, 2020 13:45
Version trunk
OS All
Attachments memset.src.ll
CC @nunoplopes,@lenary

Extended Description

$ 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.

@aqjune
Copy link
Contributor Author

aqjune commented Feb 5, 2020

Fixed (https://reviews.llvm.org/D74083)

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

1 participant