[llvm] [RISCV] Refactor helper in isDesirableToCommuteWithShift. NFC (PR #119526)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 00:48:15 PST 2024
https://github.com/lukel97 updated https://github.com/llvm/llvm-project/pull/119526
>From bda048a5133ea821e4aee2397d89f1dec50cbf9b Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Wed, 11 Dec 2024 16:39:42 +0800
Subject: [PATCH] [RISCV] Refactor helper in isDesirableToCommuteWithShift. NFC
Instead of duplicating the loop twice, add arguments to the lambda.
I plan on reusing this in a following patch.
---
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 40 ++++++---------------
1 file changed, 10 insertions(+), 30 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index c6838573637202..bf919122452628 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -18237,41 +18237,21 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
// LD/ST will optimize constant Offset extraction, so when AddNode is used by
// LD/ST, it can still complete the folding optimization operation performed
// above.
- auto isUsedByLdSt = [&]() {
- bool CanOptAlways = false;
- if (N0->getOpcode() == ISD::ADD && !N0->hasOneUse()) {
- for (SDNode *Use : N0->uses()) {
- // This use is the one we're on right now. Skip it
- if (Use == N || Use->getOpcode() == ISD::SELECT)
- continue;
- if (!isa<StoreSDNode>(Use) && !isa<LoadSDNode>(Use)) {
- CanOptAlways = false;
- break;
- }
- CanOptAlways = true;
- }
- }
-
- if (N0->getOpcode() == ISD::SIGN_EXTEND &&
- !N0->getOperand(0)->hasOneUse()) {
- for (SDNode *Use : N0->getOperand(0)->uses()) {
- // This use is the one we're on right now. Skip it
- if (Use == N0.getNode() || Use->getOpcode() == ISD::SELECT)
- continue;
- if (!isa<StoreSDNode>(Use) && !isa<LoadSDNode>(Use)) {
- CanOptAlways = false;
- break;
- }
- CanOptAlways = true;
- }
+ auto isUsedByLdSt = [](const SDNode *X, const SDNode *User) {
+ for (SDNode *Use : X->uses()) {
+ // This use is the one we're on right now. Skip it
+ if (Use == User || Use->getOpcode() == ISD::SELECT)
+ continue;
+ if (!isa<StoreSDNode>(Use) && !isa<LoadSDNode>(Use))
+ return false;
}
- return CanOptAlways;
+ return true;
};
if (Ty.isScalarInteger() &&
(N0.getOpcode() == ISD::ADD || N0.getOpcode() == ISD::OR)) {
if (N0.getOpcode() == ISD::ADD && !N0->hasOneUse())
- return isUsedByLdSt();
+ return isUsedByLdSt(N0.getNode(), N);
auto *C1 = dyn_cast<ConstantSDNode>(N0->getOperand(1));
auto *C2 = dyn_cast<ConstantSDNode>(N->getOperand(1));
@@ -18314,7 +18294,7 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
if (N0->getOpcode() == ISD::SIGN_EXTEND &&
N0->getOperand(0)->getOpcode() == ISD::ADD &&
!N0->getOperand(0)->hasOneUse())
- return isUsedByLdSt();
+ return isUsedByLdSt(N0->getOperand(0).getNode(), N0.getNode());
return true;
}
More information about the llvm-commits
mailing list