-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[LoopIdiom] Update strlen idiom body loop condition to be clean up by LoopDeletion #134906
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,43 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -S -passes=loop-idiom,loop-deletion | FileCheck %s | ||
|
||
define [2 x i64] @convert_null_terminated_to_bounded_ptr(ptr noundef %p) { | ||
; CHECK-LABEL: define [2 x i64] @convert_null_terminated_to_bounded_ptr( | ||
; CHECK-SAME: ptr noundef [[P:%.*]]) { | ||
; CHECK-NEXT: [[ENTRY:.*:]] | ||
; CHECK-NEXT: [[WCSLEN:%.*]] = call i64 @wcslen(ptr [[P]]) | ||
; CHECK-NEXT: br label %[[TERMINATED_BY_LOOP_END:.*]] | ||
; CHECK: [[TERMINATED_BY_LOOP_END]]: | ||
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i32, ptr [[P]], i64 [[WCSLEN]] | ||
; CHECK-NEXT: [[TERMINATED_BY_UPPER:%.*]] = getelementptr i8, ptr [[TMP0]], i64 4 | ||
; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint ptr [[P]] to i64 | ||
; CHECK-NEXT: [[DOTFCA_0_INSERT:%.*]] = insertvalue [2 x i64] poison, i64 [[TMP1]], 0 | ||
; CHECK-NEXT: [[TMP2:%.*]] = ptrtoint ptr [[TERMINATED_BY_UPPER]] to i64 | ||
; CHECK-NEXT: [[DOTFCA_1_INSERT:%.*]] = insertvalue [2 x i64] [[DOTFCA_0_INSERT]], i64 [[TMP2]], 1 | ||
; CHECK-NEXT: ret [2 x i64] [[DOTFCA_1_INSERT]] | ||
; | ||
entry: | ||
br label %terminated_by.loop_cond | ||
|
||
terminated_by.loop_cond: ; preds = %terminated_by.loop_cond, %entry | ||
%terminated_by.len.0 = phi i64 [ 0, %entry ], [ %terminated_by.new_len, %terminated_by.loop_cond ] | ||
%0 = getelementptr inbounds i32, ptr %p, i64 %terminated_by.len.0 | ||
%terminated_by.elem = load i32, ptr %0, align 4 | ||
%terminted_by.check_terminator = icmp eq i32 %terminated_by.elem, 0 | ||
%terminated_by.new_len = add i64 %terminated_by.len.0, 1 | ||
br i1 %terminted_by.check_terminator, label %terminated_by.loop_end, label %terminated_by.loop_cond | ||
|
||
terminated_by.loop_end: ; preds = %terminated_by.loop_cond | ||
%1 = getelementptr inbounds i32, ptr %p, i64 %terminated_by.len.0 | ||
%terminated_by.upper = getelementptr i8, ptr %1, i64 4 | ||
%2 = ptrtoint ptr %p to i64 | ||
%.fca.0.insert = insertvalue [2 x i64] poison, i64 %2, 0 | ||
%3 = ptrtoint ptr %terminated_by.upper to i64 | ||
%.fca.1.insert = insertvalue [2 x i64] %.fca.0.insert, i64 %3, 1 | ||
ret [2 x i64] %.fca.1.insert | ||
} | ||
|
||
!llvm.module.flags = !{!0} | ||
|
||
!0 = !{i32 1, !"wchar_size", i32 4} | ||
|
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
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
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.
Consider adding a comment explaining that this intends to make the old code unreachable/dead.
Add
assert
that at least one of the successors isLoopBody
?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.
Thanks for taking a look. I added the asserts and comments.
I will take a look to see if there's any further testing required.