[llvm] solve #65072, scalarize binary ops of splats by not check isTypeLegal (PR #100749)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 27 03:53:48 PDT 2024


================
@@ -26948,11 +26948,20 @@ static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG,
   // TODO: use DAG.isSplatValue instead?
   bool IsBothSplatVector = N0.getOpcode() == ISD::SPLAT_VECTOR &&
                            N1.getOpcode() == ISD::SPLAT_VECTOR;
+
+  // If binop is legal or custom on EltVT, scalarize should be profitable. The
+  // check is the same as isOperationLegalOrCustom without isTypeLegal. We
+  // can do this only before LegalTypes, because it may generate illegal `op
+  // EltVT` from legal `op VT (splat EltVT)`, where EltVT is not legal type but
+  // the result type of splat is legal.
+  auto EltAction = TLI.getOperationAction(Opcode, EltVT);
   if (!Src0 || !Src1 || Index0 != Index1 ||
       Src0.getValueType().getVectorElementType() != EltVT ||
       Src1.getValueType().getVectorElementType() != EltVT ||
       !(IsBothSplatVector || TLI.isExtractVecEltCheap(VT, Index0)) ||
-      !TLI.isOperationLegalOrCustom(Opcode, EltVT))
+      (LegalTypes && !TLI.isOperationLegalOrCustom(Opcode, EltVT)) ||
+      !(EltAction == TargetLoweringBase::Legal ||
+        EltAction == TargetLoweringBase::Custom))
----------------
lukel97 wrote:

Nit, would it be a bit more obvious if we do the check as
```suggestion
      (LegalTypes && !TLI.isTypeLegal(Opcode, EltVT)) ||
      !(EltAction == TargetLoweringBase::Legal ||
        EltAction == TargetLoweringBase::Custom))
```

I can see the pattern `if (LegalTypes && !TLI.isTypeLegal(...))` in a few places in DAGCombiner.cpp

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


More information about the llvm-commits mailing list