summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2017-11-27 21:25:13 +0000
committerDavide Italiano <davide@freebsd.org>2017-11-27 21:25:13 +0000
commitb5d59e73eec454961e56316ad5140088bdc93f50 (patch)
tree666d2db8da1c101358302965467e94e9926c3f5d /llvm/lib/Transforms/Utils/Local.cpp
parent2072552360079082237f6a1aef4b00da0ee9d69d (diff)
downloadbcm5719-llvm-b5d59e73eec454961e56316ad5140088bdc93f50.tar.gz
bcm5719-llvm-b5d59e73eec454961e56316ad5140088bdc93f50.zip
[SROA] Propagate !range metadata when moving loads.
This tries to propagate !range metadata to a pre-existing load when a load is optimized out. This is done instead of adding an assume because converting loads to and from assumes creates a lot of IR. Patch by Ariel Ben-Yehuda. Differential Revision: https://reviews.llvm.org/D37216 llvm-svn: 319096
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 3f7629540be..fa429029c1f 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1947,18 +1947,24 @@ void llvm::copyNonnullMetadata(const LoadInst &OldLI, MDNode *N,
void llvm::copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI,
MDNode *N, LoadInst &NewLI) {
auto *NewTy = NewLI.getType();
+ auto *OldTy = OldLI.getType();
- // Give up unless it is converted to a pointer where there is a single very
- // valuable mapping we can do reliably.
- // FIXME: It would be nice to propagate this in more ways, but the type
- // conversions make it hard.
- if (!NewTy->isPointerTy())
+ if (DL.getTypeStoreSizeInBits(NewTy) == DL.getTypeSizeInBits(OldTy) &&
+ NewTy->isIntegerTy()) {
+ // An integer with the same number of bits - give it the range
+ // metadata!.
+ NewLI.setMetadata(LLVMContext::MD_range, N);
return;
+ }
- unsigned BitWidth = DL.getTypeSizeInBits(NewTy);
- if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) {
- MDNode *NN = MDNode::get(OldLI.getContext(), None);
- NewLI.setMetadata(LLVMContext::MD_nonnull, NN);
+ if (NewTy->isPointerTy()) {
+ // Try to convert the !range metadata to !nonnull metadata on the
+ // new pointer.
+ unsigned BitWidth = DL.getTypeSizeInBits(NewTy);
+ if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) {
+ MDNode *NN = MDNode::get(OldLI.getContext(), None);
+ NewLI.setMetadata(LLVMContext::MD_nonnull, NN);
+ }
}
}
OpenPOWER on IntegriCloud