Skip to content

Commit

Permalink
[DAGCombine] NFC. MatchLoadCombine extract MemoryByteOffset lambda he…
Browse files Browse the repository at this point in the history
…lper

This refactoring will simplify the upcoming change to fix the bug in folding patterns with non-zero offsets on BE targets.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296332 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arpilipe committed Feb 27, 2017
1 parent 0003ac9 commit f854325
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4516,16 +4516,25 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
std::function<unsigned(unsigned, unsigned)> BigEndianByteAt = [](
unsigned BW, unsigned i) { return BW - i - 1; };

bool IsBigEndianTarget = DAG.getDataLayout().isBigEndian();
auto MemoryByteOffset = [&] (ByteProvider P) {
assert(P.isMemory() && "Must be a memory byte provider");
unsigned LoadBitWidth = P.Load->getMemoryVT().getSizeInBits();
assert(LoadBitWidth % 8 == 0 &&
"can only analyze providers for individual bytes not bit");
unsigned LoadByteWidth = LoadBitWidth / 8;
return IsBigEndianTarget
? BigEndianByteAt(LoadByteWidth, P.ByteOffset)
: LittleEndianByteAt(LoadByteWidth, P.ByteOffset);
};

Optional<BaseIndexOffset> Base;
SDValue Chain;

SmallSet<LoadSDNode *, 8> Loads;
Optional<ByteProvider> FirstByteProvider;
int64_t FirstOffset = INT64_MAX;

bool IsBigEndianTarget = DAG.getDataLayout().isBigEndian();
auto ByteAt = IsBigEndianTarget ? BigEndianByteAt : LittleEndianByteAt;

// Check if all the bytes of the OR we are looking at are loaded from the same
// base address. Collect bytes offsets from Base address in ByteOffsets.
SmallVector<int64_t, 4> ByteOffsets(ByteWidth);
Expand Down Expand Up @@ -4555,12 +4564,7 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
return SDValue();

// Calculate the offset of the current byte from the base address
unsigned LoadBitWidth = L->getMemoryVT().getSizeInBits();
assert(LoadBitWidth % 8 == 0 &&
"can only analyze providers for individual bytes not bit");
unsigned LoadByteWidth = LoadBitWidth / 8;
int64_t MemoryByteOffset = ByteAt(LoadByteWidth, P->ByteOffset);
int64_t ByteOffsetFromBase = Ptr.Offset + MemoryByteOffset;
int64_t ByteOffsetFromBase = Ptr.Offset + MemoryByteOffset(*P);
ByteOffsets[i] = ByteOffsetFromBase;

// Remember the first byte load
Expand Down

0 comments on commit f854325

Please sign in to comment.