Skip to content

Commit 632cb06

Browse files
committed
Addressed review comments.
1 parent a4deae0 commit 632cb06

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ namespace hlfir {
4242

4343
#define DEBUG_TYPE "opt-bufferization"
4444

45-
// An engineering option to allow treating hlfir.assign with realloc
46-
// attribute as never requiring (re)allocation of the LHS.
47-
// Setting it to true may result in incorrect code, so it is present
48-
// just for quicker benchmarking of apps that may benefit
49-
// from multiversioning such hlfir.assign operations under
50-
// the dynamic checks of the type/shape/allocation status.
51-
static llvm::cl::opt<bool> assumeNoLhsReallocation(
52-
"flang-assume-no-lhs-reallocation",
53-
llvm::cl::desc("Assume that hlfir.assign never (re)allocates the LHS, i.e. "
54-
"that the LHS and RHS are always conformant"),
55-
llvm::cl::init(false));
56-
5745
namespace {
5846

5947
/// This transformation should match in place modification of arrays.
@@ -474,7 +462,7 @@ ElementalAssignBufferization::findMatch(hlfir::ElementalOp elemental) {
474462
// the incoming expression
475463
match.array = match.assign.getLhs();
476464
mlir::Type arrayType = mlir::dyn_cast<fir::SequenceType>(
477-
hlfir::getFortranElementOrSequenceType(match.array.getType()));
465+
fir::unwrapPassByRefType(match.array.getType()));
478466
if (!arrayType) {
479467
LLVM_DEBUG(llvm::dbgs() << "AssignOp's result is not an array\n");
480468
return std::nullopt;
@@ -501,7 +489,7 @@ ElementalAssignBufferization::findMatch(hlfir::ElementalOp elemental) {
501489
// there is no reallocation of the lhs due to the assignment.
502490
// We can probably try generating multiple versions of the code
503491
// with checking for the shape match, length parameters match, etc.
504-
if (match.assign.isAllocatableAssignment() && !assumeNoLhsReallocation) {
492+
if (match.assign.isAllocatableAssignment()) {
505493
LLVM_DEBUG(llvm::dbgs() << "AssignOp may involve (re)allocation of LHS\n");
506494
return std::nullopt;
507495
}
@@ -624,8 +612,6 @@ llvm::LogicalResult ElementalAssignBufferization::matchAndRewrite(
624612

625613
// create the loop at the assignment
626614
builder.setInsertionPoint(match->assign);
627-
hlfir::Entity arrayObj = hlfir::derefPointersAndAllocatables(
628-
loc, builder, hlfir::Entity{match->array});
629615

630616
// Generate a loop nest looping around the hlfir.elemental shape and clone
631617
// hlfir.elemental region inside the inner loop
@@ -639,8 +625,8 @@ llvm::LogicalResult ElementalAssignBufferization::matchAndRewrite(
639625
rewriter.eraseOp(yield);
640626

641627
// Assign the element value to the array element for this iteration.
642-
auto arrayElement =
643-
hlfir::getElementAt(loc, builder, arrayObj, loopNest.oneBasedIndices);
628+
auto arrayElement = hlfir::getElementAt(
629+
loc, builder, hlfir::Entity{match->array}, loopNest.oneBasedIndices);
644630
builder.create<hlfir::AssignOp>(
645631
loc, elementValue, arrayElement, /*realloc=*/false,
646632
/*keep_lhs_length_if_realloc=*/false, match->assign.getTemporaryLhs());

0 commit comments

Comments
 (0)