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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu May 1 03:31:47 PDT 2025


================
@@ -1135,9 +1167,16 @@ bool VectorCombine::scalarizeBinopOrCmp(Instruction &I) {
     ScalarInst->copyIRFlags(&I);
 
   // Fold the vector constants in the original vectors into a new base vector.
-  Value *NewVecC =
-      IsCmp ? Builder.CreateCmp(Pred, VecC0, VecC1)
-            : Builder.CreateBinOp((Instruction::BinaryOps)Opcode, VecC0, VecC1);
+  Value *NewVecC;
+  if (isa<CmpInst>(I))
+    NewVecC = Builder.CreateCmp(Pred, VecC0, VecC1);
+  else if (isa<BinaryOperator>(I))
+    NewVecC = Builder.CreateBinOp((Instruction::BinaryOps)Opcode, VecC0, VecC1);
----------------
dtcxzyw wrote:

This transformation is invalid for `div/rem`: https://alive2.llvm.org/ce/z/FfrxXp


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


More information about the llvm-commits mailing list