[Mlir-commits] [mlir] 6600301 - [mlir][llvm] Improve access group import handling.

Tobias Gysi llvmlistbot at llvm.org
Thu Apr 20 04:33:24 PDT 2023


Author: Tobias Gysi
Date: 2023-04-20T11:32:22Z
New Revision: 6600301c2fbfa3ed3619b62d46edee148cda85b1

URL: https://github.com/llvm/llvm-project/commit/6600301c2fbfa3ed3619b62d46edee148cda85b1
DIFF: https://github.com/llvm/llvm-project/commit/6600301c2fbfa3ed3619b62d46edee148cda85b1.diff

LOG: [mlir][llvm] Improve access group import handling.

In particular, do not drop all access groups of a loop annotation
if one of them is unused. This change makes the access group import
robust against stale access group references in loop metadata.

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D148791

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
    mlir/test/Target/LLVMIR/Import/import-failure.ll
    mlir/test/Target/LLVMIR/Import/metadata-loop.ll

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp b/mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
index c086f4c318e70..000349091afce 100644
--- a/mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
+++ b/mlir/lib/Target/LLVMIR/LoopAnnotationImporter.cpp
@@ -396,8 +396,10 @@ LoopMetadataConversion::convertParallelAccesses() {
   for (llvm::MDNode *node : *nodes) {
     FailureOr<SmallVector<SymbolRefAttr>> accessGroups =
         loopAnnotationImporter.lookupAccessGroupAttrs(node);
-    if (failed(accessGroups))
-      return emitWarning(loc) << "could not lookup access group";
+    if (failed(accessGroups)) {
+      emitWarning(loc) << "could not lookup access group";
+      continue;
+    }
     llvm::append_range(refs, *accessGroups);
   }
   return refs;

diff  --git a/mlir/test/Target/LLVMIR/Import/import-failure.ll b/mlir/test/Target/LLVMIR/Import/import-failure.ll
index 0db585ed846b7..33bd8c8a1f365 100644
--- a/mlir/test/Target/LLVMIR/Import/import-failure.ll
+++ b/mlir/test/Target/LLVMIR/Import/import-failure.ll
@@ -309,6 +309,23 @@ end:
 
 ; // -----
 
+; CHECK:      import-failure.ll
+; CHECK-SAME: warning: could not lookup access group
+define void @unused_access_group(ptr %arg) {
+entry:
+  %0 = load i32, ptr %arg, !llvm.access.group !0
+  br label %end, !llvm.loop !1
+end:
+  ret void
+}
+
+!0 = distinct !{}
+!1 = distinct !{!1, !2}
+!2 = !{!"llvm.loop.parallel_accesses", !0, !3}
+!3 = distinct !{}
+
+; // -----
+
 ; CHECK:      import-failure.ll
 ; CHECK-SAME: warning: expected function_entry_count to be attached to a function
 ; CHECK:      warning: unhandled metadata: !0 = !{!"function_entry_count", i64 42}

diff  --git a/mlir/test/Target/LLVMIR/Import/metadata-loop.ll b/mlir/test/Target/LLVMIR/Import/metadata-loop.ll
index fadb22b624755..859f7377a3eb1 100644
--- a/mlir/test/Target/LLVMIR/Import/metadata-loop.ll
+++ b/mlir/test/Target/LLVMIR/Import/metadata-loop.ll
@@ -323,3 +323,23 @@ end:
 !1 = distinct !{!1, !2}
 !2 = !{!"llvm.loop.parallel_accesses", !0, !3}
 !3 = distinct !{}
+
+; // -----
+
+; Verify the unused access group is not imported.
+; CHECK:   llvm.metadata @__llvm_global_metadata {
+; CHECK-COUNT1: llvm.access_group
+
+; CHECK-LABEL: @unused_parallel_access
+define void @unused_parallel_access(ptr %arg) {
+entry:
+  %0 = load i32, ptr %arg, !llvm.access.group !0
+  br label %end, !llvm.loop !1
+end:
+  ret void
+}
+
+!0 = distinct !{}
+!1 = distinct !{!1, !2}
+!2 = !{!"llvm.loop.parallel_accesses", !0, !3}
+!3 = distinct !{}


        


More information about the Mlir-commits mailing list