Skip to content

Commit 61f053d

Browse files
committed
fix TTI::CastContextHint
1 parent a9d4ab0 commit 61f053d

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,21 +2238,37 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF,
22382238
return TTI::CastContextHint::Normal;
22392239
};
22402240

2241+
using namespace llvm::VPlanPatternMatch;
22412242
VPValue *Operand = getOperand(0);
22422243
TTI::CastContextHint CCH = TTI::CastContextHint::None;
22432244
// For Trunc/FPTrunc, get the context from the only user.
2244-
if ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
2245-
!hasMoreThanOneUniqueUser() && getNumUsers() > 0) {
2246-
if (auto *StoreRecipe = dyn_cast<VPRecipeBase>(*user_begin()))
2247-
CCH = ComputeCCH(StoreRecipe);
2245+
if (Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) {
2246+
static auto GetOnlyUser = [](const VPSingleDefRecipe *R) -> VPRecipeBase * {
2247+
if (R->hasMoreThanOneUniqueUser() || R->getNumUsers() == 0)
2248+
return nullptr;
2249+
return dyn_cast<VPRecipeBase>(*R->user_begin());
2250+
};
2251+
2252+
if (VPRecipeBase *Recipe = GetOnlyUser(this)) {
2253+
if (match(Recipe, m_VPInstruction<VPInstruction::Reverse>(m_VPValue())))
2254+
Recipe = GetOnlyUser(cast<VPInstruction>(Recipe));
2255+
if (Recipe)
2256+
CCH = ComputeCCH(Recipe);
2257+
}
22482258
}
22492259
// For Z/Sext, get the context from the operand.
22502260
else if (Opcode == Instruction::ZExt || Opcode == Instruction::SExt ||
22512261
Opcode == Instruction::FPExt) {
22522262
if (Operand->isLiveIn())
22532263
CCH = TTI::CastContextHint::Normal;
2254-
else if (Operand->getDefiningRecipe())
2255-
CCH = ComputeCCH(Operand->getDefiningRecipe());
2264+
else if (auto *Recipe = Operand->getDefiningRecipe()) {
2265+
VPValue *ReverseOp;
2266+
if (match(Recipe,
2267+
m_VPInstruction<VPInstruction::Reverse>(m_VPValue(ReverseOp))))
2268+
Recipe = ReverseOp->getDefiningRecipe();
2269+
if (Recipe)
2270+
CCH = ComputeCCH(Recipe);
2271+
}
22562272
}
22572273

22582274
auto *SrcTy =

0 commit comments

Comments
 (0)