[PATCH] D46657: [sanitizer] Minor 32-bit primary improvements

Aleksey Shlyapnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 14:17:54 PDT 2018


alekseyshl added inline comments.


================
Comment at: lib/sanitizer_common/sanitizer_allocator_local_cache.h:183
     if (UNLIKELY(c->count == c->max_count))
-      Drain(c, allocator, class_id);
+      Drain(c, allocator, class_id, c->max_count / 2);
     c->batch[c->count++] = p;
----------------
Drain(c, allocator, class_id, c->count / 2); is the same, but reads a bit easier, more logical ("drain half of the elements").


================
Comment at: lib/sanitizer_common/sanitizer_allocator_local_cache.h:192
       while (c->count > 0)
-        Drain(c, allocator, i);
+        Drain(c, allocator, i, Min(c->max_count / 2, c->count));
     }
----------------
Why the loop, why don't we drain the class in one call?

  Drain(c, allocator, i, c->count);

We used to have to have a loop because of the Drain API, but now we can specify the number of elements to drain.


================
Comment at: lib/sanitizer_common/sanitizer_allocator_primary32.h:305
+        class_id != SizeClassMap::kBatchClassID)) {
+      u32 rand_state = sci->rand_state;
+      RandomShuffle(pointers_array, count, &rand_state);
----------------
Add a comment why you need a local variable here, otherwise someone will "optimize" it back later or, better yet, add a local variable in RandomShuffle and let the compiler do its job generating the best code possible.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D46657





More information about the llvm-commits mailing list