From 69921f6f4558a2c5c8e48c5b12d83a65127bfecc Mon Sep 17 00:00:00 2001 From: Anna Thomas Date: Mon, 20 Sep 2021 16:37:38 -0400 Subject: [InstCombine] Improve TryToSinkInstruction with multiple uses This patch allows sinking an instruction which can have multiple uses in a single user. We were previously over-restrictive by looking for exactly one use, rather than one user. Also added an API for retrieving a unique undroppable user. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D109700 --- llvm/lib/IR/Value.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/IR/Value.cpp') diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index a13380b..0f11bf61 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -176,6 +176,18 @@ Use *Value::getSingleUndroppableUse() { return Result; } +User *Value::getUniqueUndroppableUser() { + User *Result = nullptr; + for (auto *U : users()) { + if (!U->isDroppable()) { + if (Result && Result != U) + return nullptr; + Result = U; + } + } + return Result; +} + bool Value::hasNUndroppableUses(unsigned int N) const { return hasNItems(user_begin(), user_end(), N, isUnDroppableUser); } -- cgit v1.1