[flang][hlfir] support dynamically optional array arguments to intrinsics with custom...
authorTom Eccles <tom.eccles@arm.com>
Thu, 13 Jul 2023 15:36:22 +0000 (15:36 +0000)
committerTom Eccles <tom.eccles@arm.com>
Tue, 18 Jul 2023 11:03:35 +0000 (11:03 +0000)
commitdb7b665c5c7136d21665555916785129460b5860
tree2951c99dd380f88b9ac59f3bf5faa42ac04969ba
parent09880ef6c977aa0c83bccc5e475f0fb8986dd7db
[flang][hlfir] support dynamically optional array arguments to intrinsics with custom handling

The previous code path created the elemental kernel by generating a
scalar intrinsic call using pre-prepared arguments using genIntrinsicRefCore,
which then generated the intrinsic call using genIntrinsicCall().

The problem with this approach was that the dynamically optional
arguments were marked as having no argLowering, which meant that they
were unconditionally passed by value without any check to see if they
were present.

It would be nice to put an if operation in the path for !argLowering,
doing something similar to genOptionalValue(). However, this can't be
done because it isn't clear what value should be used for the default.
If zero was used (like in genOptionalValue) this could effect the result
of MIN or MAX.

Instead, this patch re-uses the implementation for scalar dynamically
optional arguments (in non-elemental calls). This does the correct
thing, entirely ignoring absent optional arguments.

Depends On: D155292

Differential Revision: https://reviews.llvm.org/D155293
flang/lib/Lower/ConvertCall.cpp
flang/test/Lower/HLFIR/custom-intrinsic.f90