diff options
| author | Nirav Dave <niravd@google.com> | 2018-11-12 14:05:40 +0000 |
|---|---|---|
| committer | Nirav Dave <niravd@google.com> | 2018-11-12 14:05:40 +0000 |
| commit | a395e2df569cd287f2765180faf6bd43e14221f6 (patch) | |
| tree | 2d15ffc8a57805ff3bcf456bc6a3d26a5f72d87f /llvm/lib/CodeGen | |
| parent | ac7c4f1db363927581d6246214c2ea93244b364a (diff) | |
| download | bcm5719-llvm-a395e2df569cd287f2765180faf6bd43e14221f6.tar.gz bcm5719-llvm-a395e2df569cd287f2765180faf6bd43e14221f6.zip | |
[DAGCombiner] Fix load-store forwarding of indexed loads.
Summary:
Handle extra output from index loads in cases where we wish to
forward a load value directly from a preceeding store.
Fixes PR39571.
Reviewers: peter.smith, rengolin
Subscribers: javed.absar, hiraditya, arphaman, llvm-commits
Differential Revision: https://reviews.llvm.org/D54265
llvm-svn: 346654
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index b6d88ee6a9d..2b6d5286180 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -12866,6 +12866,20 @@ SDValue DAGCombiner::ForwardStoreValueToDirectLoad(LoadSDNode *LD) { bool STCoversLD = (Offset >= 0) && (Offset * 8 + LDMemType.getSizeInBits() <= STMemType.getSizeInBits()); + + auto ReplaceLd = [&](LoadSDNode *LD, SDValue Val, SDValue Chain) -> SDValue { + if (LD->isIndexed()) { + bool IsSub = (LD->getAddressingMode() == ISD::PRE_DEC || + LD->getAddressingMode() == ISD::POST_DEC); + unsigned Opc = IsSub ? ISD::SUB : ISD::ADD; + SDValue Idx = DAG.getNode(Opc, SDLoc(LD), LD->getOperand(1).getValueType(), + LD->getOperand(1), LD->getOperand(2)); + SDValue Ops[] = {Val, Idx, Chain}; + return CombineTo(LD, Ops, 3); + } + return CombineTo(LD, Val, Chain); + }; + if (!STCoversLD) return SDValue(); @@ -12873,7 +12887,7 @@ SDValue DAGCombiner::ForwardStoreValueToDirectLoad(LoadSDNode *LD) { if (Offset == 0 && LDType == STType && STMemType == LDMemType) { // Simple case: Direct non-truncating forwarding if (LDType.getSizeInBits() == LDMemType.getSizeInBits()) - return CombineTo(LD, ST->getValue(), Chain); + return ReplaceLd(LD, ST->getValue(), Chain); // Can we model the truncate and extension with an and mask? if (STType.isInteger() && LDMemType.isInteger() && !STType.isVector() && !LDMemType.isVector() && LD->getExtensionType() != ISD::SEXTLOAD) { @@ -12883,7 +12897,7 @@ SDValue DAGCombiner::ForwardStoreValueToDirectLoad(LoadSDNode *LD) { STMemType.getSizeInBits()), SDLoc(ST), STType); auto Val = DAG.getNode(ISD::AND, SDLoc(LD), LDType, ST->getValue(), Mask); - return CombineTo(LD, Val, Chain); + return ReplaceLd(LD, Val, Chain); } } @@ -12908,7 +12922,7 @@ SDValue DAGCombiner::ForwardStoreValueToDirectLoad(LoadSDNode *LD) { } if (!extendLoadedValueToExtension(LD, Val)) continue; - return CombineTo(LD, Val, Chain); + return ReplaceLd(LD, Val, Chain); } while (false); // On failure, cleanup dead nodes we may have created. |

