[llvm] [ExpandLargeDivRem] Scalarize vector types. (PR #86959)

Bevin Hansson via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 1 23:49:28 PDT 2024


================
@@ -54,8 +54,34 @@ static bool isSigned(unsigned int Opcode) {
   return Opcode == Instruction::SDiv || Opcode == Instruction::SRem;
 }
 
+static void scalarize(BinaryOperator *BO,
+                      SmallVectorImpl<BinaryOperator *> &Replace) {
+  VectorType *VTy = cast<VectorType>(BO->getType());
+  assert(!VTy->isScalableTy() && "Tried to scalarize scalable vector!");
+
+  IRBuilder<> Builder(BO);
+
+  unsigned NumElements = VTy->getElementCount().getKnownMinValue();
+  Value *Result = nullptr;
+  for (unsigned Idx = 0; Idx < NumElements; ++Idx) {
+    Value *LHS = Builder.CreateExtractElement(BO->getOperand(0), Idx);
----------------
bevin-hansson wrote:

I was looking for one, but couldn't find anything.

(For fun I also asked GPT, and it told me about an API in VectorUtils that didn't exist. Very useful!)

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


More information about the llvm-commits mailing list