[llvm] [ExpandMemCmp] Improve memcmp optimisation for boolean results (PR #71221)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 3 12:43:25 PDT 2023
================
@@ -656,6 +658,40 @@ Value *MemCmpExpansion::getMemCmpOneBlock() {
const LoadPair Loads = getLoadPair(LoadSizeType, BSwapSizeType, MaxLoadType,
/*Offset*/ 0);
+
+ // If a user of memcmp cares only about two outcomes, for example:
+ // bool result = memcmp(a, b, NBYTES) > 0;
+ // We can generate more optimal code with a smaller number of operations
+ if (auto *U = CI->getUniqueUndroppableUser()) {
----------------
nikic wrote:
You are looking for hasOneUse(). If you use getUniqueUndroppableUser() you actually need to drop droppable users.
https://github.com/llvm/llvm-project/pull/71221
More information about the llvm-commits
mailing list