@@ -2345,31 +2345,35 @@ bool SCEVExpander::isHighCostExpansionHelper(
2345
2345
if (getRelatedExistingExpansion (S, &At, L))
2346
2346
return false ; // Consider the expression to be free.
2347
2347
2348
- // Assume to be zero-cost.
2349
- if (isa<SCEVUnknown>(S))
2350
- return false ;
2351
-
2352
2348
TargetTransformInfo::TargetCostKind CostKind =
2353
- L->getHeader ()->getParent ()->hasMinSize ()
2354
- ? TargetTransformInfo::TCK_CodeSize
2355
- : TargetTransformInfo::TCK_RecipThroughput;
2349
+ L->getHeader ()->getParent ()->hasMinSize ()
2350
+ ? TargetTransformInfo::TCK_CodeSize
2351
+ : TargetTransformInfo::TCK_RecipThroughput;
2356
2352
2357
- if (auto *Constant = dyn_cast<SCEVConstant>(S)) {
2353
+ switch (S->getSCEVType ()) {
2354
+ case scUnknown:
2355
+ // Assume to be zero-cost.
2356
+ return false ;
2357
+ case scConstant: {
2358
+ auto *Constant = dyn_cast<SCEVConstant>(S);
2358
2359
// Only evalulate the costs of constants when optimizing for size.
2359
2360
if (CostKind != TargetTransformInfo::TCK_CodeSize)
2360
2361
return 0 ;
2361
2362
const APInt &Imm = Constant->getAPInt ();
2362
2363
Type *Ty = S->getType ();
2363
- BudgetRemaining -=
2364
- TTI.getIntImmCostInst (WorkItem.ParentOpcode , WorkItem.OperandIdx ,
2365
- Imm, Ty, CostKind);
2364
+ BudgetRemaining -= TTI.getIntImmCostInst (
2365
+ WorkItem.ParentOpcode , WorkItem.OperandIdx , Imm, Ty, CostKind);
2366
2366
return BudgetRemaining < 0 ;
2367
- } else if (isa<SCEVIntegralCastExpr>(S)) {
2367
+ }
2368
+ case scTruncate:
2369
+ case scZeroExtend:
2370
+ case scSignExtend: {
2368
2371
int Cost = costAndCollectOperands<SCEVIntegralCastExpr>(WorkItem, TTI,
2369
2372
CostKind, Worklist);
2370
2373
BudgetRemaining -= Cost;
2371
2374
return false ; // Will answer upon next entry into this function.
2372
- } else if (isa<SCEVUDivExpr>(S)) {
2375
+ }
2376
+ case scUDivExpr: {
2373
2377
// UDivExpr is very likely a UDiv that ScalarEvolution's HowFarToZero or
2374
2378
// HowManyLessThans produced to compute a precise expression, rather than a
2375
2379
// UDiv from the user's code. If we can't find a UDiv in the code with some
@@ -2383,27 +2387,36 @@ bool SCEVExpander::isHighCostExpansionHelper(
2383
2387
return false ; // Consider it to be free.
2384
2388
2385
2389
int Cost =
2386
- costAndCollectOperands<SCEVUDivExpr>(WorkItem, TTI, CostKind, Worklist);
2390
+ costAndCollectOperands<SCEVUDivExpr>(WorkItem, TTI, CostKind, Worklist);
2387
2391
// Need to count the cost of this UDiv.
2388
2392
BudgetRemaining -= Cost;
2389
2393
return false ; // Will answer upon next entry into this function.
2390
- } else if (const SCEVNAryExpr *NAry = dyn_cast<SCEVNAryExpr>(S)) {
2394
+ }
2395
+ case scAddExpr:
2396
+ case scMulExpr:
2397
+ case scUMaxExpr:
2398
+ case scSMaxExpr:
2399
+ case scUMinExpr:
2400
+ case scSMinExpr: {
2401
+ const SCEVNAryExpr *NAry = dyn_cast<SCEVNAryExpr>(S);
2391
2402
assert (NAry->getNumOperands () > 1 &&
2392
2403
" Nary expr should have more than 1 operand." );
2393
2404
// The simple nary expr will require one less op (or pair of ops)
2394
2405
// than the number of it's terms.
2395
2406
int Cost =
2396
- costAndCollectOperands<SCEVNAryExpr>(WorkItem, TTI, CostKind, Worklist);
2407
+ costAndCollectOperands<SCEVNAryExpr>(WorkItem, TTI, CostKind, Worklist);
2397
2408
BudgetRemaining -= Cost;
2398
2409
return BudgetRemaining < 0 ;
2399
- } else if (isa<SCEVAddRecExpr>(S)) {
2410
+ }
2411
+ case scAddRecExpr: {
2400
2412
assert (cast<SCEVAddRecExpr>(S)->getNumOperands () >= 2 &&
2401
2413
" Polynomial should be at least linear" );
2402
2414
BudgetRemaining -= costAndCollectOperands<SCEVAddRecExpr>(
2403
- WorkItem, TTI, CostKind, Worklist);
2415
+ WorkItem, TTI, CostKind, Worklist);
2404
2416
return BudgetRemaining < 0 ;
2405
- } else
2406
- llvm_unreachable (" No other scev expressions possible." );
2417
+ }
2418
+ }
2419
+ llvm_unreachable (" Switch is exaustive and we return in all of them." );
2407
2420
}
2408
2421
2409
2422
Value *SCEVExpander::expandCodeForPredicate (const SCEVPredicate *Pred,
0 commit comments