Skip to content

Commit 9f302ed

Browse files
authored
[flang] Inline hlfir.eoshift during HLFIR intrinsics simplication. (#153108)
This patch generalizes the code for hlfir.cshift to be applicable for hlfir.eoshift. The major difference is the selection of the boundary value that might be statically/dynamically absent, in which case the default scalar value has to be used. The scalar value of the boundary is always computed before the hlfir.elemental or the assignment loop. Contrary to hlfir.cshift simplication, the SHIFT value is not normalized, because the original value (and its sign) participate in the EOSHIFT index computation for addressing the input array and selecting which elements of the results are assigned from the boundary operand.
1 parent 0cd35e7 commit 9f302ed

File tree

4 files changed

+2754
-133
lines changed

4 files changed

+2754
-133
lines changed

flang/lib/Optimizer/Builder/HLFIRTools.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,10 @@ hlfir::Entity hlfir::loadTrivialScalar(mlir::Location loc,
416416
entity = derefPointersAndAllocatables(loc, builder, entity);
417417
if (entity.isVariable() && entity.isScalar() &&
418418
fir::isa_trivial(entity.getFortranElementType())) {
419-
return Entity{fir::LoadOp::create(builder, loc, entity)};
419+
// Optional entities may be represented with !fir.box<i32/f32/...>.
420+
// We need to take the data pointer before loading the scalar.
421+
mlir::Value base = genVariableRawAddress(loc, builder, entity);
422+
return Entity{fir::LoadOp::create(builder, loc, base)};
420423
}
421424
return entity;
422425
}

0 commit comments

Comments
 (0)