Skip to content

Commit 5dea7a8

Browse files
committed
Combine to vpdpbusd when operand is constant and small enough.
Differential Revision: https://reviews.llvm.org/D116363
1 parent 94173dc commit 5dea7a8

File tree

3 files changed

+164
-133
lines changed

3 files changed

+164
-133
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9252,8 +9252,13 @@ static bool isFoldableUseOfShuffle(SDNode *N) {
92529252
return true;
92539253
if (Opc == ISD::BITCAST) // Ignore bitcasts
92549254
return isFoldableUseOfShuffle(U);
9255-
if (N->hasOneUse())
9255+
if (N->hasOneUse()) {
9256+
// TODO, there may be some general way to know if a SDNode can
9257+
// be folded. We now only know whether an MI is foldable.
9258+
if (Opc == X86ISD::VPDPBUSD && U->getOperand(2).getNode() != N)
9259+
return false;
92569260
return true;
9261+
}
92579262
}
92589263
return false;
92599264
}
@@ -41973,17 +41978,14 @@ static bool detectExtMul(SelectionDAG &DAG, const SDValue &Mul, SDValue &Op0,
4197341978
if (Op0.getOpcode() == ISD::SIGN_EXTEND)
4197441979
std::swap(Op0, Op1);
4197541980

41976-
if (Op0.getOpcode() != ISD::ZERO_EXTEND)
41977-
return false;
41978-
4197941981
auto IsFreeTruncation = [](SDValue &Op) -> bool {
4198041982
if ((Op.getOpcode() == ISD::ZERO_EXTEND ||
4198141983
Op.getOpcode() == ISD::SIGN_EXTEND) &&
4198241984
Op.getOperand(0).getScalarValueSizeInBits() <= 8)
4198341985
return true;
4198441986

41985-
// TODO: Support contant value.
41986-
return false;
41987+
auto *BV = dyn_cast<BuildVectorSDNode>(Op);
41988+
return (BV && BV->isConstant());
4198741989
};
4198841990

4198941991
// (dpbusd (zext a), (sext, b)). Since the first operand should be unsigned

llvm/lib/Target/X86/X86PartialReduction.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ static bool matchVPDPBUSDPattern(const X86Subtarget *ST, BinaryOperator *Mul,
7676
if (isa<SExtInst>(LHS))
7777
std::swap(LHS, RHS);
7878

79-
if (!isa<ZExtInst>(LHS))
80-
return false;
81-
8279
auto IsFreeTruncation = [&](Value *Op) {
8380
if (auto *Cast = dyn_cast<CastInst>(Op)) {
8481
if (Cast->getParent() == Mul->getParent() &&
@@ -87,8 +84,8 @@ static bool matchVPDPBUSDPattern(const X86Subtarget *ST, BinaryOperator *Mul,
8784
Cast->getOperand(0)->getType()->getScalarSizeInBits() <= 8)
8885
return true;
8986
}
90-
// TODO: Support constant in ISel.
91-
return false;
87+
88+
return isa<Constant>(Op);
9289
};
9390

9491
// (dpbusd (zext a), (sext, b)). Since the first operand should be unsigned

0 commit comments

Comments
 (0)