-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[SCCP] Refine trunc with nsw/nuw flags #87926
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: opt -passes=ipsccp -S %s | FileCheck %s | ||
dtcxzyw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
define i16 @range_from_and_nuw(i32 %a) { | ||
; CHECK-LABEL: define i16 @range_from_and_nuw( | ||
; CHECK-SAME: i32 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], 65535 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i32 [[AND1]] to i16 | ||
; CHECK-NEXT: ret i16 [[TRUNC1]] | ||
; | ||
entry: | ||
%and1 = and i32 %a, 65535 | ||
%trunc1 = trunc i32 %and1 to i16 | ||
ret i16 %trunc1 | ||
} | ||
|
||
define i8 @range_from_or_nsw(i16 %a) { | ||
; CHECK-LABEL: define i8 @range_from_or_nsw( | ||
; CHECK-SAME: i16 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[AND1:%.*]] = or i16 [[A]], -128 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nsw i16 [[AND1]] to i8 | ||
; CHECK-NEXT: ret i8 [[TRUNC1]] | ||
; | ||
entry: | ||
%and1 = or i16 %a, 65408 | ||
%trunc1 = trunc i16 %and1 to i8 | ||
ret i8 %trunc1 | ||
} | ||
|
||
define i16 @range_from_and_nuw_nsw(i32 %a) { | ||
; CHECK-LABEL: define i16 @range_from_and_nuw_nsw( | ||
; CHECK-SAME: i32 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[AND1:%.*]] = and i32 [[A]], 32767 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw nsw i32 [[AND1]] to i16 | ||
; CHECK-NEXT: ret i16 [[TRUNC1]] | ||
; | ||
entry: | ||
%and1 = and i32 %a, 32767 | ||
%trunc1 = trunc i32 %and1 to i16 | ||
ret i16 %trunc1 | ||
} | ||
|
||
define <4 x i16> @range_from_and_nuw_vec(<4 x i32> %a) { | ||
; CHECK-LABEL: define <4 x i16> @range_from_and_nuw_vec( | ||
; CHECK-SAME: <4 x i32> [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[AND1:%.*]] = and <4 x i32> [[A]], <i32 65535, i32 65535, i32 65535, i32 65535> | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc <4 x i32> [[AND1]] to <4 x i16> | ||
; CHECK-NEXT: ret <4 x i16> [[TRUNC1]] | ||
; | ||
entry: | ||
%and1 = and <4 x i32> %a, <i32 65535, i32 65535, i32 65535, i32 65535> | ||
%trunc1 = trunc <4 x i32> %and1 to <4 x i16> | ||
ret <4 x i16> %trunc1 | ||
} | ||
|
||
define i4 @range_from_sge_sle(i8 %a) { | ||
; CHECK-LABEL: define i4 @range_from_sge_sle( | ||
; CHECK-SAME: i8 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[SGT:%.*]] = icmp sge i8 [[A]], 0 | ||
; CHECK-NEXT: [[SLT:%.*]] = icmp sle i8 [[A]], 15 | ||
; CHECK-NEXT: [[AND:%.*]] = and i1 [[SGT]], [[SLT]] | ||
; CHECK-NEXT: br i1 [[AND]], label [[THEN:%.*]], label [[ELSE:%.*]] | ||
; CHECK: then: | ||
; CHECK-NEXT: [[AND1:%.*]] = and i8 [[A]], 7 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i8 [[A]] to i4 | ||
; CHECK-NEXT: [[TRUNC2:%.*]] = trunc nuw nsw i8 [[AND1]] to i4 | ||
; CHECK-NEXT: [[XOR1:%.*]] = xor i4 [[TRUNC1]], [[TRUNC2]] | ||
; CHECK-NEXT: ret i4 [[XOR1]] | ||
; CHECK: else: | ||
; CHECK-NEXT: [[TRUNC3:%.*]] = trunc i8 [[A]] to i4 | ||
; CHECK-NEXT: ret i4 [[TRUNC3]] | ||
; | ||
entry: | ||
%sgt = icmp sge i8 %a, 0 | ||
%slt = icmp sle i8 %a, 15 | ||
%and = and i1 %sgt, %slt | ||
br i1 %and, label %then, label %else | ||
|
||
then: | ||
%and1 = and i8 %a, 7 | ||
|
||
%trunc1 = trunc i8 %a to i4 | ||
%trunc2 = trunc i8 %and1 to i4 | ||
%xor1 = xor i4 %trunc1, %trunc2 | ||
ret i4 %xor1 | ||
|
||
else: | ||
%trunc3 = trunc i8 %a to i4 | ||
ret i4 %trunc3 | ||
} | ||
|
||
define i16 @range_from_sext(i16 %a) { | ||
; CHECK-LABEL: define i16 @range_from_sext( | ||
; CHECK-SAME: i16 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[SEXT1:%.*]] = sext i16 [[A]] to i32 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nsw i32 [[SEXT1]] to i16 | ||
; CHECK-NEXT: ret i16 [[TRUNC1]] | ||
; | ||
entry: | ||
%sext1 = sext i16 %a to i32 | ||
%trunc1 = trunc i32 %sext1 to i16 | ||
ret i16 %trunc1 | ||
} | ||
|
||
define i16 @range_from_zext(i16 %a) { | ||
; CHECK-LABEL: define i16 @range_from_zext( | ||
; CHECK-SAME: i16 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[ZEXT1:%.*]] = zext i16 [[A]] to i32 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i32 [[ZEXT1]] to i16 | ||
; CHECK-NEXT: ret i16 [[TRUNC1]] | ||
; | ||
entry: | ||
%zext1 = zext i16 %a to i32 | ||
%trunc1 = trunc i32 %zext1 to i16 | ||
ret i16 %trunc1 | ||
} | ||
|
||
define i1 @range_from_select_i1_nuw(i1 %c) { | ||
; CHECK-LABEL: define i1 @range_from_select_i1_nuw( | ||
; CHECK-SAME: i1 [[C:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[C]], i16 0, i16 1 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nuw i16 [[SELECT1]] to i1 | ||
; CHECK-NEXT: ret i1 [[TRUNC1]] | ||
; | ||
entry: | ||
%select1 = select i1 %c, i16 0, i16 1 | ||
%trunc1 = trunc i16 %select1 to i1 | ||
ret i1 %trunc1 | ||
} | ||
|
||
define i1 @range_from_select_i1_nsw(i1 %c) { | ||
; CHECK-LABEL: define i1 @range_from_select_i1_nsw( | ||
; CHECK-SAME: i1 [[C:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[C]], i16 0, i16 -1 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc nsw i16 [[SELECT1]] to i1 | ||
; CHECK-NEXT: ret i1 [[TRUNC1]] | ||
; | ||
entry: | ||
%select1 = select i1 %c, i16 0, i16 -1 | ||
%trunc1 = trunc i16 %select1 to i1 | ||
ret i1 %trunc1 | ||
} | ||
|
||
define i1 @range_from_select_i1_fail(i1 %c) { | ||
; CHECK-LABEL: define i1 @range_from_select_i1_fail( | ||
; CHECK-SAME: i1 [[C:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[SELECT1:%.*]] = select i1 [[C]], i16 1, i16 -1 | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc i16 [[SELECT1]] to i1 | ||
; CHECK-NEXT: ret i1 [[TRUNC1]] | ||
; | ||
entry: | ||
%select1 = select i1 %c, i16 1, i16 -1 | ||
%trunc1 = trunc i16 %select1 to i1 | ||
ret i1 %trunc1 | ||
} | ||
|
||
define i8 @range_from_trunc_fail(i32 %a) { | ||
; CHECK-LABEL: define i8 @range_from_trunc_fail( | ||
; CHECK-SAME: i32 [[A:%.*]]) { | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: [[TRUNC1:%.*]] = trunc i32 [[A]] to i16 | ||
; CHECK-NEXT: [[TRUNC2:%.*]] = trunc i16 [[TRUNC1]] to i8 | ||
; CHECK-NEXT: ret i8 [[TRUNC2]] | ||
; | ||
entry: | ||
%trunc1 = trunc i32 %a to i16 | ||
%trunc2 = trunc i16 %trunc1 to i8 | ||
ret i8 %trunc2 | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.