Skip to content

Commit 85837b3

Browse files
fhahnarichardson
authored andcommitted
Revert "[SLP] Consider alternatives for cost of select instructions."
This reverts commit 1922570. This appears to cause a crash in the following example a, b, c; l() { int e = a, f = l, g, h, i, j; float *d = c, *k = b; for (;;) for (; g < f; g++) { k[h] = d[i]; k[h - 1] = d[j]; h += e << 1; i += e; } } clang -cc1 -triple i386-unknown-linux-gnu -emit-obj -target-cpu pentium-m -O1 -vectorize-loops -vectorize-slp reduced.c llvm::Type *llvm::Type::getWithNewBitWidth(unsigned int) const: Assertion `isIntOrIntVectorTy() && "Original type expected to be a vector of integers or a scalar integer."' failed.
2 parents 1ef2cda + a1b53db commit 85837b3

File tree

4 files changed

+401
-175
lines changed

4 files changed

+401
-175
lines changed

llvm/include/llvm/Analysis/ValueTracking.h

-8
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,6 @@ constexpr unsigned MaxAnalysisRecursionDepth = 6;
728728
/// minimum/maximum flavor.
729729
CmpInst::Predicate getInverseMinMaxPred(SelectPatternFlavor SPF);
730730

731-
/// Check if the values in \p VL are select instructions that can be converted
732-
/// to a min or max (vector) intrinsic. Returns the intrinsic ID, if such a
733-
/// conversion is possible, together with a bool indicating whether all select
734-
/// conditions are only used by the selects. Otherwise return
735-
/// Intrinsic::not_intrinsic.
736-
std::pair<Intrinsic::ID, bool>
737-
canConvertToMinOrMaxIntrinsic(ArrayRef<Value *> VL);
738-
739731
/// Return true if RHS is known to be implied true by LHS. Return false if
740732
/// RHS is known to be implied false by LHS. Otherwise, return None if no
741733
/// implication can be made.

llvm/lib/Analysis/ValueTracking.cpp

-39
Original file line numberDiff line numberDiff line change
@@ -6128,45 +6128,6 @@ CmpInst::Predicate llvm::getInverseMinMaxPred(SelectPatternFlavor SPF) {
61286128
return getMinMaxPred(getInverseMinMaxFlavor(SPF));
61296129
}
61306130

6131-
std::pair<Intrinsic::ID, bool>
6132-
llvm::canConvertToMinOrMaxIntrinsic(ArrayRef<Value *> VL) {
6133-
// Check if VL contains select instructions that can be folded into a min/max
6134-
// vector intrinsic and return the intrinsic if it is possible.
6135-
// TODO: Support floating point min/max.
6136-
bool AllCmpSingleUse = true;
6137-
SelectPatternResult SelectPattern;
6138-
SelectPattern.Flavor = SPF_UNKNOWN;
6139-
if (all_of(VL, [&SelectPattern, &AllCmpSingleUse](Value *I) {
6140-
Value *LHS, *RHS;
6141-
auto CurrentPattern = matchSelectPattern(I, LHS, RHS);
6142-
if (!SelectPatternResult::isMinOrMax(CurrentPattern.Flavor) ||
6143-
CurrentPattern.Flavor == SPF_FMINNUM ||
6144-
CurrentPattern.Flavor == SPF_FMAXNUM)
6145-
return false;
6146-
if (SelectPattern.Flavor != SPF_UNKNOWN &&
6147-
SelectPattern.Flavor != CurrentPattern.Flavor)
6148-
return false;
6149-
SelectPattern = CurrentPattern;
6150-
AllCmpSingleUse &=
6151-
match(I, m_Select(m_OneUse(m_Value()), m_Value(), m_Value()));
6152-
return true;
6153-
})) {
6154-
switch (SelectPattern.Flavor) {
6155-
case SPF_SMIN:
6156-
return {Intrinsic::smin, AllCmpSingleUse};
6157-
case SPF_UMIN:
6158-
return {Intrinsic::umin, AllCmpSingleUse};
6159-
case SPF_SMAX:
6160-
return {Intrinsic::smax, AllCmpSingleUse};
6161-
case SPF_UMAX:
6162-
return {Intrinsic::umax, AllCmpSingleUse};
6163-
default:
6164-
llvm_unreachable("unexpected select pattern flavor");
6165-
}
6166-
}
6167-
return {Intrinsic::not_intrinsic, false};
6168-
}
6169-
61706131
/// Return true if "icmp Pred LHS RHS" is always true.
61716132
static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS,
61726133
const Value *RHS, const DataLayout &DL,

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -3549,21 +3549,6 @@ int BoUpSLP::getEntryCost(TreeEntry *E) {
35493549
int ScalarCost = VecTy->getNumElements() * ScalarEltCost;
35503550
int VecCost = TTI->getCmpSelInstrCost(E->getOpcode(), VecTy, MaskTy,
35513551
CostKind, VL0);
3552-
// Check if it is possible and profitable to use min/max for selects in
3553-
// VL.
3554-
//
3555-
auto IntrinsicAndUse = canConvertToMinOrMaxIntrinsic(VL);
3556-
if (IntrinsicAndUse.first != Intrinsic::not_intrinsic) {
3557-
IntrinsicCostAttributes CostAttrs(IntrinsicAndUse.first, VecTy,
3558-
{VecTy, VecTy});
3559-
int IntrinsicCost = TTI->getIntrinsicInstrCost(CostAttrs, CostKind);
3560-
// If the selects are the only uses of the compares, they will be dead
3561-
// and we can adjust the cost by removing their cost.
3562-
if (IntrinsicAndUse.second)
3563-
IntrinsicCost -= TTI->getCmpSelInstrCost(Instruction::ICmp, VecTy,
3564-
MaskTy, CostKind);
3565-
VecCost = std::min(VecCost, IntrinsicCost);
3566-
}
35673552
return ReuseShuffleCost + VecCost - ScalarCost;
35683553
}
35693554
case Instruction::FNeg:

0 commit comments

Comments
 (0)