Skip to content

Commit 2698fc6

Browse files
authored
[RISCV] Refactor helper in isDesirableToCommuteWithShift. NFC (#119526)
Instead of duplicating the loop twice, add arguments to the lambda. I plan on reusing this in #119527
1 parent 02dd73a commit 2698fc6

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18237,41 +18237,21 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
1823718237
// LD/ST will optimize constant Offset extraction, so when AddNode is used by
1823818238
// LD/ST, it can still complete the folding optimization operation performed
1823918239
// above.
18240-
auto isUsedByLdSt = [&]() {
18241-
bool CanOptAlways = false;
18242-
if (N0->getOpcode() == ISD::ADD && !N0->hasOneUse()) {
18243-
for (SDNode *Use : N0->uses()) {
18244-
// This use is the one we're on right now. Skip it
18245-
if (Use == N || Use->getOpcode() == ISD::SELECT)
18246-
continue;
18247-
if (!isa<StoreSDNode>(Use) && !isa<LoadSDNode>(Use)) {
18248-
CanOptAlways = false;
18249-
break;
18250-
}
18251-
CanOptAlways = true;
18252-
}
18253-
}
18254-
18255-
if (N0->getOpcode() == ISD::SIGN_EXTEND &&
18256-
!N0->getOperand(0)->hasOneUse()) {
18257-
for (SDNode *Use : N0->getOperand(0)->uses()) {
18258-
// This use is the one we're on right now. Skip it
18259-
if (Use == N0.getNode() || Use->getOpcode() == ISD::SELECT)
18260-
continue;
18261-
if (!isa<StoreSDNode>(Use) && !isa<LoadSDNode>(Use)) {
18262-
CanOptAlways = false;
18263-
break;
18264-
}
18265-
CanOptAlways = true;
18266-
}
18240+
auto isUsedByLdSt = [](const SDNode *X, const SDNode *User) {
18241+
for (SDNode *Use : X->uses()) {
18242+
// This use is the one we're on right now. Skip it
18243+
if (Use == User || Use->getOpcode() == ISD::SELECT)
18244+
continue;
18245+
if (!isa<StoreSDNode>(Use) && !isa<LoadSDNode>(Use))
18246+
return false;
1826718247
}
18268-
return CanOptAlways;
18248+
return true;
1826918249
};
1827018250

1827118251
if (Ty.isScalarInteger() &&
1827218252
(N0.getOpcode() == ISD::ADD || N0.getOpcode() == ISD::OR)) {
1827318253
if (N0.getOpcode() == ISD::ADD && !N0->hasOneUse())
18274-
return isUsedByLdSt();
18254+
return isUsedByLdSt(N0.getNode(), N);
1827518255

1827618256
auto *C1 = dyn_cast<ConstantSDNode>(N0->getOperand(1));
1827718257
auto *C2 = dyn_cast<ConstantSDNode>(N->getOperand(1));
@@ -18314,7 +18294,7 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
1831418294
if (N0->getOpcode() == ISD::SIGN_EXTEND &&
1831518295
N0->getOperand(0)->getOpcode() == ISD::ADD &&
1831618296
!N0->getOperand(0)->hasOneUse())
18317-
return isUsedByLdSt();
18297+
return isUsedByLdSt(N0->getOperand(0).getNode(), N0.getNode());
1831818298

1831918299
return true;
1832018300
}

0 commit comments

Comments
 (0)