[Mlir-commits] [mlir] c4017f9 - [mlir][sparse] Simplifying assertions in fromCOO

wren romano llvmlistbot at llvm.org
Wed Jan 19 11:25:48 PST 2022


Author: wren romano
Date: 2022-01-19T11:25:41-08:00
New Revision: c4017f9d0cf224e52df06f490902d05d1d43a4a9

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

LOG: [mlir][sparse] Simplifying assertions in fromCOO

Hoisting invariant assertions to the top

Reviewed By: aartbik

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

Added: 
    

Modified: 
    mlir/lib/ExecutionEngine/SparseTensorUtils.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
index 5333c23912f1a..9087ed1885bfa 100644
--- a/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
+++ b/mlir/lib/ExecutionEngine/SparseTensorUtils.cpp
@@ -410,16 +410,15 @@ class SparseTensorStorage : public SparseTensorStorageBase {
   void fromCOO(const std::vector<Element<V>> &elements, uint64_t lo,
                uint64_t hi, uint64_t d) {
     // Once dimensions are exhausted, insert the numerical values.
-    assert(d <= getRank());
+    assert(d <= getRank() && hi <= elements.size());
     if (d == getRank()) {
-      assert(lo < hi && hi <= elements.size());
+      assert(lo < hi);
       values.push_back(elements[lo].value);
       return;
     }
     // Visit all elements in this interval.
     uint64_t full = 0;
-    while (lo < hi) {
-      assert(lo < elements.size() && hi <= elements.size());
+    while (lo < hi) { // If `hi` is unchanged, then `lo < elements.size()`.
       // Find segment in interval with same index elements in this dimension.
       uint64_t i = elements[lo].indices[d];
       uint64_t seg = lo + 1;


        


More information about the Mlir-commits mailing list