@@ -1527,6 +1527,10 @@ class LoopVectorizationCostModel {
1527
1527
getReductionPatternCost (Instruction *I, ElementCount VF, Type *VectorTy,
1528
1528
TTI::TargetCostKind CostKind) const ;
1529
1529
1530
+ // / Returns true if \p Op should be considered invariant and if it is
1531
+ // / trivially hoistable.
1532
+ bool shouldConsiderInvariant (Value *Op);
1533
+
1530
1534
private:
1531
1535
unsigned NumPredStores = 0 ;
1532
1536
@@ -6382,6 +6386,17 @@ void LoopVectorizationCostModel::setVectorizedCallDecision(ElementCount VF) {
6382
6386
}
6383
6387
}
6384
6388
6389
+ bool LoopVectorizationCostModel::shouldConsiderInvariant (Value *Op) {
6390
+ if (!Legal->isInvariant (Op))
6391
+ return false ;
6392
+ // Consider Op invariant, if it or its operands aren't predicated
6393
+ // instruction in the loop. In that case, it is not trivially hoistable.
6394
+ return !isa<Instruction>(Op) || !TheLoop->contains (cast<Instruction>(Op)) ||
6395
+ (!isPredicatedInst (cast<Instruction>(Op)) &&
6396
+ all_of (cast<Instruction>(Op)->operands (),
6397
+ [this ](Value *Op) { return shouldConsiderInvariant (Op); }));
6398
+ }
6399
+
6385
6400
InstructionCost
6386
6401
LoopVectorizationCostModel::getInstructionCost (Instruction *I,
6387
6402
ElementCount VF) {
@@ -6621,19 +6636,8 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,
6621
6636
Op2 = cast<SCEVConstant>(PSE.getSCEV (Op2))->getValue ();
6622
6637
}
6623
6638
auto Op2Info = TTI.getOperandInfo (Op2);
6624
- std::function<bool (Value *)> IsInvariant =
6625
- [this , &IsInvariant](Value *Op) -> bool {
6626
- if (!Legal->isInvariant (Op))
6627
- return false ;
6628
- // Consider Op2invariant, if it or its operands aren't predicated
6629
- // instruction in the loop. In that case, it is not trivially hoistable.
6630
- return !isa<Instruction>(Op) ||
6631
- !TheLoop->contains (cast<Instruction>(Op)) ||
6632
- (!isPredicatedInst (cast<Instruction>(Op)) &&
6633
- all_of (cast<Instruction>(Op)->operands (),
6634
- [&IsInvariant](Value *Op) { return IsInvariant (Op); }));
6635
- };
6636
- if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue && IsInvariant (Op2))
6639
+ if (Op2Info.Kind == TargetTransformInfo::OK_AnyValue &&
6640
+ shouldConsiderInvariant (Op2))
6637
6641
Op2Info.Kind = TargetTransformInfo::OK_UniformValue;
6638
6642
6639
6643
SmallVector<const Value *, 4 > Operands (I->operand_values ());
0 commit comments