Skip to content

Commit a1b53db

Browse files
committed
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.
1 parent 408c440 commit a1b53db

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
@@ -5991,45 +5991,6 @@ CmpInst::Predicate llvm::getInverseMinMaxPred(SelectPatternFlavor SPF) {
59915991
return getMinMaxPred(getInverseMinMaxFlavor(SPF));
59925992
}
59935993

5994-
std::pair<Intrinsic::ID, bool>
5995-
llvm::canConvertToMinOrMaxIntrinsic(ArrayRef<Value *> VL) {
5996-
// Check if VL contains select instructions that can be folded into a min/max
5997-
// vector intrinsic and return the intrinsic if it is possible.
5998-
// TODO: Support floating point min/max.
5999-
bool AllCmpSingleUse = true;
6000-
SelectPatternResult SelectPattern;
6001-
SelectPattern.Flavor = SPF_UNKNOWN;
6002-
if (all_of(VL, [&SelectPattern, &AllCmpSingleUse](Value *I) {
6003-
Value *LHS, *RHS;
6004-
auto CurrentPattern = matchSelectPattern(I, LHS, RHS);
6005-
if (!SelectPatternResult::isMinOrMax(CurrentPattern.Flavor) ||
6006-
CurrentPattern.Flavor == SPF_FMINNUM ||
6007-
CurrentPattern.Flavor == SPF_FMAXNUM)
6008-
return false;
6009-
if (SelectPattern.Flavor != SPF_UNKNOWN &&
6010-
SelectPattern.Flavor != CurrentPattern.Flavor)
6011-
return false;
6012-
SelectPattern = CurrentPattern;
6013-
AllCmpSingleUse &=
6014-
match(I, m_Select(m_OneUse(m_Value()), m_Value(), m_Value()));
6015-
return true;
6016-
})) {
6017-
switch (SelectPattern.Flavor) {
6018-
case SPF_SMIN:
6019-
return {Intrinsic::smin, AllCmpSingleUse};
6020-
case SPF_UMIN:
6021-
return {Intrinsic::umin, AllCmpSingleUse};
6022-
case SPF_SMAX:
6023-
return {Intrinsic::smax, AllCmpSingleUse};
6024-
case SPF_UMAX:
6025-
return {Intrinsic::umax, AllCmpSingleUse};
6026-
default:
6027-
llvm_unreachable("unexpected select pattern flavor");
6028-
}
6029-
}
6030-
return {Intrinsic::not_intrinsic, false};
6031-
}
6032-
60335994
/// Return true if "icmp Pred LHS RHS" is always true.
60345995
static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS,
60355996
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)