summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
authorArtur Pilipenko <apilipenko@azulsystems.com>2017-02-27 11:42:54 +0000
committerArtur Pilipenko <apilipenko@azulsystems.com>2017-02-27 11:42:54 +0000
commitc43b20a43b3386bb87635f78b39fcb0680b83389 (patch)
tree386ac114b1b53837f0b5009d1dfc760d834a00f8 /llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
parentf2c26e0bf23502ce55c7b855550ce9aa03008c39 (diff)
downloadbcm5719-llvm-c43b20a43b3386bb87635f78b39fcb0680b83389.tar.gz
bcm5719-llvm-c43b20a43b3386bb87635f78b39fcb0680b83389.zip
[DAGCombine] NFC. MatchLoadCombine extract MemoryByteOffset lambda helper
This refactoring will simplify the upcoming change to fix the bug in folding patterns with non-zero offsets on BE targets. llvm-svn: 296332
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 34be7766b57..26cb3a69cf6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4516,6 +4516,18 @@ 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;
@@ -4523,9 +4535,6 @@ SDValue DAGCombiner::MatchLoadCombine(SDNode *N) {
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);
@@ -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
OpenPOWER on IntegriCloud