@@ -1150,7 +1150,8 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM,
1150
1150
// Jumps are expensive, compared to logic
1151
1151
setJumpIsExpensive();
1152
1152
1153
- setTargetDAGCombine({ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::AND,
1153
+ setTargetDAGCombine({ISD::INTRINSIC_VOID, ISD::INTRINSIC_W_CHAIN,
1154
+ ISD::INTRINSIC_WO_CHAIN, ISD::ADD, ISD::SUB, ISD::AND,
1154
1155
ISD::OR, ISD::XOR, ISD::SETCC, ISD::SELECT});
1155
1156
if (Subtarget.is64Bit())
1156
1157
setTargetDAGCombine(ISD::SRA);
@@ -10623,6 +10624,46 @@ static SDValue performXORCombine(SDNode *N, SelectionDAG &DAG,
10623
10624
return combineSelectAndUseCommutative(N, DAG, /*AllOnes*/ false, Subtarget);
10624
10625
}
10625
10626
10627
+ // According to the property that indexed load/store instructions
10628
+ // zero-extended their indices, \p narrowIndex tries to narrow the type of index
10629
+ // operand if it is matched to pattern (shl (zext x to ty), C) and bits(x) + C <
10630
+ // bits(ty).
10631
+ static SDValue narrowIndex(SDValue N, SelectionDAG &DAG) {
10632
+ if (N.getOpcode() != ISD::SHL || !N->hasOneUse())
10633
+ return SDValue();
10634
+
10635
+ SDValue N0 = N.getOperand(0);
10636
+ if (N0.getOpcode() != ISD::ZERO_EXTEND &&
10637
+ N0.getOpcode() != RISCVISD::VZEXT_VL)
10638
+ return SDValue();
10639
+ if (!N0->hasOneUse())
10640
+ return SDValue();
10641
+
10642
+ APInt ShAmt;
10643
+ SDValue N1 = N.getOperand(1);
10644
+ if (!ISD::isConstantSplatVector(N1.getNode(), ShAmt))
10645
+ return SDValue();
10646
+
10647
+ SDLoc DL(N);
10648
+ SDValue Src = N0.getOperand(0);
10649
+ EVT SrcVT = Src.getValueType();
10650
+ unsigned SrcElen = SrcVT.getScalarSizeInBits();
10651
+ unsigned ShAmtV = ShAmt.getZExtValue();
10652
+ unsigned NewElen = PowerOf2Ceil(SrcElen + ShAmtV);
10653
+ NewElen = std::max(NewElen, 8U);
10654
+
10655
+ // Skip if NewElen is not narrower than the original extended type.
10656
+ if (NewElen >= N0.getValueType().getScalarSizeInBits())
10657
+ return SDValue();
10658
+
10659
+ EVT NewEltVT = EVT::getIntegerVT(*DAG.getContext(), NewElen);
10660
+ EVT NewVT = SrcVT.changeVectorElementType(NewEltVT);
10661
+
10662
+ SDValue NewExt = DAG.getNode(N0->getOpcode(), DL, NewVT, N0->ops());
10663
+ SDValue NewShAmtVec = DAG.getConstant(ShAmtV, DL, NewVT);
10664
+ return DAG.getNode(ISD::SHL, DL, NewVT, NewExt, NewShAmtVec);
10665
+ }
10666
+
10626
10667
// Replace (seteq (i64 (and X, 0xffffffff)), C1) with
10627
10668
// (seteq (i64 (sext_inreg (X, i32)), C1')) where C1' is C1 sign extended from
10628
10669
// bit 31. Same for setne. C1' may be cheaper to materialize and the sext_inreg
@@ -12920,8 +12961,11 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
12920
12961
}
12921
12962
break;
12922
12963
}
12964
+ case ISD::INTRINSIC_VOID:
12965
+ case ISD::INTRINSIC_W_CHAIN:
12923
12966
case ISD::INTRINSIC_WO_CHAIN: {
12924
- unsigned IntNo = N->getConstantOperandVal(0);
12967
+ unsigned IntOpNo = N->getOpcode() == ISD::INTRINSIC_WO_CHAIN ? 0 : 1;
12968
+ unsigned IntNo = N->getConstantOperandVal(IntOpNo);
12925
12969
switch (IntNo) {
12926
12970
// By default we do not combine any intrinsic.
12927
12971
default:
@@ -12944,6 +12988,23 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
12944
12988
return DAG.getConstant(-1, DL, VT);
12945
12989
return DAG.getConstant(0, DL, VT);
12946
12990
}
12991
+ case Intrinsic::riscv_vloxei:
12992
+ case Intrinsic::riscv_vloxei_mask:
12993
+ case Intrinsic::riscv_vluxei:
12994
+ case Intrinsic::riscv_vluxei_mask:
12995
+ case Intrinsic::riscv_vsoxei:
12996
+ case Intrinsic::riscv_vsoxei_mask:
12997
+ case Intrinsic::riscv_vsuxei:
12998
+ case Intrinsic::riscv_vsuxei_mask:
12999
+ if (SDValue V = narrowIndex(N->getOperand(4), DAG)) {
13000
+ SmallVector<SDValue, 8> Ops(N->ops());
13001
+ Ops[4] = V;
13002
+ const auto *MemSD = cast<MemIntrinsicSDNode>(N);
13003
+ return DAG.getMemIntrinsicNode(N->getOpcode(), SDLoc(N), N->getVTList(),
13004
+ Ops, MemSD->getMemoryVT(),
13005
+ MemSD->getMemOperand());
13006
+ }
13007
+ return SDValue();
12947
13008
}
12948
13009
}
12949
13010
case ISD::BITCAST: {
0 commit comments