Skip to content

Commit 9e70cdc

Browse files
committed
VectorCombine: fix costs
1 parent 116e2f9 commit 9e70cdc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,11 +1966,12 @@ bool VectorCombine::foldTruncFromReductions(Instruction &I) {
19661966
Type *ResultTy = I.getType();
19671967

19681968
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput;
1969-
InstructionCost OldCost =
1970-
TTI.getCastInstrCost(Instruction::Trunc, ReductionSrcTy, TruncSrcTy,
1971-
TTI::CastContextHint::None, CostKind) +
1972-
TTI.getArithmeticReductionCost(ReductionOpc, ReductionSrcTy, std::nullopt,
1973-
CostKind);
1969+
InstructionCost OldCost = TTI.getArithmeticReductionCost(
1970+
ReductionOpc, ReductionSrcTy, std::nullopt, CostKind);
1971+
if (auto *Trunc = dyn_cast<CastInst>(ReductionSrc))
1972+
OldCost +=
1973+
TTI.getCastInstrCost(Instruction::Trunc, ReductionSrcTy, TruncSrcTy,
1974+
TTI::CastContextHint::None, CostKind, Trunc);
19741975
InstructionCost NewCost =
19751976
TTI.getArithmeticReductionCost(ReductionOpc, TruncSrcTy, std::nullopt,
19761977
CostKind) +

0 commit comments

Comments
 (0)