Skip to content

Commit fe37f08

Browse files
committed
Address comments.
1 parent 29c4d81 commit fe37f08

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7258,7 +7258,7 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
72587258
const auto &ChainOps = RdxDesc.getReductionOpChain(RedPhi, OrigLoop);
72597259
SetVector<Instruction *> ChainOpsAndOperands(ChainOps.begin(),
72607260
ChainOps.end());
7261-
auto isZExtOrSExt = [](const unsigned Opcode) -> bool {
7261+
auto IsZExtOrSExt = [](const unsigned Opcode) -> bool {
72627262
return Opcode == Instruction::ZExt || Opcode == Instruction::SExt;
72637263
};
72647264
// Also include the operands of instructions in the chain, as the cost-model
@@ -7274,11 +7274,12 @@ LoopVectorizationPlanner::precomputeCosts(VPlan &Plan, ElementCount VF,
72747274
ChainOpsAndOperands.insert(I);
72757275
if (I->getOpcode() == Instruction::Mul) {
72767276
auto *Ext0 = dyn_cast<Instruction>(I->getOperand(0));
7277-
if (Ext0 && isZExtOrSExt(Ext0->getOpcode()))
7278-
ChainOpsAndOperands.insert(Ext0);
72797277
auto *Ext1 = dyn_cast<Instruction>(I->getOperand(1));
7280-
if (Ext1 && isZExtOrSExt(Ext1->getOpcode()))
7278+
if (Ext0 && IsZExtOrSExt(Ext0->getOpcode()) && Ext1 &&
7279+
Ext0->getOpcode() == Ext1->getOpcode()) {
7280+
ChainOpsAndOperands.insert(Ext0);
72817281
ChainOpsAndOperands.insert(Ext1);
7282+
}
72827283
}
72837284
}
72847285
}

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF,
14851485
return TTI::CastContextHint::Normal;
14861486
};
14871487

1488+
VPValue *Operand = getOperand(0);
14881489
TTI::CastContextHint CCH = TTI::CastContextHint::None;
14891490
// For Trunc, the context is the only user, which must be a
14901491
// VPWidenStoreRecipe, a VPInterleaveRecipe ,or a VPReplicateRecipe.
@@ -1497,14 +1498,14 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF,
14971498
// a VPInterleaveRecipe, a VPReplicateRecipe or a live-in value.
14981499
else if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt ||
14991500
Opcode == Instruction::FPExt) {
1500-
if (getOperand(0)->isLiveIn())
1501+
if (Operand->isLiveIn())
15011502
CCH = TTI::CastContextHint::Normal;
1502-
else if (getOperand(0)->getDefiningRecipe())
1503-
CCH = ComputeCCH(getOperand(0)->getDefiningRecipe());
1503+
else if (Operand->getDefiningRecipe())
1504+
CCH = ComputeCCH(Operand->getDefiningRecipe());
15041505
}
15051506

1506-
auto *SrcTy = cast<VectorType>(
1507-
ToVectorTy(Ctx.Types.inferScalarType(getOperand(0)), VF));
1507+
auto *SrcTy =
1508+
cast<VectorType>(ToVectorTy(Ctx.Types.inferScalarType(Operand), VF));
15081509
auto *DestTy = cast<VectorType>(ToVectorTy(getResultType(), VF));
15091510
// Arm TTI will use the underlying instruction to determine the cost.
15101511
return Ctx.TTI.getCastInstrCost(

0 commit comments

Comments
 (0)