[flang-commits] [flang] [Flang] Minloc elemental intrinsic lowering (PR #74828)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Mon Dec 18 13:37:32 PST 2023


================
@@ -659,6 +677,194 @@ mlir::LogicalResult VariableAssignBufferization::matchAndRewrite(
   return mlir::success();
 }
 
+// Look for assign(minloc(mask=elemental)) and generate the minloc loop with
+// inlined elemental and no extra temporaries.
+//  %e = hlfir.elemental %shape ({ ... })
+//  %m = hlfir.minloc %array mask %e
+//  hlfir.assign %m to %result
----------------
vzakhari wrote:

I think we should try to decompose this matching into more generic patterns rather than handling this altogether.

For the no-dim case, the result is a rank-1 array with size equal to the rank of the input.  Can we allocate a temporary array and transform the elemental+minloc into a loop nest that updates the temporary array, and keep the regular assign with the temporary array RHS?

Then we can think of optimizing the assign on its own (note that the RHS will be of compile time known shape).

https://github.com/llvm/llvm-project/pull/74828


More information about the flang-commits mailing list