[llvm] [lldb] [mlir] [mlir] Introduce replaceWithZeroTripCheck in LoopLikeOpInterface (PR #80331)

Diego Caballero via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 19:08:35 PST 2024


================
@@ -220,6 +220,28 @@ def LoopLikeOpInterface : OpInterface<"LoopLikeOpInterface"> {
       /*defaultImplementation=*/[{
         return ::mlir::failure();
       }]
+    >,
+    InterfaceMethod<[{
+        Add a zero-trip-check around the loop to check if the loop body is ever
+        run and return the new loop inside the check. The loop body is moved
+        over to the new loop. Returns "failure" if the loop doesn't support
+        this transformation.
+
+        After the transformation, the ops inserted to the parent region of the
+        loop are guaranteed to be run only if the loop body runs at least one
+        iteration.
+
+        Note: Ops in the loop body might be rearranged because of loop rotating
+        to maintain the semantic. Terminators might be removed/added during this
+        transformation.
----------------
dcaballe wrote:

You can also mention that loop conditions might be checked redundantly so they are expected to not have side effects and that the utility won't check that but just apply the transformation.

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


More information about the llvm-commits mailing list