|
|
198b24 |
From eff5dc809ed54701f2bb3e15c58d01881299cedf Mon Sep 17 00:00:00 2001
|
|
|
198b24 |
From: David Majnemer <david.majnemer@gmail.com>
|
|
|
198b24 |
Date: Tue, 11 Oct 2016 01:00:45 +0000
|
|
|
198b24 |
Subject: [rust-lang/llvm#55] [InstCombine] Transform !range metadata to
|
|
|
198b24 |
!nonnull when combining loads
|
|
|
198b24 |
|
|
|
198b24 |
When combining an integer load with !range metadata that does not include 0 to a pointer load, make sure emit !nonnull metadata on the newly-created pointer load. This prevents the !nonnull metadata from being dropped during a ptrtoint/inttoptr pair.
|
|
|
198b24 |
|
|
|
198b24 |
This fixes PR30597.
|
|
|
198b24 |
|
|
|
198b24 |
Patch by Ariel Ben-Yehuda!
|
|
|
198b24 |
|
|
|
198b24 |
Differential Revision: https://reviews.llvm.org/D25215
|
|
|
198b24 |
|
|
|
198b24 |
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283836 91177308-0d34-0410-b5e6-96231b3b80d8
|
|
|
198b24 |
---
|
|
|
198b24 |
.../InstCombine/InstCombineLoadStoreAlloca.cpp | 12 ++++++--
|
|
|
198b24 |
test/Transforms/InstCombine/PR30597.ll | 32 ++++++++++++++++++++++
|
|
|
198b24 |
2 files changed, 42 insertions(+), 2 deletions(-)
|
|
|
198b24 |
create mode 100644 test/Transforms/InstCombine/PR30597.ll
|
|
|
198b24 |
|
|
|
198b24 |
diff --git a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
|
|
|
198b24 |
index d312983ed51b..26f4e764501a 100644
|
|
|
198b24 |
--- a/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
|
|
|
198b24 |
+++ b/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
|
|
|
198b24 |
@@ -380,8 +380,16 @@ static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewT
|
|
|
198b24 |
break;
|
|
|
198b24 |
case LLVMContext::MD_range:
|
|
|
198b24 |
// FIXME: It would be nice to propagate this in some way, but the type
|
|
|
198b24 |
- // conversions make it hard. If the new type is a pointer, we could
|
|
|
198b24 |
- // translate it to !nonnull metadata.
|
|
|
198b24 |
+ // conversions make it hard.
|
|
|
198b24 |
+
|
|
|
198b24 |
+ // If it's a pointer now and the range does not contain 0, make it !nonnull.
|
|
|
198b24 |
+ if (NewTy->isPointerTy()) {
|
|
|
198b24 |
+ unsigned BitWidth = IC.getDataLayout().getTypeSizeInBits(NewTy);
|
|
|
198b24 |
+ if (!getConstantRangeFromMetadata(*N).contains(APInt(BitWidth, 0))) {
|
|
|
198b24 |
+ MDNode *NN = MDNode::get(LI.getContext(), None);
|
|
|
198b24 |
+ NewLoad->setMetadata(LLVMContext::MD_nonnull, NN);
|
|
|
198b24 |
+ }
|
|
|
198b24 |
+ }
|
|
|
198b24 |
break;
|
|
|
198b24 |
}
|
|
|
198b24 |
}
|
|
|
198b24 |
diff --git a/test/Transforms/InstCombine/PR30597.ll b/test/Transforms/InstCombine/PR30597.ll
|
|
|
198b24 |
new file mode 100644
|
|
|
198b24 |
index 000000000000..c0803ed71204
|
|
|
198b24 |
--- /dev/null
|
|
|
198b24 |
+++ b/test/Transforms/InstCombine/PR30597.ll
|
|
|
198b24 |
@@ -0,0 +1,32 @@
|
|
|
198b24 |
+; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
198b24 |
+
|
|
|
198b24 |
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
|
|
198b24 |
+target triple = "x86_64-unknown-linux-gnu"
|
|
|
198b24 |
+
|
|
|
198b24 |
+; Function Attrs: readonly uwtable
|
|
|
198b24 |
+define i1 @dot_ref_s(i32** noalias nocapture readonly dereferenceable(8)) {
|
|
|
198b24 |
+entry-block:
|
|
|
198b24 |
+ %loadedptr = load i32*, i32** %0, align 8, !nonnull !0
|
|
|
198b24 |
+ %ptrtoint = ptrtoint i32* %loadedptr to i64
|
|
|
198b24 |
+ %inttoptr = inttoptr i64 %ptrtoint to i32*
|
|
|
198b24 |
+ %switchtmp = icmp eq i32* %inttoptr, null
|
|
|
198b24 |
+ ret i1 %switchtmp
|
|
|
198b24 |
+
|
|
|
198b24 |
+; CHECK-LABEL: @dot_ref_s
|
|
|
198b24 |
+; CHECK-NEXT: entry-block:
|
|
|
198b24 |
+; CHECK-NEXT: ret i1 false
|
|
|
198b24 |
+}
|
|
|
198b24 |
+
|
|
|
198b24 |
+; Function Attrs: readonly uwtable
|
|
|
198b24 |
+define i64* @function(i64* noalias nocapture readonly dereferenceable(8)) {
|
|
|
198b24 |
+entry-block:
|
|
|
198b24 |
+ %loaded = load i64, i64* %0, align 8, !range !1
|
|
|
198b24 |
+ %inttoptr = inttoptr i64 %loaded to i64*
|
|
|
198b24 |
+ ret i64* %inttoptr
|
|
|
198b24 |
+; CHECK-LABEL: @function
|
|
|
198b24 |
+; CHECK: %{{.+}} = load i64*, i64** %{{.+}}, align 8, !nonnull
|
|
|
198b24 |
+}
|
|
|
198b24 |
+
|
|
|
198b24 |
+
|
|
|
198b24 |
+!0 = !{}
|
|
|
198b24 |
+!1 = !{i64 1, i64 140737488355327}
|
|
|
198b24 |
--
|
|
|
198b24 |
2.9.3
|
|
|
198b24 |
|