Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2259,9 +2259,8 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF,
VPValue *Operand = getOperand(0);
TTI::CastContextHint CCH = TTI::CastContextHint::None;
// For Trunc/FPTrunc, get the context from the only user.
if ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
!hasMoreThanOneUniqueUser() && getNumUsers() > 0) {
if (auto *StoreRecipe = dyn_cast<VPRecipeBase>(*user_begin()))
if (Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) {
if (auto *StoreRecipe = dyn_cast_or_null<VPRecipeBase>(getSingleUser()))
CCH = ComputeCCH(StoreRecipe);
}
// For Z/Sext, get the context from the operand.
Expand Down
14 changes: 12 additions & 2 deletions llvm/lib/Transforms/Vectorize/VPlanValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,21 @@ class LLVM_ABI_FOR_TEST VPValue {

bool hasOneUse() const { return getNumUsers() == 1; }

/// Returns true if the value has exactly one unique user, ignoring multiple
/// uses by the same user.
bool hasOneUser() const {
if (getNumUsers() == 0)
return false;
if (hasOneUse())
return true;
return std::equal(std::next(user_begin()), user_end(), user_begin());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could use all_equal(Users)

}

/// Return the single user of this value, or nullptr if there is not exactly
/// one user.
VPUser *getSingleUser() { return hasOneUse() ? *user_begin() : nullptr; }
VPUser *getSingleUser() { return hasOneUser() ? *user_begin() : nullptr; }
const VPUser *getSingleUser() const {
return hasOneUse() ? *user_begin() : nullptr;
return hasOneUser() ? *user_begin() : nullptr;
}

void replaceAllUsesWith(VPValue *New);
Expand Down
Loading