From c9721935835b1608f1cc0d82f852aa4d2cb39a0d Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Wed, 10 Jul 2019 11:26:57 +0000 Subject: [PATCH] [X86] EltsFromConsecutiveLoads - store Loads on a per-element basis. NFCI. Cache the LoadSDNode nodes so we can easily map to/from the element index instead of packing them together - this will be useful for future patches for PR16739 etc. llvm-svn: 365620 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 6fee0bb87646..1040cc6ae36e 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -7517,6 +7517,8 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, APInt ZeroMask = APInt::getNullValue(NumElems); APInt UndefMask = APInt::getNullValue(NumElems); + SmallVector Loads(NumElems, nullptr); + // For each element in the initializer, see if we've found a load, zero or an // undef. for (unsigned i = 0; i < NumElems; ++i) { @@ -7529,6 +7531,7 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, else if (X86::isZeroNode(Elt) || ISD::isBuildVectorAllZeros(Elt.getNode())) ZeroMask.setBit(i); else if (ISD::isNON_EXTLoad(Elt.getNode())) { + Loads[i] = cast(Elt); LoadMask.setBit(i); LastLoadedElt = i; // Each loaded element must be the correct fractional portion of the @@ -7554,7 +7557,7 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, const TargetLowering &TLI = DAG.getTargetLoweringInfo(); int FirstLoadedElt = LoadMask.countTrailingZeros(); SDValue EltBase = peekThroughBitcasts(Elts[FirstLoadedElt]); - LoadSDNode *LDBase = cast(EltBase); + LoadSDNode *LDBase = Loads[FirstLoadedElt]; EVT LDBaseVT = EltBase.getValueType(); // Consecutive loads can contain UNDEFS but not ZERO elements. @@ -7565,7 +7568,7 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, for (int i = FirstLoadedElt + 1; i <= LastLoadedElt; ++i) { if (LoadMask[i]) { SDValue Elt = peekThroughBitcasts(Elts[i]); - LoadSDNode *LD = cast(Elt); + LoadSDNode* LD = Loads[i]; if (!DAG.areNonVolatileConsecutiveLoads( LD, LDBase, Elt.getValueType().getStoreSizeInBits() / 8, i - FirstLoadedElt)) { @@ -7578,11 +7581,6 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, } } - SmallVector Loads; - for (int i = FirstLoadedElt; i <= LastLoadedElt; ++i) - if (LoadMask[i]) - Loads.push_back(cast(peekThroughBitcasts(Elts[i]))); - auto CreateLoad = [&DAG, &DL, &Loads](EVT VT, LoadSDNode *LDBase) { auto MMOFlags = LDBase->getMemOperand()->getFlags(); assert(!(MMOFlags & MachineMemOperand::MOVolatile) && @@ -7591,7 +7589,8 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, DAG.getLoad(VT, DL, LDBase->getChain(), LDBase->getBasePtr(), LDBase->getPointerInfo(), LDBase->getAlignment(), MMOFlags); for (auto *LD : Loads) - DAG.makeEquivalentMemoryOrdering(LD, NewLd); + if (LD) + DAG.makeEquivalentMemoryOrdering(LD, NewLd); return NewLd; }; @@ -7682,7 +7681,8 @@ static SDValue EltsFromConsecutiveLoads(EVT VT, ArrayRef Elts, LDBase->getAlignment(), MachineMemOperand::MOLoad); for (auto *LD : Loads) - DAG.makeEquivalentMemoryOrdering(LD, ResNode); + if (LD) + DAG.makeEquivalentMemoryOrdering(LD, ResNode); return DAG.getBitcast(VT, ResNode); } }