-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MemCpyOpt] Avoid infinite loops in MemCpyOptPass::processMemCpyMemCpyDependence
#103218
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt -S -passes=memcpyopt < %s | FileCheck %s | ||
|
||
@g1 = external global i8 | ||
@g2 = external global [64 x i8] | ||
@g3 = global i8 0, align 1 | ||
|
||
define void @func() { | ||
; CHECK-LABEL: define void @func() { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g2, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g2, i64 16), i64 20, i1 false) | ||
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr @g1, ptr getelementptr inbounds (i8, ptr @g2, i64 24), i64 1, i1 false) | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
call void @llvm.memcpy.p0.p0.i64(ptr getelementptr inbounds (i8, ptr @g2, i64 16), ptr getelementptr inbounds nuw (i8, ptr @g2, i64 16), i64 20, i1 false) | ||
call void @llvm.memcpy.p0.p0.i64(ptr @g1, ptr getelementptr inbounds (i8, ptr @g2, i64 24), i64 1, i1 false) | ||
ret void | ||
} | ||
|
||
define void @func2(ptr %p) { | ||
; CHECK-LABEL: define void @func2( | ||
; CHECK-SAME: ptr [[P:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[P]], i64 32 | ||
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[P]], i64 34 | ||
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[P]], i64 32 | ||
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[GEP1]], ptr [[GEP3]], i64 32, i1 false) | ||
; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr @g3, ptr [[GEP2]], i64 1, i1 false) | ||
; CHECK-NEXT: ret void | ||
; | ||
entry: | ||
%gep1 = getelementptr i8, ptr %p, i64 32 | ||
%gep2 = getelementptr i8, ptr %p, i64 34 | ||
%gep3 = getelementptr i8, ptr %p, i64 32 | ||
call void @llvm.memcpy.p0.p0.i64(ptr %gep1, ptr %gep3, i64 32, i1 false) | ||
call void @llvm.memcpy.p0.p0.i64(ptr @g3, ptr %gep2, i64 1, i1 false) | ||
ret void | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already is a
M->getSource() == MDep->getSource()
check above. Can we change that one?Also, do you think it would make sense to also remove the no-op memcpy, if we already have to check for them anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to change this check into
BAA.isMustAlias(M->getSource(), MDep->getSource())
. But it doesn't work.Yeah, it's definitely a better approach. But before doing this, we should prove that
ptr getelementptr inbounds (i8, ptr @g2, i64 16)
andptr getelementptr inbounds nuw (i8, ptr @g2, i64 16)
must alias.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to should be
BAA.isMustAlias(MDep->getDest(), MDep->getSource())
#140376.This should already must alias, and it seems we can handle it before
processMemCpyMemCpyDependence
.