@@ -14245,17 +14245,23 @@ static SDValue combineBVOfConsecutiveLoads(SDNode *N, SelectionDAG &DAG) {
14245
14245
unsigned ElemSize = N->getValueType(0).getScalarType().getStoreSize();
14246
14246
SDValue FirstInput = N->getOperand(0);
14247
14247
bool IsRoundOfExtLoad = false;
14248
+ LoadSDNode *FirstLoad = nullptr;
14248
14249
14249
14250
if (FirstInput.getOpcode() == ISD::FP_ROUND &&
14250
14251
FirstInput.getOperand(0).getOpcode() == ISD::LOAD) {
14251
- LoadSDNode *LD = dyn_cast <LoadSDNode>(FirstInput.getOperand(0));
14252
- IsRoundOfExtLoad = LD ->getExtensionType() == ISD::EXTLOAD;
14252
+ FirstLoad = cast <LoadSDNode>(FirstInput.getOperand(0));
14253
+ IsRoundOfExtLoad = FirstLoad ->getExtensionType() == ISD::EXTLOAD;
14253
14254
}
14254
14255
// Not a build vector of (possibly fp_rounded) loads.
14255
14256
if ((!IsRoundOfExtLoad && FirstInput.getOpcode() != ISD::LOAD) ||
14256
14257
N->getNumOperands() == 1)
14257
14258
return SDValue();
14258
14259
14260
+ if (!IsRoundOfExtLoad)
14261
+ FirstLoad = cast<LoadSDNode>(FirstInput);
14262
+
14263
+ SmallVector<LoadSDNode *, 4> InputLoads;
14264
+ InputLoads.push_back(FirstLoad);
14259
14265
for (int i = 1, e = N->getNumOperands(); i < e; ++i) {
14260
14266
// If any inputs are fp_round(extload), they all must be.
14261
14267
if (IsRoundOfExtLoad && N->getOperand(i).getOpcode() != ISD::FP_ROUND)
@@ -14268,53 +14274,55 @@ static SDValue combineBVOfConsecutiveLoads(SDNode *N, SelectionDAG &DAG) {
14268
14274
14269
14275
SDValue PreviousInput =
14270
14276
IsRoundOfExtLoad ? N->getOperand(i-1).getOperand(0) : N->getOperand(i-1);
14271
- LoadSDNode *LD1 = dyn_cast <LoadSDNode>(PreviousInput);
14272
- LoadSDNode *LD2 = dyn_cast <LoadSDNode>(NextInput);
14277
+ LoadSDNode *LD1 = cast <LoadSDNode>(PreviousInput);
14278
+ LoadSDNode *LD2 = cast <LoadSDNode>(NextInput);
14273
14279
14274
14280
// If any inputs are fp_round(extload), they all must be.
14275
14281
if (IsRoundOfExtLoad && LD2->getExtensionType() != ISD::EXTLOAD)
14276
14282
return SDValue();
14277
14283
14278
- if (!isConsecutiveLS(LD2, LD1, ElemSize, 1, DAG))
14284
+ // We only care about regular loads. The PPC-specific load intrinsics
14285
+ // will not lead to a merge opportunity.
14286
+ if (!DAG.areNonVolatileConsecutiveLoads(LD2, LD1, ElemSize, 1))
14279
14287
InputsAreConsecutiveLoads = false;
14280
- if (!isConsecutiveLS (LD1, LD2, ElemSize, 1, DAG ))
14288
+ if (!DAG.areNonVolatileConsecutiveLoads (LD1, LD2, ElemSize, 1))
14281
14289
InputsAreReverseConsecutive = false;
14282
14290
14283
14291
// Exit early if the loads are neither consecutive nor reverse consecutive.
14284
14292
if (!InputsAreConsecutiveLoads && !InputsAreReverseConsecutive)
14285
14293
return SDValue();
14294
+ InputLoads.push_back(LD2);
14286
14295
}
14287
14296
14288
14297
assert(!(InputsAreConsecutiveLoads && InputsAreReverseConsecutive) &&
14289
14298
"The loads cannot be both consecutive and reverse consecutive.");
14290
14299
14291
- SDValue FirstLoadOp =
14292
- IsRoundOfExtLoad ? FirstInput.getOperand(0) : FirstInput;
14293
- SDValue LastLoadOp =
14294
- IsRoundOfExtLoad ? N->getOperand(N->getNumOperands()-1).getOperand(0) :
14295
- N->getOperand(N->getNumOperands()-1);
14296
-
14297
- LoadSDNode *LD1 = dyn_cast<LoadSDNode>(FirstLoadOp);
14298
- LoadSDNode *LDL = dyn_cast<LoadSDNode>(LastLoadOp);
14300
+ SDValue WideLoad;
14301
+ SDValue ReturnSDVal;
14299
14302
if (InputsAreConsecutiveLoads) {
14300
- assert(LD1 && "Input needs to be a LoadSDNode.");
14301
- return DAG.getLoad(N->getValueType(0), dl, LD1->getChain(),
14302
- LD1->getBasePtr(), LD1->getPointerInfo(),
14303
- LD1->getAlign());
14304
- }
14305
- if (InputsAreReverseConsecutive) {
14306
- assert(LDL && "Input needs to be a LoadSDNode.");
14307
- SDValue Load =
14308
- DAG.getLoad(N->getValueType(0), dl, LDL->getChain(), LDL->getBasePtr(),
14309
- LDL->getPointerInfo(), LDL->getAlign());
14303
+ assert(FirstLoad && "Input needs to be a LoadSDNode.");
14304
+ WideLoad = DAG.getLoad(N->getValueType(0), dl, FirstLoad->getChain(),
14305
+ FirstLoad->getBasePtr(), FirstLoad->getPointerInfo(),
14306
+ FirstLoad->getAlign());
14307
+ ReturnSDVal = WideLoad;
14308
+ } else if (InputsAreReverseConsecutive) {
14309
+ LoadSDNode *LastLoad = InputLoads.back();
14310
+ assert(LastLoad && "Input needs to be a LoadSDNode.");
14311
+ WideLoad = DAG.getLoad(N->getValueType(0), dl, LastLoad->getChain(),
14312
+ LastLoad->getBasePtr(), LastLoad->getPointerInfo(),
14313
+ LastLoad->getAlign());
14310
14314
SmallVector<int, 16> Ops;
14311
14315
for (int i = N->getNumOperands() - 1; i >= 0; i--)
14312
14316
Ops.push_back(i);
14313
14317
14314
- return DAG.getVectorShuffle(N->getValueType(0), dl, Load,
14315
- DAG.getUNDEF(N->getValueType(0)), Ops);
14316
- }
14317
- return SDValue();
14318
+ ReturnSDVal = DAG.getVectorShuffle(N->getValueType(0), dl, WideLoad,
14319
+ DAG.getUNDEF(N->getValueType(0)), Ops);
14320
+ } else
14321
+ return SDValue();
14322
+
14323
+ for (auto *LD : InputLoads)
14324
+ DAG.makeEquivalentMemoryOrdering(LD, WideLoad);
14325
+ return ReturnSDVal;
14318
14326
}
14319
14327
14320
14328
// This function adds the required vector_shuffle needed to get
0 commit comments