@@ -18237,41 +18237,21 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
18237
18237
// LD/ST will optimize constant Offset extraction, so when AddNode is used by
18238
18238
// LD/ST, it can still complete the folding optimization operation performed
18239
18239
// 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;
18267
18247
}
18268
- return CanOptAlways ;
18248
+ return true ;
18269
18249
};
18270
18250
18271
18251
if (Ty.isScalarInteger() &&
18272
18252
(N0.getOpcode() == ISD::ADD || N0.getOpcode() == ISD::OR)) {
18273
18253
if (N0.getOpcode() == ISD::ADD && !N0->hasOneUse())
18274
- return isUsedByLdSt();
18254
+ return isUsedByLdSt(N0.getNode(), N );
18275
18255
18276
18256
auto *C1 = dyn_cast<ConstantSDNode>(N0->getOperand(1));
18277
18257
auto *C2 = dyn_cast<ConstantSDNode>(N->getOperand(1));
@@ -18314,7 +18294,7 @@ bool RISCVTargetLowering::isDesirableToCommuteWithShift(
18314
18294
if (N0->getOpcode() == ISD::SIGN_EXTEND &&
18315
18295
N0->getOperand(0)->getOpcode() == ISD::ADD &&
18316
18296
!N0->getOperand(0)->hasOneUse())
18317
- return isUsedByLdSt();
18297
+ return isUsedByLdSt(N0->getOperand(0).getNode(), N0.getNode() );
18318
18298
18319
18299
return true;
18320
18300
}
0 commit comments