summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeno Fischer <keno@alumni.harvard.edu>2017-05-09 21:07:20 +0000
committerKeno Fischer <keno@alumni.harvard.edu>2017-05-09 21:07:20 +0000
commit06f962c1e8c84aac3bac31ceeeeda22a58a1fb7b (patch)
treef796c5e0fd8dcc780b9dbd9b981335c57a0e6f12
parent7e3794d5c3f02b74e87e58bdce5a2e95b3334f72 (diff)
downloadbcm5719-llvm-06f962c1e8c84aac3bac31ceeeeda22a58a1fb7b.tar.gz
bcm5719-llvm-06f962c1e8c84aac3bac31ceeeeda22a58a1fb7b.zip
[GVN] Fix a crash on encountering non-integral pointers
Summary: This fixes the immediate crash caused by introducing an incorrect inttoptr before attempting the conversion. There may still be a legality check missing somewhere earlier for non-integral pointers, but this change seems necessary in any case. Reviewers: sanjoy, dberlin Reviewed By: dberlin Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32623 llvm-svn: 302587
-rw-r--r--llvm/lib/Transforms/Utils/VNCoercion.cpp9
-rw-r--r--llvm/test/Transforms/GVN/PRE/nonintegral.ll39
2 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/VNCoercion.cpp b/llvm/lib/Transforms/Utils/VNCoercion.cpp
index 83bd29dbca6..60d9ede2c48 100644
--- a/llvm/lib/Transforms/Utils/VNCoercion.cpp
+++ b/llvm/lib/Transforms/Utils/VNCoercion.cpp
@@ -303,6 +303,15 @@ static T *getStoreValueForLoadHelper(T *SrcVal, unsigned Offset, Type *LoadTy,
const DataLayout &DL) {
LLVMContext &Ctx = SrcVal->getType()->getContext();
+ // If two pointers are in the same address space, they have the same size,
+ // so we don't need to do any truncation, etc. This avoids introducing
+ // ptrtoint instructions for pointers that may be non-integral.
+ if (SrcVal->getType()->isPointerTy() && LoadTy->isPointerTy() &&
+ cast<PointerType>(SrcVal->getType())->getAddressSpace() ==
+ cast<PointerType>(LoadTy)->getAddressSpace()) {
+ return SrcVal;
+ }
+
uint64_t StoreSize = (DL.getTypeSizeInBits(SrcVal->getType()) + 7) / 8;
uint64_t LoadSize = (DL.getTypeSizeInBits(LoadTy) + 7) / 8;
// Compute which bits of the stored value are being used by the load. Convert
diff --git a/llvm/test/Transforms/GVN/PRE/nonintegral.ll b/llvm/test/Transforms/GVN/PRE/nonintegral.ll
new file mode 100644
index 00000000000..75a756e8af8
--- /dev/null
+++ b/llvm/test/Transforms/GVN/PRE/nonintegral.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -gvn -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:4"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @nipre(double addrspace(4)** noalias %p, i64 addrspace(4)** noalias %p2, i8 %jmp) {
+
+; CHECK-LABEL: @nipre(
+; CHECK: [[PCAST:%.*]] = bitcast double addrspace(4)** [[P:%.*]] to i64 addrspace(4)**
+; CHECK: a:
+; CHECK: [[L1:%.*]] = load i64 addrspace(4)*, i64 addrspace(4)** [[PCAST]]
+; CHECK: [[TMP0:%.*]] = bitcast i64 addrspace(4)* [[L1]] to double addrspace(4)*
+; CHECK: b:
+; CHECK: [[L2:%.*]] = load i64 addrspace(4)*, i64 addrspace(4)** [[PCAST]]
+; CHECK: [[TMP1:%.*]] = bitcast i64 addrspace(4)* [[L2]] to double addrspace(4)*
+; CHECK: c:
+; CHECK-NEXT: [[L3_PRE:%.*]] = load double addrspace(4)*, double addrspace(4)** %p
+
+entry:
+ %pcast = bitcast double addrspace(4)** %p to i64 addrspace(4)**
+ switch i8 %jmp, label %c [ i8 0, label %a
+ i8 1, label %b]
+a:
+ %l1 = load i64 addrspace(4)*, i64 addrspace(4)** %pcast
+ store i64 addrspace(4)* %l1, i64 addrspace(4)** %p2
+ br label %tail
+b:
+ %l2 = load i64 addrspace(4)*, i64 addrspace(4)** %pcast
+ store i64 addrspace(4)* %l2, i64 addrspace(4)** %p2
+ br label %tail
+c:
+ br label %tail
+tail:
+ %l3 = load double addrspace(4)*, double addrspace(4)** %p
+ %l3cast = bitcast double addrspace(4)* %l3 to i64 addrspace(4)*
+ store i64 addrspace(4)* %l3cast, i64 addrspace(4)** %p2
+ ret void
+}
OpenPOWER on IntegriCloud