-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[CVP] Use at-use info in processBinOp
#88523
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 |
---|---|---|
|
@@ -596,3 +596,37 @@ define i16 @and_elide_poison_flags_missing_noundef(i16 %a) { | |
%sel = select i1 %cmp, i16 %and, i16 24 | ||
ret i16 %sel | ||
} | ||
|
||
define i32 @pr87854(i32 noundef %x.1, i32 noundef %i) { | ||
; CHECK-LABEL: @pr87854( | ||
; CHECK-NEXT: [[COND:%.*]] = icmp sgt i32 [[X_1:%.*]], -1 | ||
; CHECK-NEXT: tail call void @llvm.assume(i1 [[COND]]) | ||
; CHECK-NEXT: [[INBOUNDS:%.*]] = icmp ult i32 [[I:%.*]], [[X_1]] | ||
; CHECK-NEXT: [[NEXT:%.*]] = add nuw i32 [[I]], 1 | ||
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[INBOUNDS]], i32 [[NEXT]], i32 -1 | ||
; CHECK-NEXT: ret i32 [[SPEC_SELECT]] | ||
; | ||
%cond = icmp sgt i32 %x.1, -1 | ||
tail call void @llvm.assume(i1 %cond) | ||
%inbounds = icmp ult i32 %i, %x.1 | ||
%next = add i32 %i, 1 | ||
%spec.select = select i1 %inbounds, i32 %next, i32 -1 | ||
ret i32 %spec.select | ||
} | ||
|
||
define i64 @test_shl_nsw_at_use(i64 noundef %x) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be folded by instcombine later: https://godbolt.org/z/4MGsvnsnT |
||
; CHECK-LABEL: @test_shl_nsw_at_use( | ||
; CHECK-NEXT: [[ADD:%.*]] = add i64 [[X:%.*]], 2147483648 | ||
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i64 [[ADD]], 4294967296 | ||
; CHECK-NEXT: [[SHL:%.*]] = shl nsw i64 [[X]], 32 | ||
; CHECK-NEXT: [[SHR:%.*]] = ashr exact i64 [[SHL]], 32 | ||
; CHECK-NEXT: [[RES:%.*]] = select i1 [[CMP]], i64 [[SHR]], i64 0 | ||
; CHECK-NEXT: ret i64 [[RES]] | ||
; | ||
%add = add i64 %x, 2147483648 | ||
%cmp = icmp ult i64 %add, 4294967296 | ||
%shl = shl i64 %x, 32 | ||
%shr = ashr exact i64 %shl, 32 | ||
%res = select i1 %cmp, i64 %shr, i64 0 | ||
ret i64 %res | ||
} |
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
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.
I don't know why the nsw flag cannot be inferred from the assumption.
intersectAssumeOrGuardBlockValueConstantRange
should handle this case.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 don't think
intersectAssumeOrGuardBlockValueConstantRange
should be the one getting thensw
, its the select that enables it.but either way, I think the issue is that
UseBlockValue
is false so we don't actually compute the%x.1
CR when evaluating theinbounds
cmp.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.
As an aside, we may want to test increasing
const unsigned MaxUsesToInspect = 3;
. Seems startlingly.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.
Yes, we don't use block values when deriving information from select conditions right now. I'm not sure doing this is viable, especially in the at-use logic.