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

David Green via flang-commits flang-commits at lists.llvm.org
Fri Jan 12 07:07:17 PST 2024


================
@@ -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
----------------
davemgreen wrote:

I've had a go at making this work as minloc(elemental), not handling the assign as the same time. A lot of the benefit of this patch was from aiming to produce less temporaries, writing straight into the result is going to produce better final code than having multiple temporaries being written and copied again and again.

But I think it can work OK here so long as the assign is simple enough and get optimized away in the end. The one thing it needs to be careful of is to make sure that any assign uses of the minloc is applied to the temp array, not a new asexpr, so that the VariableAssignBufferization from this pass has a chance to kick-in. Let me know what you think.

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


More information about the flang-commits mailing list