@@ -4939,20 +4939,6 @@ void LoongArchTargetLowering::ReplaceNodeResults(
4939
4939
}
4940
4940
}
4941
4941
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
-
4956
4942
// Helper to attempt to return a cheaper, bit-inverted version of \p V.
4957
4943
static SDValue isNOT (SDValue V, SelectionDAG &DAG) {
4958
4944
// TODO: don't always ignore oneuse constraints.
@@ -4976,12 +4962,16 @@ static SDValue isNOT(SDValue V, SelectionDAG &DAG) {
4976
4962
}
4977
4963
4978
4964
// 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
+ }
4985
4975
}
4986
4976
}
4987
4977
@@ -6762,10 +6752,13 @@ static SDValue performVANDNCombine(SDNode *N, SelectionDAG &DAG,
6762
6752
// -> NOT(OR(x, SplatVector(-Imm))
6763
6753
// Combination is performed only when VT is v16i8/v32i8, using `vnori.b` to
6764
6754
// 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
+
6769
6762
if (auto *C = dyn_cast<ConstantSDNode>(SplatValue)) {
6770
6763
uint8_t NCVal = static_cast <uint8_t >(~(C->getSExtValue ()));
6771
6764
SDValue Not =
@@ -6774,6 +6767,7 @@ static SDValue performVANDNCombine(SDNode *N, SelectionDAG &DAG,
6774
6767
DL, DAG.getNode (ISD::OR, DL, VT, N0, DAG.getBitcast (VT, Not)),
6775
6768
VT);
6776
6769
}
6770
+ }
6777
6771
}
6778
6772
}
6779
6773
0 commit comments