@@ -1192,6 +1192,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, Type *Ty,
1192
1192
"This is not a truncating conversion!");
1193
1193
assert(isSCEVable(Ty) &&
1194
1194
"This is not a conversion to a SCEVable type!");
1195
+ assert(!Op->getType()->isPointerTy() && "Can't truncate pointer!");
1195
1196
Ty = getEffectiveSCEVType(Ty);
1196
1197
1197
1198
FoldingSetNodeID ID;
@@ -1581,6 +1582,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1581
1582
"This is not an extending conversion!");
1582
1583
assert(isSCEVable(Ty) &&
1583
1584
"This is not a conversion to a SCEVable type!");
1585
+ assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
1584
1586
Ty = getEffectiveSCEVType(Ty);
1585
1587
1586
1588
// Fold if the operand is constant.
@@ -1883,6 +1885,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
1883
1885
"This is not an extending conversion!");
1884
1886
assert(isSCEVable(Ty) &&
1885
1887
"This is not a conversion to a SCEVable type!");
1888
+ assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
1886
1889
Ty = getEffectiveSCEVType(Ty);
1887
1890
1888
1891
// Fold if the operand is constant.
@@ -2410,6 +2413,9 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
2410
2413
for (unsigned i = 1, e = Ops.size(); i != e; ++i)
2411
2414
assert(getEffectiveSCEVType(Ops[i]->getType()) == ETy &&
2412
2415
"SCEVAddExpr operand types don't match!");
2416
+ unsigned NumPtrs = count_if(
2417
+ Ops, [](const SCEV *Op) { return Op->getType()->isPointerTy(); });
2418
+ assert(NumPtrs <= 1 && "add has at most one pointer operand");
2413
2419
#endif
2414
2420
2415
2421
// Sort by complexity, this groups all similar expression types together.
@@ -2645,12 +2651,16 @@ const SCEV *ScalarEvolution::getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
2645
2651
Ops.clear();
2646
2652
if (AccumulatedConstant != 0)
2647
2653
Ops.push_back(getConstant(AccumulatedConstant));
2648
- for (auto &MulOp : MulOpLists)
2649
- if (MulOp.first != 0)
2654
+ for (auto &MulOp : MulOpLists) {
2655
+ if (MulOp.first == 1) {
2656
+ Ops.push_back(getAddExpr(MulOp.second, SCEV::FlagAnyWrap, Depth + 1));
2657
+ } else if (MulOp.first != 0) {
2650
2658
Ops.push_back(getMulExpr(
2651
2659
getConstant(MulOp.first),
2652
2660
getAddExpr(MulOp.second, SCEV::FlagAnyWrap, Depth + 1),
2653
2661
SCEV::FlagAnyWrap, Depth + 1));
2662
+ }
2663
+ }
2654
2664
if (Ops.empty())
2655
2665
return getZero(Ty);
2656
2666
if (Ops.size() == 1)
@@ -2969,9 +2979,10 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
2969
2979
assert(!Ops.empty() && "Cannot get empty mul!");
2970
2980
if (Ops.size() == 1) return Ops[0];
2971
2981
#ifndef NDEBUG
2972
- Type *ETy = getEffectiveSCEVType(Ops[0]->getType());
2982
+ Type *ETy = Ops[0]->getType();
2983
+ assert(!ETy->isPointerTy());
2973
2984
for (unsigned i = 1, e = Ops.size(); i != e; ++i)
2974
- assert(getEffectiveSCEVType( Ops[i]->getType() ) == ETy &&
2985
+ assert(Ops[i]->getType() == ETy &&
2975
2986
"SCEVMulExpr operand types don't match!");
2976
2987
#endif
2977
2988
@@ -3256,8 +3267,9 @@ const SCEV *ScalarEvolution::getURemExpr(const SCEV *LHS,
3256
3267
/// possible.
3257
3268
const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
3258
3269
const SCEV *RHS) {
3259
- assert(getEffectiveSCEVType(LHS->getType()) ==
3260
- getEffectiveSCEVType(RHS->getType()) &&
3270
+ assert(!LHS->getType()->isPointerTy() &&
3271
+ "SCEVUDivExpr operand can't be pointer!");
3272
+ assert(LHS->getType() == RHS->getType() &&
3261
3273
"SCEVUDivExpr operand types don't match!");
3262
3274
3263
3275
FoldingSetNodeID ID;
@@ -3506,9 +3518,11 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
3506
3518
if (Operands.size() == 1) return Operands[0];
3507
3519
#ifndef NDEBUG
3508
3520
Type *ETy = getEffectiveSCEVType(Operands[0]->getType());
3509
- for (unsigned i = 1, e = Operands.size(); i != e; ++i)
3521
+ for (unsigned i = 1, e = Operands.size(); i != e; ++i) {
3510
3522
assert(getEffectiveSCEVType(Operands[i]->getType()) == ETy &&
3511
3523
"SCEVAddRecExpr operand types don't match!");
3524
+ assert(!Operands[i]->getType()->isPointerTy() && "Step must be integer");
3525
+ }
3512
3526
for (unsigned i = 0, e = Operands.size(); i != e; ++i)
3513
3527
assert(isLoopInvariant(Operands[i], L) &&
3514
3528
"SCEVAddRecExpr operand is not loop-invariant!");
@@ -3662,9 +3676,13 @@ const SCEV *ScalarEvolution::getMinMaxExpr(SCEVTypes Kind,
3662
3676
if (Ops.size() == 1) return Ops[0];
3663
3677
#ifndef NDEBUG
3664
3678
Type *ETy = getEffectiveSCEVType(Ops[0]->getType());
3665
- for (unsigned i = 1, e = Ops.size(); i != e; ++i)
3679
+ for (unsigned i = 1, e = Ops.size(); i != e; ++i) {
3666
3680
assert(getEffectiveSCEVType(Ops[i]->getType()) == ETy &&
3667
3681
"Operand types don't match!");
3682
+ assert(Ops[0]->getType()->isPointerTy() ==
3683
+ Ops[i]->getType()->isPointerTy() &&
3684
+ "min/max should be consistently pointerish");
3685
+ }
3668
3686
#endif
3669
3687
3670
3688
bool IsSigned = Kind == scSMaxExpr || Kind == scSMinExpr;
@@ -10579,6 +10597,8 @@ bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred, const SCEV *LHS,
10579
10597
}
10580
10598
}
10581
10599
10600
+ if (LHS->getType()->isPointerTy())
10601
+ return false;
10582
10602
if (CmpInst::isSigned(Pred)) {
10583
10603
LHS = getSignExtendExpr(LHS, FoundLHS->getType());
10584
10604
RHS = getSignExtendExpr(RHS, FoundLHS->getType());
@@ -10588,6 +10608,8 @@ bool ScalarEvolution::isImpliedCond(ICmpInst::Predicate Pred, const SCEV *LHS,
10588
10608
}
10589
10609
} else if (getTypeSizeInBits(LHS->getType()) >
10590
10610
getTypeSizeInBits(FoundLHS->getType())) {
10611
+ if (FoundLHS->getType()->isPointerTy())
10612
+ return false;
10591
10613
if (CmpInst::isSigned(FoundPred)) {
10592
10614
FoundLHS = getSignExtendExpr(FoundLHS, LHS->getType());
10593
10615
FoundRHS = getSignExtendExpr(FoundRHS, LHS->getType());
0 commit comments