[llvm] [RISCV] Optimize pattern `(setcc (selectLT (vfirst_vl ...) , 0, EVL, ...), EVL)` (PR #90538)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed May 1 12:57:18 PDT 2024


================
@@ -13678,9 +13687,88 @@ static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG,
                                    const RISCVSubtarget &Subtarget) {
   SDValue N0 = N->getOperand(0);
   SDValue N1 = N->getOperand(1);
+  ISD::CondCode Cond = cast<CondCodeSDNode>(N->getOperand(2))->get();
   EVT VT = N->getValueType(0);
   EVT OpVT = N0.getValueType();
+  SDLoc DL(N);
+
+  // Both rules are looking for an equality compare.
+  if (!isIntEqualitySetCC(Cond))
+    return SDValue();
+
+  // Rule 1
+  using namespace SDPatternMatch;
+  auto matchSelectCC = [](SDValue Op, SDValue VLCandidate, bool Inverse,
+                          SDValue &Select) -> bool {
+    // Remove any sext or zext
+    auto ExtPattern =
+        m_AnyOf(m_Opc(ISD::SIGN_EXTEND_INREG), m_And(m_Value(), m_AllOnes()));
----------------
topperc wrote:

I'm not sure m_AllOnes is implemented correctly. It uses `APInt::isSameValue` which zero extends when bit widths don't match. `m_AllOnes` should be checking that all bits are one. If `m_AllOnes` is used to compare against a value that is less than 64 bits, that value will be zero extended to 64 bits and will fail to match.

https://github.com/llvm/llvm-project/pull/90538


More information about the llvm-commits mailing list