[llvm] [ExpandLargeDivRem] Scalarize vector types. (PR #86959)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 1 23:53:32 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);
+ Value *RHS = Builder.CreateExtractElement(BO->getOperand(1), Idx);
+ Value *Op = Builder.CreateBinOp(BO->getOpcode(), LHS, RHS);
+ Result = Builder.CreateInsertElement(
+ Result ? Result : PoisonValue::get(VTy), Op, Idx);
----------------
topperc wrote:
Can we initialize `Result` to `PoisonValue::get(VTy)` before the loop instead of `nullptr`?
https://github.com/llvm/llvm-project/pull/86959
More information about the llvm-commits
mailing list