summaryrefslogtreecommitdiff
path: root/lib/IR/MDBuilder.cpp
diff options
context:
space:
mode:
authorCharles Davis <cdavis5x@gmail.com>2015-02-25 05:10:25 +0000
committerCharles Davis <cdavis5x@gmail.com>2015-02-25 05:10:25 +0000
commitfba7e30f0f850877977dd7f91b88b836fa533469 (patch)
tree49ea4a615c315a823b0dfb53f65e2ecfcf0f515f /lib/IR/MDBuilder.cpp
parent465084ffcfde0e24d46a480b4d2546f9b477bf10 (diff)
[IC] Turn non-null MD on pointer loads to range MD on integer loads.
Summary: This change fixes the FIXME that you recently added when you committed (a modified version of) my patch. When `InstCombine` combines a load and store of an pointer to those of an equivalently-sized integer, it currently drops any `!nonnull` metadata that might be present. This change replaces `!nonnull` metadata with `!range !{ 1, -1 }` metadata instead. Reviewers: chandlerc Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D7621 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230462 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR/MDBuilder.cpp')
-rw-r--r--lib/IR/MDBuilder.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/IR/MDBuilder.cpp b/lib/IR/MDBuilder.cpp
index d6d03b48d0f..a9010114044 100644
--- a/lib/IR/MDBuilder.cpp
+++ b/lib/IR/MDBuilder.cpp
@@ -55,14 +55,18 @@ MDNode *MDBuilder::createBranchWeights(ArrayRef<uint32_t> Weights) {
MDNode *MDBuilder::createRange(const APInt &Lo, const APInt &Hi) {
assert(Lo.getBitWidth() == Hi.getBitWidth() && "Mismatched bitwidths!");
+
+ Type *Ty = IntegerType::get(Context, Lo.getBitWidth());
+ return createRange(ConstantInt::get(Ty, Lo), ConstantInt::get(Ty, Hi));
+}
+
+MDNode *MDBuilder::createRange(Constant *Lo, Constant *Hi) {
// If the range is everything then it is useless.
if (Hi == Lo)
return nullptr;
// Return the range [Lo, Hi).
- Type *Ty = IntegerType::get(Context, Lo.getBitWidth());
- Metadata *Range[2] = {createConstant(ConstantInt::get(Ty, Lo)),
- createConstant(ConstantInt::get(Ty, Hi))};
+ Metadata *Range[2] = {createConstant(Lo), createConstant(Hi)};
return MDNode::get(Context, Range);
}