@@ -5419,20 +5419,15 @@ static Type *isSimpleCastedPHI(const SCEV *Op, const SCEVUnknown *SymbolicPHI,
54195419 if (SourceBits != NewBits)
54205420 return nullptr;
54215421
5422- const SCEVSignExtendExpr *SExt = dyn_cast<SCEVSignExtendExpr>(Op);
5423- const SCEVZeroExtendExpr *ZExt = dyn_cast<SCEVZeroExtendExpr>(Op);
5424- if (!SExt && !ZExt)
5425- return nullptr;
5426- const SCEVTruncateExpr *Trunc =
5427- SExt ? dyn_cast<SCEVTruncateExpr>(SExt->getOperand())
5428- : dyn_cast<SCEVTruncateExpr>(ZExt->getOperand());
5429- if (!Trunc)
5430- return nullptr;
5431- const SCEV *X = Trunc->getOperand();
5432- if (X != SymbolicPHI)
5433- return nullptr;
5434- Signed = SExt != nullptr;
5435- return Trunc->getType();
5422+ if (match(Op, m_scev_SExt(m_scev_Trunc(m_scev_Specific(SymbolicPHI))))) {
5423+ Signed = true;
5424+ return cast<SCEVCastExpr>(Op)->getOperand()->getType();
5425+ }
5426+ if (match(Op, m_scev_ZExt(m_scev_Trunc(m_scev_Specific(SymbolicPHI))))) {
5427+ Signed = false;
5428+ return cast<SCEVCastExpr>(Op)->getOperand()->getType();
5429+ }
5430+ return nullptr;
54365431}
54375432
54385433static const Loop *isIntegerLoopHeaderPHI(const PHINode *PN, LoopInfo &LI) {
@@ -15428,20 +15423,18 @@ bool ScalarEvolution::matchURem(const SCEV *Expr, const SCEV *&LHS,
1542815423 // Try to match 'zext (trunc A to iB) to iY', which is used
1542915424 // for URem with constant power-of-2 second operands. Make sure the size of
1543015425 // the operand A matches the size of the whole expressions.
15431- if (const auto *ZExt = dyn_cast<SCEVZeroExtendExpr>(Expr))
15432- if (const auto *Trunc = dyn_cast<SCEVTruncateExpr>(ZExt->getOperand(0))) {
15433- LHS = Trunc->getOperand();
15434- // Bail out if the type of the LHS is larger than the type of the
15435- // expression for now.
15436- if (getTypeSizeInBits(LHS->getType()) >
15437- getTypeSizeInBits(Expr->getType()))
15438- return false;
15439- if (LHS->getType() != Expr->getType())
15440- LHS = getZeroExtendExpr(LHS, Expr->getType());
15441- RHS = getConstant(APInt(getTypeSizeInBits(Expr->getType()), 1)
15442- << getTypeSizeInBits(Trunc->getType()));
15443- return true;
15444- }
15426+ if (match(Expr, m_scev_ZExt(m_scev_Trunc(m_SCEV(LHS))))) {
15427+ Type *TruncTy = cast<SCEVZeroExtendExpr>(Expr)->getOperand()->getType();
15428+ // Bail out if the type of the LHS is larger than the type of the
15429+ // expression for now.
15430+ if (getTypeSizeInBits(LHS->getType()) > getTypeSizeInBits(Expr->getType()))
15431+ return false;
15432+ if (LHS->getType() != Expr->getType())
15433+ LHS = getZeroExtendExpr(LHS, Expr->getType());
15434+ RHS = getConstant(APInt(getTypeSizeInBits(Expr->getType()), 1)
15435+ << getTypeSizeInBits(TruncTy));
15436+ return true;
15437+ }
1544515438 const auto *Add = dyn_cast<SCEVAddExpr>(Expr);
1544615439 if (Add == nullptr || Add->getNumOperands() != 2)
1544715440 return false;
0 commit comments