summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2016-08-08 01:30:53 +0000
committerEli Friedman <eli.friedman@gmail.com>2016-08-08 01:30:53 +0000
commit2a65dd1ba608aa2477a397f58194c505ba69cf83 (patch)
tree9ae2a0c0515b4b8a2aacb6725aa35f0a778a91f1
parent2fdf202493fcef9a3cf7c1b14843090d9eef2539 (diff)
downloadbcm5719-llvm-2a65dd1ba608aa2477a397f58194c505ba69cf83.tar.gz
bcm5719-llvm-2a65dd1ba608aa2477a397f58194c505ba69cf83.zip
[SROA] Fix crash with lifetime intrinsic partially covering alloca.
Summary: PromoteMemToReg looks specifically for the pattern bitcast+lifetime.start (or a bitcast-equivalent GEP); any offset will lead to an assertion failure. Fixes https://llvm.org/bugs/show_bug.cgi?id=27999 . Differential Revision: https://reviews.llvm.org/D22737 llvm-svn: 277969
-rw-r--r--llvm/lib/Transforms/Scalar/SROA.cpp8
-rw-r--r--llvm/test/Transforms/SROA/basictest.ll15
2 files changed, 22 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 7d33259c030..67d90a346f2 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -2890,7 +2890,13 @@ private:
(void)New;
DEBUG(dbgs() << " to: " << *New << "\n");
- return true;
+
+ // Lifetime intrinsics are only promotable if they cover the whole alloca.
+ // (In theory, intrinsics which partially cover an alloca could be
+ // promoted, but PromoteMemToReg doesn't handle that case.)
+ bool IsWholeAlloca = NewBeginOffset == NewAllocaBeginOffset &&
+ NewEndOffset == NewAllocaEndOffset;
+ return IsWholeAlloca;
}
bool visitPHINode(PHINode &PN) {
diff --git a/llvm/test/Transforms/SROA/basictest.ll b/llvm/test/Transforms/SROA/basictest.ll
index 968669ad4f6..75fe279849d 100644
--- a/llvm/test/Transforms/SROA/basictest.ll
+++ b/llvm/test/Transforms/SROA/basictest.ll
@@ -1669,3 +1669,18 @@ entry:
}
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
+
+define void @PR27999() unnamed_addr {
+; CHECK-LABEL: @PR27999(
+; CHECK: alloca [2 x i64], align 8
+; CHECK: call void @llvm.lifetime.start(i64 16,
+; CHECK: call void @llvm.lifetime.end(i64 8,
+entry-block:
+ %0 = alloca [2 x i64], align 8
+ %1 = bitcast [2 x i64]* %0 to i8*
+ call void @llvm.lifetime.start(i64 16, i8* %1)
+ %2 = getelementptr inbounds [2 x i64], [2 x i64]* %0, i32 0, i32 1
+ %3 = bitcast i64* %2 to i8*
+ call void @llvm.lifetime.end(i64 8, i8* %3)
+ ret void
+}
OpenPOWER on IntegriCloud