Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 9daabae

Browse files
committed
Prevent X86ISelLowering from merging volatile loads
Change isConsecutiveLoads to check that loads are non-volatile as this is a requirement for any load merges. Propagate change to two callers. Reviewers: RKSimon Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18546 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265013 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8cd0a25 commit 9daabae

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

include/llvm/CodeGen/SelectionDAG.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,10 +1284,12 @@ class SelectionDAG {
12841284
/// vector op and fill the end of the resulting vector with UNDEFS.
12851285
SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
12861286

1287-
/// Return true if LD is loading 'Bytes' bytes from a location that is 'Dist'
1288-
/// units away from the location that the 'Base' load is loading from.
1289-
bool isConsecutiveLoad(LoadSDNode *LD, LoadSDNode *Base,
1290-
unsigned Bytes, int Dist) const;
1287+
/// Return true if loads are next to each other and can be
1288+
/// merged. Check that both are nonvolatile and if LD is loading
1289+
/// 'Bytes' bytes from a location that is 'Dist' units away from the
1290+
/// location that the 'Base' load is loading from.
1291+
bool areNonVolatileConsecutiveLoads(LoadSDNode *LD, LoadSDNode *Base,
1292+
unsigned Bytes, int Dist) const;
12911293

12921294
/// Infer alignment of a load / store address. Return 0 if
12931295
/// it cannot be inferred.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7251,14 +7251,9 @@ SDValue DAGCombiner::CombineConsecutiveLoads(SDNode *N, EVT VT) {
72517251
LD1->getAddressSpace() != LD2->getAddressSpace())
72527252
return SDValue();
72537253
EVT LD1VT = LD1->getValueType(0);
7254-
7255-
if (ISD::isNON_EXTLoad(LD2) &&
7256-
LD2->hasOneUse() &&
7257-
// If both are volatile this would reduce the number of volatile loads.
7258-
// If one is volatile it might be ok, but play conservative and bail out.
7259-
!LD1->isVolatile() &&
7260-
!LD2->isVolatile() &&
7261-
DAG.isConsecutiveLoad(LD2, LD1, LD1VT.getSizeInBits()/8, 1)) {
7254+
unsigned LD1Bytes = LD1VT.getSizeInBits() / 8;
7255+
if (ISD::isNON_EXTLoad(LD2) && LD2->hasOneUse() &&
7256+
DAG.areNonVolatileConsecutiveLoads(LD2, LD1, LD1Bytes, 1)) {
72627257
unsigned Align = LD1->getAlignment();
72637258
unsigned NewAlign = DAG.getDataLayout().getABITypeAlignment(
72647259
VT.getTypeForEVT(*DAG.getContext()));

lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6959,12 +6959,12 @@ SDValue SelectionDAG::UnrollVectorOp(SDNode *N, unsigned ResNE) {
69596959
EVT::getVectorVT(*getContext(), EltVT, ResNE), Scalars);
69606960
}
69616961

6962-
6963-
/// isConsecutiveLoad - Return true if LD is loading 'Bytes' bytes from a
6964-
/// location that is 'Dist' units away from the location that the 'Base' load
6965-
/// is loading from.
6966-
bool SelectionDAG::isConsecutiveLoad(LoadSDNode *LD, LoadSDNode *Base,
6967-
unsigned Bytes, int Dist) const {
6962+
bool SelectionDAG::areNonVolatileConsecutiveLoads(LoadSDNode *LD,
6963+
LoadSDNode *Base,
6964+
unsigned Bytes,
6965+
int Dist) const {
6966+
if (LD->isVolatile() || Base->isVolatile())
6967+
return false;
69686968
if (LD->getChain() != Base->getChain())
69696969
return false;
69706970
EVT VT = LD->getValueType(0);

lib/Target/X86/X86ISelLowering.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5736,9 +5736,9 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef<SDValue> Elts,
57365736
if (LoadMask[i]) {
57375737
SDValue Elt = peekThroughBitcasts(Elts[i]);
57385738
LoadSDNode *LD = cast<LoadSDNode>(Elt);
5739-
if (!DAG.isConsecutiveLoad(LD, LDBase,
5740-
Elt.getValueType().getStoreSizeInBits() / 8,
5741-
i - FirstLoadedElt)) {
5739+
if (!DAG.areNonVolatileConsecutiveLoads(
5740+
LD, LDBase, Elt.getValueType().getStoreSizeInBits() / 8,
5741+
i - FirstLoadedElt)) {
57425742
IsConsecutiveLoad = false;
57435743
IsConsecutiveLoadWithZeros = false;
57445744
break;
@@ -5749,10 +5749,10 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef<SDValue> Elts,
57495749
}
57505750

57515751
auto CreateLoad = [&DAG, &DL](EVT VT, LoadSDNode *LDBase) {
5752-
SDValue NewLd = DAG.getLoad(VT, DL, LDBase->getChain(),
5753-
LDBase->getBasePtr(), LDBase->getPointerInfo(),
5754-
LDBase->isVolatile(), LDBase->isNonTemporal(),
5755-
LDBase->isInvariant(), LDBase->getAlignment());
5752+
SDValue NewLd = DAG.getLoad(
5753+
VT, DL, LDBase->getChain(), LDBase->getBasePtr(),
5754+
LDBase->getPointerInfo(), false /*LDBase->isVolatile()*/,
5755+
LDBase->isNonTemporal(), LDBase->isInvariant(), LDBase->getAlignment());
57565756

57575757
if (LDBase->hasAnyUseOfValue(1)) {
57585758
SDValue NewChain =

0 commit comments

Comments
 (0)