aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/Loads.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-03-06 16:10:21 +0100
committerNikita Popov <nikita.ppv@gmail.com>2021-04-03 12:10:31 +0200
commitb552e16b0b04cd216753e40990da774f4a400782 (patch)
treef1bc9e4246d8877a4b7da457a13033750185b894 /llvm/lib/Analysis/Loads.cpp
parent9d20eaf9c08c9c22aa0d13f04d8e7895c9ac05d4 (diff)
downloadllvm-b552e16b0b04cd216753e40990da774f4a400782.zip
llvm-b552e16b0b04cd216753e40990da774f4a400782.tar.gz
llvm-b552e16b0b04cd216753e40990da774f4a400782.tar.bz2
[Loads] Forward constant vector store to load of first element
InstCombine performs simple forwarding from stores to loads, but currently only handles the case where the load and store have the same size. This extends it to also handle a store of a constant with a larger size followed by a load with a smaller size. This is implemented through ConstantFoldLoadThroughBitcast() which is fairly primitive (e.g. does not allow storing a large integer and then loading a small one), but at least can forward the first element of a vector store. Unfortunately it seems that we currently don't have a generic helper for "read a constant value as a different type", it's all tangled up with other logic in either ConstantFolding or VNCoercion. Differential Revision: https://reviews.llvm.org/D98114
Diffstat (limited to 'llvm/lib/Analysis/Loads.cpp')
-rw-r--r--llvm/lib/Analysis/Loads.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp
index 9a0211f..1f3d602 100644
--- a/llvm/lib/Analysis/Loads.cpp
+++ b/llvm/lib/Analysis/Loads.cpp
@@ -495,12 +495,15 @@ static Value *getAvailableLoadStore(Instruction *Inst, const Value *Ptr,
if (!AreEquivalentAddressValues(StorePtr, Ptr))
return nullptr;
+ if (IsLoadCSE)
+ *IsLoadCSE = false;
+
Value *Val = SI->getValueOperand();
- if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL)) {
- if (IsLoadCSE)
- *IsLoadCSE = false;
+ if (CastInst::isBitOrNoopPointerCastable(Val->getType(), AccessTy, DL))
return Val;
- }
+
+ if (auto *C = dyn_cast<Constant>(Val))
+ return ConstantFoldLoadThroughBitcast(C, AccessTy, DL);
}
return nullptr;