[Mlir-commits] [mlir] [MLIR][SCFToOpenMP] Fix crash when lowering vector reductions (PR #173978)
Tom Eccles
llvmlistbot at llvm.org
Mon Jan 5 08:04:17 PST 2026
================
@@ -261,54 +295,67 @@ static omp::DeclareReductionOp declareReduction(PatternRewriter &builder,
// Match simple binary reductions that can be expressed with atomicrmw.
Type type = reduce.getOperands()[reductionIndex].getType();
Block &reduction = reduce.getReductions()[reductionIndex].front();
+
+ // Handle scalar element type extraction for vector bitwidth safety.
+ Type elType = type;
+ if (auto vecType = dyn_cast<VectorType>(type))
+ elType = vecType.getElementType();
+
+ // Helper to create splat (for vectors) or scalar attributes.
+ auto getAttr = [&](Attribute val) -> Attribute {
+ if (auto vecType = dyn_cast<VectorType>(type))
+ return DenseElementsAttr::get(vecType, val);
+ return val;
+ };
+
+ // Arithmetic Reductions
if (matchSimpleReduction<arith::AddFOp, LLVM::FAddOp>(reduction)) {
- omp::DeclareReductionOp decl =
- createDecl(builder, symbolTable, reduce, reductionIndex,
- builder.getFloatAttr(type, 0.0));
- return addAtomicRMW(builder, LLVM::AtomicBinOp::fadd, decl, reduce,
- reductionIndex);
+ auto decl = createDecl(builder, symbolTable, reduce, reductionIndex,
----------------
tblah wrote:
Why did you switch to auto here? Spelling out the type is preferred
https://github.com/llvm/llvm-project/pull/173978
More information about the Mlir-commits
mailing list