================
@@ -1703,12 +1703,23 @@ class HlfirBuilder {
BinaryOp<D> binaryOp;
auto left = hlfir::loadTrivialScalar(loc, builder, gen(op.left()));
auto right = hlfir::loadTrivialScalar(loc, builder, gen(op.right()));
+
+ bool noReassoc = getConverter().getLoweringOptions().getProtectParens() &&
+ (left.template getDefiningOp<hlfir::NoReassocOp>() ||
+ right.template getDefiningOp<hlfir::NoReassocOp>());
----------------
jeanPerier wrote:
Matching the hlfir is tempting, but is it working OK with array expressions?
I would expect that the `hlfir::NoReassocOp` will be nested inside an
hlfir.elemental and that the matching will be harder. So I think it is safer to
check for parenthesis at the evaluate::Expr level.
```
real, dimension(10) :: a, b, c, d, e
b = 1.0
c = 2.0
d = 3.0
e = 4.0
a = b * (c * d * e)
print *, a
end
```
The IR will look like this:
```
%18 = hlfir.elemental %8 unordered : (!fir.shape<1>) -> !hlfir.expr<10xf32>
{
^bb0(%arg0: index):
%28 = hlfir.apply %17, %arg0 : (!hlfir.expr<10xf32>, index) -> f32
%29 = hlfir.no_reassoc %28 : f32
hlfir.yield_element %29 : f32
}
%19 = hlfir.elemental %5 unordered : (!fir.shape<1>) -> !hlfir.expr<10xf32>
{
^bb0(%arg0: index):
%28 = hlfir.designate %6#0 (%arg0) : (!fir.ref<!fir.array<10xf32>>,
index) -> !fir.ref<f32>
%29 = hlfir.apply %18, %arg0 : (!hlfir.expr<10xf32>, index) -> f32
%30 = fir.load %28 : !fir.ref<f32>
%31 = arith.mulf %30, %29 fastmath<contract> : f32
hlfir.yield_element %31 : f32
}
```
https://github.com/llvm/llvm-project/pull/170505
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits