Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -8558,11 +8558,11 @@ if (LoadSDNode *LD = dyn_cast(Use)) { if (LD->isIndexed() || LD->getBasePtr().getNode() != N) return false; - VT = Use->getValueType(0); + VT = LD->getMemoryVT(); } else if (StoreSDNode *ST = dyn_cast(Use)) { if (ST->isIndexed() || ST->getBasePtr().getNode() != N) return false; - VT = ST->getValue().getValueType(); + VT = ST->getMemoryVT(); } else return false; @@ -8850,8 +8850,7 @@ return false; for (SDNode *Op : Ptr.getNode()->uses()) { - if (Op == N || - (Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB)) + if (Op->getOpcode() != ISD::ADD && Op->getOpcode() != ISD::SUB) continue; SDValue BasePtr; @@ -8874,28 +8873,18 @@ continue; // Check for #1. - bool TryNext = false; - for (SDNode *Use : BasePtr.getNode()->uses()) { - if (Use == Ptr.getNode()) - continue; - - // If all the uses are load / store addresses, then don't do the - // transformation. - if (Use->getOpcode() == ISD::ADD || Use->getOpcode() == ISD::SUB){ - bool RealUse = false; - for (SDNode *UseUse : Use->uses()) { - if (!canFoldInAddressingMode(Use, UseUse, DAG, TLI)) - RealUse = true; - } - - if (!RealUse) { - TryNext = true; - break; - } + // Look for a RealUse, i.e. one use that is not a load / store op, or one + // that cannot be folded as addressing mode + // If one use is not a load / store address, then do the transformation. + bool RealUse = false; + for (SDNode *OpUse : Op->uses()) { + if (!canFoldInAddressingMode(Op, OpUse, DAG, TLI)) { + RealUse = true; + break; } } - if (TryNext) + if (!RealUse) continue; // Check for #2