aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Seaborn <mseaborn@chromium.org>2013-05-31 09:56:47 -0700
committerMark Seaborn <mseaborn@chromium.org>2013-05-31 09:56:47 -0700
commitb74fb76de6dba430089e94fd5e8d0fa856cda3cc (patch)
treef2f11f6e40421cc3803a52e7f831f3c78d444cf3
parent99c2f236a1a09b6c550e91b71dabbbb0e634ea37 (diff)
PNaCl: Remove and disallow llvm.invariant.start/end intrinsics
These markers work in a similar way to llvm.lifetime.start/end, so we should remove them for similar reasons: it's not very well defined how one marker cancels out the effects of the other. Arguably, invariant.start/end are less useful than lifetime.start/end. They are ignored by the backend. They are generated in fewer places: invariant.start is generated by Clang (at -O1 or higher) when a const global is initialised with a non-POD initialiser. invariant.end is apparently not generated at all. Do the stripping in ReplacePtrsWithInts for consistency with the existing lifetime.start/end stripping. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3443 TEST=PNaCl toolchain trybots Review URL: https://codereview.chromium.org/15995004
-rw-r--r--lib/Analysis/NaCl/PNaClABIVerifyModule.cpp4
-rw-r--r--lib/Transforms/NaCl/ReplacePtrsWithInts.cpp9
-rw-r--r--test/Transforms/NaCl/replace-ptrs-with-ints.ll12
3 files changed, 21 insertions, 4 deletions
diff --git a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
index 9b2def5ac4..d977175b67 100644
--- a/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
+++ b/lib/Analysis/NaCl/PNaClABIVerifyModule.cpp
@@ -161,8 +161,6 @@ bool PNaClABIVerifyModule::isWhitelistedIntrinsic(const Function *F,
default: return false;
// (1) Always allowed.
case Intrinsic::bswap: return isWhitelistedBswap(F);
- case Intrinsic::invariant_end:
- case Intrinsic::invariant_start:
case Intrinsic::memcpy:
case Intrinsic::memmove:
case Intrinsic::memset:
@@ -215,6 +213,8 @@ bool PNaClABIVerifyModule::isWhitelistedIntrinsic(const Function *F,
// See https://code.google.com/p/nativeclient/issues/detail?id=3443
case Intrinsic::lifetime_end:
case Intrinsic::lifetime_start:
+ case Intrinsic::invariant_end:
+ case Intrinsic::invariant_start:
return false;
// (3) Dev intrinsics.
diff --git a/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp b/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp
index 00d374dc7b..9be459d986 100644
--- a/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp
+++ b/lib/Transforms/NaCl/ReplacePtrsWithInts.cpp
@@ -38,7 +38,8 @@
// * a bitcast of an InherentPtr.
//
// This pass currently strips out lifetime markers (that is, calls to
-// the llvm.lifetime.start/end intrinsics).
+// the llvm.lifetime.start/end intrinsics) and invariant markers
+// (calls to llvm.invariant.start/end).
//
//===----------------------------------------------------------------------===//
@@ -407,7 +408,9 @@ static void ConvertInstruction(DataLayout *DL, Type *IntPtrType,
} else if (CallInst *Call = dyn_cast<CallInst>(Inst)) {
if (IntrinsicInst *ICall = dyn_cast<IntrinsicInst>(Inst)) {
if (ICall->getIntrinsicID() == Intrinsic::lifetime_start ||
- ICall->getIntrinsicID() == Intrinsic::lifetime_end) {
+ ICall->getIntrinsicID() == Intrinsic::lifetime_end ||
+ ICall->getIntrinsicID() == Intrinsic::invariant_start ||
+ ICall->getIntrinsicID() == Intrinsic::invariant_end) {
// Remove alloca lifetime markers for now. This is because
// the GVN pass can introduce lifetime markers taking PHI
// nodes as arguments. If ReplacePtrsWithInts converts the
@@ -416,6 +419,8 @@ static void ConvertInstruction(DataLayout *DL, Type *IntPtrType,
// not safe in general. So, until LLVM better defines the
// semantics of lifetime markers, we drop them all. See:
// https://code.google.com/p/nativeclient/issues/detail?id=3443
+ // We do the same for invariant.start/end because they work in
+ // a similar way.
Inst->eraseFromParent();
} else {
FC->convertInPlace(Inst);
diff --git a/test/Transforms/NaCl/replace-ptrs-with-ints.ll b/test/Transforms/NaCl/replace-ptrs-with-ints.ll
index bab6101848..d7e85f6da6 100644
--- a/test/Transforms/NaCl/replace-ptrs-with-ints.ll
+++ b/test/Transforms/NaCl/replace-ptrs-with-ints.ll
@@ -447,6 +447,8 @@ define void @debug_value(i32 %val, i8* %ptr) {
declare void @llvm.lifetime.start(i64 %size, i8* %ptr)
+declare void @llvm.invariant.start(i64 %size, i8* %ptr)
+declare void @llvm.invariant.end(i64 %size, i8* %ptr)
; GVN can introduce the following horrible corner case of a lifetime
; marker referencing a PHI node. But we convert the phi to i32 type,
@@ -486,6 +488,16 @@ define void @alloca_lifetime_via_bitcast() {
; CHECK-NEXT: %buf = alloca [4 x i8]
; CHECK-NEXT: ret void
+define void @strip_invariant_markers() {
+ %buf = alloca i8
+ call void @llvm.invariant.start(i64 1, i8* %buf)
+ call void @llvm.invariant.end(i64 1, i8* %buf)
+ ret void
+}
+; CHECK: define void @strip_invariant_markers() {
+; CHECK-NEXT: %buf = alloca [1 x i8]
+; CHECK-NEXT: ret void
+
; "nocapture" and "noalias" only apply to pointers, so must be stripped.
define void @nocapture_attr(i8* nocapture noalias %ptr) {