Skip to content

Commit bc730b5

Browse files
committed
[InstCombine] collectBitParts - use APInt directly to check for out of range bit shifts. NFCI.
1 parent ef4e971 commit bc730b5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,10 +2872,10 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
28722872

28732873
// If this is a logical shift by a constant, recurse then shift the result.
28742874
if (I->isLogicalShift() && isa<ConstantInt>(I->getOperand(1))) {
2875-
unsigned BitShift =
2876-
cast<ConstantInt>(I->getOperand(1))->getLimitedValue(~0U);
2875+
const APInt &BitShift = cast<ConstantInt>(I->getOperand(1))->getValue();
2876+
28772877
// Ensure the shift amount is defined.
2878-
if (BitShift > BitWidth)
2878+
if (BitShift.uge(BitWidth))
28792879
return Result;
28802880

28812881
const auto &Res = collectBitParts(I->getOperand(0), MatchBSwaps,
@@ -2887,11 +2887,11 @@ collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
28872887
// Perform the "shift" on BitProvenance.
28882888
auto &P = Result->Provenance;
28892889
if (I->getOpcode() == Instruction::Shl) {
2890-
P.erase(std::prev(P.end(), BitShift), P.end());
2891-
P.insert(P.begin(), BitShift, BitPart::Unset);
2890+
P.erase(std::prev(P.end(), BitShift.getZExtValue()), P.end());
2891+
P.insert(P.begin(), BitShift.getZExtValue(), BitPart::Unset);
28922892
} else {
2893-
P.erase(P.begin(), std::next(P.begin(), BitShift));
2894-
P.insert(P.end(), BitShift, BitPart::Unset);
2893+
P.erase(P.begin(), std::next(P.begin(), BitShift.getZExtValue()));
2894+
P.insert(P.end(), BitShift.getZExtValue(), BitPart::Unset);
28952895
}
28962896

28972897
return Result;

0 commit comments

Comments
 (0)