Index: flang/lib/Evaluate/tools.cpp =================================================================== --- flang/lib/Evaluate/tools.cpp +++ flang/lib/Evaluate/tools.cpp @@ -19,6 +19,14 @@ namespace Fortran::evaluate { +// Can x*(a,b) be represented as (x*a,x*b)? This code duplication +// of the subexpression "x" cannot (yet?) be reliably undone by +// common subexpression elimination in lowering, so it's disabled +// here for now to avoid the risk of potential duplication of +// expensive subexpressions (e.g., large array expressions, references +// to expensive functions) in generate code. +static constexpr bool allowOperandDuplication{false}; + std::optional> AsGenericExpr(DataRef &&ref) { const Symbol &symbol{ref.GetLastSymbol()}; if (auto dyType{DynamicType::From(symbol)}) { @@ -250,7 +258,7 @@ template