[llvm] [VectorCombine] Scalarize binop-like intrinsics (PR #138095)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Sat May 3 06:03:57 PDT 2025


================
@@ -1016,21 +1017,34 @@ bool VectorCombine::scalarizeVPIntrinsic(Instruction &I) {
   return true;
 }
 
-/// Match a vector binop or compare instruction with at least one inserted
-/// scalar operand and convert to scalar binop/cmp followed by insertelement.
+/// Match a vector binop, compare or binop-like intrinsic with at least one
+/// inserted scalar operand and convert to scalar binop/cmp/intrinsic followed
+/// by insertelement.
 bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) {
   CmpPredicate Pred = CmpInst::BAD_ICMP_PREDICATE;
   Value *Ins0, *Ins1;
   if (!match(&I, m_BinOp(m_Value(Ins0), m_Value(Ins1))) &&
-      !match(&I, m_Cmp(Pred, m_Value(Ins0), m_Value(Ins1))))
-    return false;
+      !match(&I, m_Cmp(Pred, m_Value(Ins0), m_Value(Ins1)))) {
+    // TODO: Allow unary and ternary intrinsics
+    // TODO: Allow intrinsics with different argument types
+    // TODO: Allow intrinsics with scalar arguments
----------------
lukel97 wrote:

Should we split it out in a separate PR when we want to support these? Or do you want it to be done in this PR? 

Happy either way, but FWIW we probably want to also support unary instructions too i.e. fneg, as that was needed for the motivating case I saw in SPEC. And in my local patch it's not too much work to support n-ary arguments in the same function, it abstracts pretty well. 

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


More information about the llvm-commits mailing list