Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions llvm/include/llvm/IR/PatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1013,12 +1013,13 @@ struct bind_const_intval_ty {
bind_const_intval_ty(uint64_t &V) : VR(V) {}

template <typename ITy> bool match(ITy *V) const {
if (const auto *CV = dyn_cast<ConstantInt>(V))
if (CV->getValue().ule(UINT64_MAX)) {
VR = CV->getZExtValue();
return true;
}
return false;
const APInt *ConstInt;
if (!apint_match(ConstInt, /*AllowPoison=*/false).match(V))
return false;
if (ConstInt->ugt(UINT64_MAX))
return false;
VR = ConstInt->getZExtValue();
return true;
}
};

Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,9 @@ auto HvxIdioms::matchFxpMul(Instruction &In) const -> std::optional<FxpOp> {
return m_CombineOr(m_LShr(V, S), m_AShr(V, S));
};

const APInt *Qn = nullptr;
if (Value * T; match(Exp, m_Shr(m_Value(T), m_APInt(Qn)))) {
Op.Frac = Qn->getZExtValue();
uint64_t Qn = 0;
if (Value *T; match(Exp, m_Shr(m_Value(T), m_ConstantInt(Qn)))) {
Op.Frac = Qn;
Exp = T;
} else {
Op.Frac = 0;
Expand All @@ -1689,9 +1689,9 @@ auto HvxIdioms::matchFxpMul(Instruction &In) const -> std::optional<FxpOp> {
return std::nullopt;

// Check if there is rounding added.
const APInt *C = nullptr;
if (Value * T; Op.Frac > 0 && match(Exp, m_Add(m_Value(T), m_APInt(C)))) {
uint64_t CV = C->getZExtValue();
uint64_t CV;
if (Value *T;
Op.Frac > 0 && match(Exp, m_Add(m_Value(T), m_ConstantInt(CV)))) {
if (CV != 0 && !isPowerOf2_64(CV))
return std::nullopt;
if (CV != 0)
Expand Down
11 changes: 5 additions & 6 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,11 +1131,10 @@ static bool canEvaluateZExtd(Value *V, Type *Ty, unsigned &BitsToClear,
case Instruction::Shl: {
// We can promote shl(x, cst) if we can promote x. Since shl overwrites the
// upper bits we can reduce BitsToClear by the shift amount.
const APInt *Amt;
if (match(I->getOperand(1), m_APInt(Amt))) {
uint64_t ShiftAmt;
if (match(I->getOperand(1), m_ConstantInt(ShiftAmt))) {
if (!canEvaluateZExtd(I->getOperand(0), Ty, BitsToClear, IC, CxtI))
return false;
uint64_t ShiftAmt = Amt->getZExtValue();
BitsToClear = ShiftAmt < BitsToClear ? BitsToClear - ShiftAmt : 0;
return true;
}
Expand All @@ -1144,11 +1143,11 @@ static bool canEvaluateZExtd(Value *V, Type *Ty, unsigned &BitsToClear,
case Instruction::LShr: {
// We can promote lshr(x, cst) if we can promote x. This requires the
// ultimate 'and' to clear out the high zero bits we're clearing out though.
const APInt *Amt;
if (match(I->getOperand(1), m_APInt(Amt))) {
uint64_t ShiftAmt;
if (match(I->getOperand(1), m_ConstantInt(ShiftAmt))) {
if (!canEvaluateZExtd(I->getOperand(0), Ty, BitsToClear, IC, CxtI))
return false;
BitsToClear += Amt->getZExtValue();
BitsToClear += ShiftAmt;
if (BitsToClear > V->getType()->getScalarSizeInBits())
BitsToClear = V->getType()->getScalarSizeInBits();
return true;
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1550,11 +1550,11 @@ Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp,
// trunc iN (ShOp >> ShAmtC) to i[N - ShAmtC] < 0 --> ShOp < 0
// trunc iN (ShOp >> ShAmtC) to i[N - ShAmtC] > -1 --> ShOp > -1
Value *ShOp;
const APInt *ShAmtC;
uint64_t ShAmt;
bool TrueIfSigned;
if (isSignBitCheck(Pred, C, TrueIfSigned) &&
match(X, m_Shr(m_Value(ShOp), m_APInt(ShAmtC))) &&
DstBits == SrcBits - ShAmtC->getZExtValue()) {
match(X, m_Shr(m_Value(ShOp), m_ConstantInt(ShAmt))) &&
DstBits == SrcBits - ShAmt) {
return TrueIfSigned ? new ICmpInst(ICmpInst::ICMP_SLT, ShOp,
ConstantInt::getNullValue(SrcTy))
: new ICmpInst(ICmpInst::ICMP_SGT, ShOp,
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ static void annotateNonNullAndDereferenceable(CallInst *CI, ArrayRef<unsigned> A
annotateDereferenceableBytes(CI, ArgNos, LenC->getZExtValue());
} else if (isKnownNonZero(Size, DL)) {
annotateNonNullNoUndefBasedOnAccess(CI, ArgNos);
const APInt *X, *Y;
uint64_t X, Y;
uint64_t DerefMin = 1;
if (match(Size, m_Select(m_Value(), m_APInt(X), m_APInt(Y)))) {
DerefMin = std::min(X->getZExtValue(), Y->getZExtValue());
if (match(Size, m_Select(m_Value(), m_ConstantInt(X), m_ConstantInt(Y)))) {
DerefMin = std::min(X, Y);
annotateDereferenceableBytes(CI, ArgNos, DerefMin);
}
}
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1863,15 +1863,15 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
unsigned ExtCnt = 0;
bool ExtLane0 = false;
for (User *U : Ext->users()) {
const APInt *Idx;
if (!match(U, m_ExtractElt(m_Value(), m_APInt(Idx))))
uint64_t Idx;
if (!match(U, m_ExtractElt(m_Value(), m_ConstantInt(Idx))))
return false;
if (cast<Instruction>(U)->use_empty())
continue;
ExtCnt += 1;
ExtLane0 |= Idx->isZero();
ExtLane0 |= !Idx;
VectorCost += TTI.getVectorInstrCost(Instruction::ExtractElement, DstTy,
CostKind, Idx->getZExtValue(), U);
CostKind, Idx, U);
}

InstructionCost ScalarCost =
Expand Down