-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[InstCombine] Narrow trunc(lshr) in more cases #139645
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
bc37712
92e1943
8a14c69
88d6028
2b17e85
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 |
|---|---|---|
|
|
@@ -51,6 +51,8 @@ Value *InstCombinerImpl::EvaluateInDifferentType(Value *V, Type *Ty, | |
| Value *LHS = EvaluateInDifferentType(I->getOperand(0), Ty, isSigned); | ||
| Value *RHS = EvaluateInDifferentType(I->getOperand(1), Ty, isSigned); | ||
| Res = BinaryOperator::Create((Instruction::BinaryOps)Opc, LHS, RHS); | ||
| if (Opc == Instruction::LShr || Opc == Instruction::AShr) | ||
| Res->setIsExact(I->isExact()); | ||
| break; | ||
| } | ||
| case Instruction::Trunc: | ||
|
|
@@ -319,13 +321,21 @@ static bool canEvaluateTruncated(Value *V, Type *Ty, InstCombinerImpl &IC, | |
| // zero - use AmtKnownBits.getMaxValue(). | ||
| uint32_t OrigBitWidth = OrigTy->getScalarSizeInBits(); | ||
| uint32_t BitWidth = Ty->getScalarSizeInBits(); | ||
| KnownBits AmtKnownBits = | ||
| llvm::computeKnownBits(I->getOperand(1), IC.getDataLayout()); | ||
| KnownBits AmtKnownBits = IC.computeKnownBits(I->getOperand(1), 0, CxtI); | ||
| APInt MaxShiftAmt = AmtKnownBits.getMaxValue(); | ||
| APInt ShiftedBits = APInt::getBitsSetFrom(OrigBitWidth, BitWidth); | ||
| if (AmtKnownBits.getMaxValue().ult(BitWidth) && | ||
| IC.MaskedValueIsZero(I->getOperand(0), ShiftedBits, 0, CxtI)) { | ||
| return canEvaluateTruncated(I->getOperand(0), Ty, IC, CxtI) && | ||
| canEvaluateTruncated(I->getOperand(1), Ty, IC, CxtI); | ||
| if (MaxShiftAmt.ult(BitWidth)) { | ||
| if (IC.MaskedValueIsZero(I->getOperand(0), ShiftedBits, 0, CxtI)) | ||
| return canEvaluateTruncated(I->getOperand(0), Ty, IC, CxtI) && | ||
| canEvaluateTruncated(I->getOperand(1), Ty, IC, CxtI); | ||
| // If the only user is a trunc then we can narrow the shift if any new | ||
| // MSBs are not going to be used. | ||
| if (auto *Trunc = dyn_cast<TruncInst>(V->user_back())) { | ||
UsmanNadeem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| auto DemandedBits = Trunc->getType()->getScalarSizeInBits(); | ||
| if (MaxShiftAmt.ule(BitWidth - DemandedBits)) | ||
|
||
| return canEvaluateTruncated(I->getOperand(0), Ty, IC, CxtI) && | ||
| canEvaluateTruncated(I->getOperand(1), Ty, IC, CxtI); | ||
| } | ||
| } | ||
| break; | ||
| } | ||
|
|
||
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 change looks unrelated. Is it necessary to avoid regression?
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, some other tests regress without it.