[PATCH] D132334: [ADT] Add all_equal predicate

Jakub Kuderski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 14:45:41 PDT 2022


kuhar added inline comments.


================
Comment at: llvm/include/llvm/ADT/STLExtras.h:1770
+  auto End = adl_end(Range);
+  return Begin == End || std::equal(Begin + 1, End, Begin);
+}
----------------
dtzWill wrote:
> Hi! Just wondering, why does this use `std::equal`-- which compares ranges (here, range of [2nd to last] vs [1st to (last-1)])-- instead of something like `llvm::all_of(Range,[&](auto x)(return x == *Begin;)`?
> 
> Does this have advantages? Seems slightly more expensive this way, is why I'm asking, but I haven't bounced through the generated code or such.
This is how `is_splat` used to be implemented. `is_splat` was in fact introduced in https://reviews.llvm.org/D49958 to fix previous misuses of `std::equal` that called it incorrectly.

I haven't looked at the generated code to see which implementation would be better either.  Based on the existing uses in the code base, I don't think we ever use `all_equal` with a large enough number of elements for it to matter. But I'd be happy to know too, if you want to dig deeper.

FWIW, the implementation based on `all_of` performs one more comparison.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132334/new/

https://reviews.llvm.org/D132334



More information about the llvm-commits mailing list