-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Add known and demanded bits support for zext nneg #70858
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1103,6 +1103,9 @@ static void computeKnownBitsFromOperator(const Operator *I, | |||
| assert(SrcBitWidth && "SrcBitWidth can't be zero"); | ||||
| Known = Known.anyextOrTrunc(SrcBitWidth); | ||||
| computeKnownBits(I->getOperand(0), Known, Depth + 1, Q); | ||||
| if (auto *Inst = dyn_cast<PossiblyNonNegInst>(I); | ||||
| Inst && Inst->hasNonNeg() && !Known.isNegative()) | ||||
| Known.makeNonNegative(); | ||||
|
||||
| if (isKnownNonNegative && !Known.isNegative()) |
!Known.isNegative() check first.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -795,9 +795,8 @@ define i16 @zext_nneg_flag_drop(i8 %x, i16 %y) { | |
|
|
||
| define i32 @zext_nneg_redundant_and(i8 %a) { | ||
| ; CHECK-LABEL: @zext_nneg_redundant_and( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[A:%.*]], 127 | ||
| ; CHECK-NEXT: [[RES:%.*]] = zext i8 [[TMP1]] to i32 | ||
| ; CHECK-NEXT: ret i32 [[RES]] | ||
| ; CHECK-NEXT: [[A_I32:%.*]] = zext nneg i8 [[A:%.*]] to i32 | ||
| ; CHECK-NEXT: ret i32 [[A_I32]] | ||
| ; | ||
| %a.i32 = zext nneg i8 %a to i32 | ||
| %res = and i32 %a.i32, 127 | ||
|
|
@@ -818,20 +817,19 @@ define i32 @zext_nneg_redundant_and_neg(i8 %a) { | |
|
|
||
| define i64 @zext_nneg_signbit_extract(i32 %a) nounwind { | ||
| ; CHECK-LABEL: @zext_nneg_signbit_extract( | ||
| ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[A:%.*]], 31 | ||
| ; CHECK-NEXT: [[C:%.*]] = zext i32 [[TMP1]] to i64 | ||
| ; CHECK-NEXT: ret i64 [[C]] | ||
| ; CHECK-NEXT: ret i64 0 | ||
| ; | ||
| %b = zext nneg i32 %a to i64 | ||
| %c = lshr i64 %b, 31 | ||
| ret i64 %c | ||
| } | ||
|
|
||
| define i64 @zext_nneg_demanded_constant(i8 %a) nounwind { | ||
| ; | ||
|
||
| ; CHECK-LABEL: @zext_nneg_demanded_constant( | ||
| ; CHECK-NEXT: [[B:%.*]] = zext nneg i8 [[A:%.*]] to i64 | ||
| ; CHECK-NEXT: call void @use64(i64 [[B]]) #[[ATTR0:[0-9]+]] | ||
| ; CHECK-NEXT: [[C:%.*]] = and i64 [[B]], 254 | ||
| ; CHECK-NEXT: [[C:%.*]] = and i64 [[B]], 126 | ||
| ; CHECK-NEXT: ret i64 [[C]] | ||
| ; | ||
| %b = zext nneg i8 %a to i64 | ||
|
|
||
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.
nit; imo should move this statement to before the if and use
&&.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.
Not sure what you're suggesting? Why would I want to expand the scope of the Inst variable?
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.
Guess the syntax
if (A = expr; other_stuff...)is a pretty abnormal pattern and imo prone to be misread, but its a nit and nikics approved so no need to change if you feel otherwise.