@@ -338,35 +338,20 @@ ElementalAssignBufferization::findMatch(hlfir::ElementalOp elemental) {
338338 if (!fir::isa_trivial (eleTy))
339339 return std::nullopt ;
340340
341- // The array must have the same shape as the elemental. CSE should have
342- // deduplicated the fir.shape operations where they are provably the same
343- // so we just have to check for the same ssa value.
341+ // The array must have the same shape as the elemental.
344342 //
345343 // f2018 10.2.1.2 (3) requires the lhs and rhs of an assignment to be
346344 // conformable unless the lhs is an allocatable array. In HLFIR we can
347345 // see this from the presence or absence of the realloc attribute on
348346 // hlfir.assign. If it is not a realloc assignment, we can trust that
349347 // the shapes do conform.
350- if (match.assign .getRealloc ()) {
351- mlir::Value arrayShape;
352- if (match.array .getDefiningOp ())
353- arrayShape =
354- mlir::TypeSwitch<mlir::Operation *, mlir::Value>(
355- match.array .getDefiningOp ())
356- .Case ([](hlfir::DesignateOp designate) {
357- return designate.getShape ();
358- })
359- .Case ([](hlfir::DeclareOp declare) { return declare.getShape (); })
360- .Default ([](mlir::Operation *) { return mlir::Value{}; });
361- if (!arrayShape) {
362- // TODO: add more ways of getting the shape of the array
363- LLVM_DEBUG (llvm::dbgs () << " Can't get shape of " << match.array << " at "
364- << elemental->getLoc () << " \n " );
365- return std::nullopt ;
366- }
367- if (arrayShape != elemental.getShape ())
368- return std::nullopt ;
369- }
348+ //
349+ // TODO: the lhs's shape is dynamic, so it is hard to prove that
350+ // there is no reallocation of the lhs due to the assignment.
351+ // We can probably try generating multiple versions of the code
352+ // with checking for the shape match, length parameters match, etc.
353+ if (match.assign .getRealloc ())
354+ return std::nullopt ;
370355
371356 // the transformation wants to apply the elemental in a do-loop at the
372357 // hlfir.assign, check there are no effects which make this unsafe
0 commit comments