Skip to content

Commit f64d6f3

Browse files
committed
Use getSplatValue instead of isSplatOrUndef
1 parent 83e3d7f commit f64d6f3

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4939,20 +4939,6 @@ void LoongArchTargetLowering::ReplaceNodeResults(
49394939
}
49404940
}
49414941

4942-
// Check if all elements in build_vector are the same or undef, and if so,
4943-
// return true and set the splat element in SplatValue.
4944-
static bool isSplatOrUndef(SDNode *N, SDValue &SplatValue) {
4945-
if (N->getOpcode() != ISD::BUILD_VECTOR)
4946-
return false;
4947-
for (SDValue Op : N->ops()) {
4948-
if (!Op.isUndef() && SplatValue && Op != SplatValue)
4949-
return false;
4950-
if (!Op.isUndef())
4951-
SplatValue = Op;
4952-
}
4953-
return true;
4954-
}
4955-
49564942
// Helper to attempt to return a cheaper, bit-inverted version of \p V.
49574943
static SDValue isNOT(SDValue V, SelectionDAG &DAG) {
49584944
// TODO: don't always ignore oneuse constraints.
@@ -4976,12 +4962,16 @@ static SDValue isNOT(SDValue V, SelectionDAG &DAG) {
49764962
}
49774963

49784964
// Match not(SplatVector(not(X)) -> SplatVector(X).
4979-
SDValue SplatValue;
4980-
if (isSplatOrUndef(V.getNode(), SplatValue) &&
4981-
V->isOnlyUserOf(SplatValue.getNode())) {
4982-
if (SDValue Not = isNOT(SplatValue, DAG)) {
4983-
Not = DAG.getBitcast(V.getOperand(0).getValueType(), Not);
4984-
return DAG.getSplat(VT, SDLoc(Not), Not);
4965+
if (V.getOpcode() == ISD::BUILD_VECTOR) {
4966+
if (SDValue SplatValue =
4967+
cast<BuildVectorSDNode>(V.getNode())->getSplatValue()) {
4968+
if (!V->isOnlyUserOf(SplatValue.getNode()))
4969+
return SDValue();
4970+
4971+
if (SDValue Not = isNOT(SplatValue, DAG)) {
4972+
Not = DAG.getBitcast(V.getOperand(0).getValueType(), Not);
4973+
return DAG.getSplat(VT, SDLoc(Not), Not);
4974+
}
49854975
}
49864976
}
49874977

@@ -6762,10 +6752,13 @@ static SDValue performVANDNCombine(SDNode *N, SelectionDAG &DAG,
67626752
// -> NOT(OR(x, SplatVector(-Imm))
67636753
// Combination is performed only when VT is v16i8/v32i8, using `vnori.b` to
67646754
// gain benefits.
6765-
if (!DCI.isBeforeLegalizeOps() && (VT == MVT::v16i8 || VT == MVT::v32i8)) {
6766-
SDValue SplatValue;
6767-
if (isSplatOrUndef(N1.getNode(), SplatValue) &&
6768-
N1->isOnlyUserOf(SplatValue.getNode()))
6755+
if (!DCI.isBeforeLegalizeOps() && (VT == MVT::v16i8 || VT == MVT::v32i8) &&
6756+
N1.getOpcode() == ISD::BUILD_VECTOR) {
6757+
if (SDValue SplatValue =
6758+
cast<BuildVectorSDNode>(N1.getNode())->getSplatValue()) {
6759+
if (!N1->isOnlyUserOf(SplatValue.getNode()))
6760+
return SDValue();
6761+
67696762
if (auto *C = dyn_cast<ConstantSDNode>(SplatValue)) {
67706763
uint8_t NCVal = static_cast<uint8_t>(~(C->getSExtValue()));
67716764
SDValue Not =
@@ -6774,6 +6767,7 @@ static SDValue performVANDNCombine(SDNode *N, SelectionDAG &DAG,
67746767
DL, DAG.getNode(ISD::OR, DL, VT, N0, DAG.getBitcast(VT, Not)),
67756768
VT);
67766769
}
6770+
}
67776771
}
67786772
}
67796773

0 commit comments

Comments
 (0)