Skip to content
Merged
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
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7954,9 +7954,9 @@ bool VPRecipeBuilder::getScaledReductions(
auto CollectExtInfo = [this, &Exts, &ExtOpTypes,
&ExtKinds](SmallVectorImpl<Value *> &Ops) -> bool {
for (const auto &[I, OpI] : enumerate(Ops)) {
auto *CI = dyn_cast<ConstantInt>(OpI);
if (I > 0 && CI &&
canConstantBeExtended(CI, ExtOpTypes[0], ExtKinds[0])) {
const APInt *C;
if (I > 0 && match(OpI, m_APInt(C)) &&
canConstantBeExtended(C, ExtOpTypes[0], ExtKinds[0])) {
ExtOpTypes[I] = ExtOpTypes[0];
ExtKinds[I] = ExtKinds[0];
continue;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Transforms/Vectorize/VPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,14 +1753,14 @@ void LoopVectorizationPlanner::printPlans(raw_ostream &O) {
}
#endif

bool llvm::canConstantBeExtended(const ConstantInt *CI, Type *NarrowType,
bool llvm::canConstantBeExtended(const APInt *C, Type *NarrowType,
TTI::PartialReductionExtendKind ExtKind) {
APInt TruncatedVal = CI->getValue().trunc(NarrowType->getScalarSizeInBits());
unsigned WideSize = CI->getType()->getScalarSizeInBits();
APInt TruncatedVal = C->trunc(NarrowType->getScalarSizeInBits());
unsigned WideSize = C->getBitWidth();
APInt ExtendedVal = ExtKind == TTI::PR_SignExtend
? TruncatedVal.sext(WideSize)
: TruncatedVal.zext(WideSize);
return ExtendedVal == CI->getValue();
return ExtendedVal == *C;
}

TargetTransformInfo::OperandValueInfo
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Vectorize/VPlanHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class VPlanPrinter {

/// Check if a constant \p CI can be safely treated as having been extended
/// from a narrower type with the given extension kind.
bool canConstantBeExtended(const ConstantInt *CI, Type *NarrowType,
bool canConstantBeExtended(const APInt *C, Type *NarrowType,
TTI::PartialReductionExtendKind ExtKind);
} // end namespace llvm

Expand Down
24 changes: 20 additions & 4 deletions llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,10 @@ inline int_pred_ty<is_zero_int> m_ZeroInt() {
/// For vectors, this includes constants with undefined elements.
inline int_pred_ty<is_one> m_One() { return int_pred_ty<is_one>(); }

struct bind_const_int {
uint64_t &Res;
struct bind_apint {
const APInt *&Res;

bind_const_int(uint64_t &Res) : Res(Res) {}
bind_apint(const APInt *&Res) : Res(Res) {}

bool match(VPValue *VPV) const {
if (!VPV->isLiveIn())
Expand All @@ -188,7 +188,23 @@ struct bind_const_int {
const auto *CI = dyn_cast<ConstantInt>(V);
if (!CI)
return false;
if (auto C = CI->getValue().tryZExtValue()) {
Res = &CI->getValue();
return true;
}
};

inline bind_apint m_APInt(const APInt *&C) { return C; }

struct bind_const_int {
uint64_t &Res;

bind_const_int(uint64_t &Res) : Res(Res) {}

bool match(VPValue *VPV) const {
const APInt *APConst;
if (!bind_apint(APConst).match(VPV))
return false;
if (auto C = APConst->tryZExtValue()) {
Res = *C;
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,12 @@ VPPartialReductionRecipe::computeCost(ElementCount VF,
ExtAType = GetExtendKind(ExtAR);
ExtBType = GetExtendKind(ExtBR);

if (!ExtBR && Widen->getOperand(1)->isLiveIn()) {
auto *CI = cast<ConstantInt>(Widen->getOperand(1)->getLiveInIRValue());
if (canConstantBeExtended(CI, InputTypeA, ExtAType)) {
InputTypeB = InputTypeA;
ExtBType = ExtAType;
}
using namespace VPlanPatternMatch;
const APInt *C;
if (!ExtBR && match(Widen->getOperand(1), m_APInt(C)) &&
canConstantBeExtended(C, InputTypeA, ExtAType)) {
InputTypeB = InputTypeA;
ExtBType = ExtAType;
}
};

Expand Down