[llvm] [RISCV] Vector sub (zext, zext) -> sext (sub (zext, zext)) (PR #82455)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 14:54:54 PST 2024


================
@@ -12865,14 +12865,15 @@ static SDValue performSUBCombine(SDNode *N, SelectionDAG &DAG,
   //   where the sum of the extend widths match, and the inner zexts
   //   add at least one bit.  (For profitability on rvv, we use a
   //   power of two for both inner and outer extend.)
-  if (VT.isVector() && N0.getOpcode() == N1.getOpcode() && N0.hasOneUse() &&
-      N1.hasOneUse() && N0.getOpcode() == ISD::ZERO_EXTEND) {
+  if (VT.isVector() && Subtarget.getTargetLowering()->isTypeLegal(VT) &&
+      N0.getOpcode() == N1.getOpcode() && N0.hasOneUse() && N1.hasOneUse() &&
----------------
topperc wrote:

The list of uses for all results is stored in one linked list that is not sorted. SDValue::hasOneUse calls SDNode::hasNUsesOfValue. hasNUseOfValue will walk the list until it finds more than N uses of the result or it reaches the end of the list. If there is more than 1 result there may be many uses of the other results in the list. So the list length can be more than 1 even when the result we're looking for only has a single use. We would have to scan through all those other uses before the loop can terminate.

If the node only has 1 result, the list will only contain 1 use when that result has one use. If a second use exists it would be the next one in the linked list and the loop would terminate there.

Checking the opcode first ensures we are in the single result case.

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


More information about the llvm-commits mailing list