[llvm] [VectorCombine] Support nary operands and intrinsics in scalarizeOpOrCmp (PR #138406)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri May 23 09:56:58 PDT 2025


================
@@ -1120,15 +1110,37 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) {
     VectorOpCost = TTI.getIntrinsicInstrCost(VectorICA, CostKind);
   }
 
+  // Fold the vector constants in the original vectors into a new base vector to
+  // get more accurate cost modelling.
+  Value *NewVecC = nullptr;
+  if (auto *CI = dyn_cast<CmpInst>(&I))
+    NewVecC = ConstantFoldCompareInstOperands(CI->getPredicate(), VecCs[0],
+                                              VecCs[1], *DL);
+  else if (isa<UnaryOperator>(I))
+    NewVecC = ConstantFoldUnaryOpOperand((Instruction::UnaryOps)Opcode,
+                                         VecCs[0], *DL);
+  else if (isa<BinaryOperator>(I))
+    NewVecC = ConstantFoldBinaryOpOperands((Instruction::BinaryOps)Opcode,
+                                           VecCs[0], VecCs[1], *DL);
+  else if (isa<IntrinsicInst>(I) && cast<IntrinsicInst>(I).arg_size() == 2)
----------------
RKSimon wrote:

```cpp
else if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
  if (II->arg_size() == 2)
    NewVecC = ConstantFoldBinaryIntrinsic(II->getIntrinsicID(), VecCs[0], VecCs[1], I.getType(), &I);
}
```

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


More information about the llvm-commits mailing list