[llvm] [DAGCombiner] Add support for scalarising extracts of a vector setcc (PR #117566)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 28 01:50:10 PST 2024


================
@@ -22766,19 +22771,25 @@ static SDValue scalarizeExtractedBinop(SDNode *ExtElt, SelectionDAG &DAG,
   SDValue Op0 = Vec.getOperand(0);
   SDValue Op1 = Vec.getOperand(1);
   APInt SplatVal;
-  if (isAnyConstantBuildVector(Op0, true) ||
-      ISD::isConstantSplatVector(Op0.getNode(), SplatVal) ||
-      isAnyConstantBuildVector(Op1, true) ||
-      ISD::isConstantSplatVector(Op1.getNode(), SplatVal)) {
-    // extractelt (binop X, C), IndexC --> binop (extractelt X, IndexC), C'
-    // extractelt (binop C, X), IndexC --> binop C', (extractelt X, IndexC)
-    EVT VT = ExtElt->getValueType(0);
-    SDValue Ext0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Op0, Index);
-    SDValue Ext1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, Op1, Index);
-    return DAG.getNode(Vec.getOpcode(), DL, VT, Ext0, Ext1);
+  if (!isAnyConstantBuildVector(Op0, true) &&
+      !ISD::isConstantSplatVector(Op0.getNode(), SplatVal) &&
+      !isAnyConstantBuildVector(Op1, true) &&
+      !ISD::isConstantSplatVector(Op1.getNode(), SplatVal))
+    return SDValue();
----------------
david-arm wrote:

I see we already have a confusing number of predicate functions in SelectionDAG and DAGCombiner related to asking similar, but not identical questions about whether an operand is a constant splat/non-constant splat/constant build vector/etc. If it's ok with you I'd prefer not to add one more for now in this patch, but I'm happy to do a follow-on patch that tries to rationalise/refactor some of the existing interfaces. Hopefully that will then allow me to rewrite and simplify this code. What do you think?

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


More information about the llvm-commits mailing list