[llvm] [RISCV] Support multiple levels of truncates in combineTruncToVnclip. (PR #93752)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 23:37:01 PDT 2024
================
@@ -16263,22 +16263,39 @@ static SDValue combineTruncToVnclip(SDNode *N, SelectionDAG &DAG,
return SDValue();
};
+ SDValue Src = N->getOperand(0);
+
+ // Look through multiple layers of truncates.
+ while (Src.getOpcode() == RISCVISD::TRUNCATE_VECTOR_VL &&
+ Src.getOperand(1) == Mask && Src.getOperand(2) == VL &&
+ Src.hasOneUse())
+ Src = Src.getOperand(0);
+
SDValue Val;
unsigned ClipOpc;
- if ((Val = DetectUSatPattern(N->getOperand(0))))
+ if ((Val = DetectUSatPattern(Src)))
ClipOpc = RISCVISD::VNCLIPU_VL;
- else if ((Val = DetectSSatPattern(N->getOperand(0))))
+ else if ((Val = DetectSSatPattern(Src)))
ClipOpc = RISCVISD::VNCLIP_VL;
else
return SDValue();
SDLoc DL(N);
- // Rounding mode here is arbitrary since we aren't shifting out any bits.
- return DAG.getNode(
- ClipOpc, DL, VT,
- {Val, DAG.getConstant(0, DL, VT), DAG.getUNDEF(VT), Mask,
- DAG.getTargetConstant(RISCVVXRndMode::RNU, DL, Subtarget.getXLenVT()),
- VL});
+
+ MVT ValVT = Val.getSimpleValueType();
+
+ do {
+ MVT ValEltVT = MVT::getIntegerVT(ValVT.getScalarSizeInBits() / 2);
+ ValVT = MVT::getVectorVT(ValEltVT, ValVT.getVectorElementCount());
----------------
wangpc-pp wrote:
changeVectorElementType?
Or we can add a helper `getHalfVectorElementSizeVT` like `getHalfNumVectorElementsVT`?
https://github.com/llvm/llvm-project/pull/93752
More information about the llvm-commits
mailing list