From: Eli Friedman Date: Mon, 28 Nov 2016 21:50:34 +0000 (+0000) Subject: [SROA] Drop lifetime.start/end intrinsics when they block promotion. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=56089e7485640a284d5526e45e4caa14a503d036;p=llvm [SROA] Drop lifetime.start/end intrinsics when they block promotion. Preserving lifetime markers isn't as important as allowing promotion, so just drop the lifetime markers if necessary. This also fixes an assertion failure where other parts of SROA assumed that lifetime markers never block promotion. Fixes https://llvm.org/bugs/show_bug.cgi?id=29139. Differential Revision: https://reviews.llvm.org/D24854 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288074 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp index 19078669110..54ce1d8fb60 100644 --- a/lib/Transforms/Scalar/SROA.cpp +++ b/lib/Transforms/Scalar/SROA.cpp @@ -2876,6 +2876,17 @@ private: // Record this instruction for deletion. Pass.DeadInsts.insert(&II); + // Lifetime intrinsics are only promotable if they cover the whole alloca. + // Therefore, we drop lifetime intrinsics which don't cover the whole + // alloca. + // (In theory, intrinsics which partially cover an alloca could be + // promoted, but PromoteMemToReg doesn't handle that case.) + // FIXME: Check whether the alloca is promotable before dropping the + // lifetime intrinsics? + if (NewBeginOffset != NewAllocaBeginOffset || + NewEndOffset != NewAllocaEndOffset) + return true; + ConstantInt *Size = ConstantInt::get(cast(II.getArgOperand(0)->getType()), NewEndOffset - NewBeginOffset); @@ -2889,12 +2900,7 @@ private: (void)New; DEBUG(dbgs() << " to: " << *New << "\n"); - // 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; + return true; } bool visitPHINode(PHINode &PN) { diff --git a/test/Transforms/SROA/basictest.ll b/test/Transforms/SROA/basictest.ll index 75fe279849d..70096f37be0 100644 --- a/test/Transforms/SROA/basictest.ll +++ b/test/Transforms/SROA/basictest.ll @@ -1672,9 +1672,8 @@ declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, 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, +; CHECK: entry-block: +; CHECK-NEXT: ret void entry-block: %0 = alloca [2 x i64], align 8 %1 = bitcast [2 x i64]* %0 to i8* @@ -1684,3 +1683,15 @@ entry-block: call void @llvm.lifetime.end(i64 8, i8* %3) ret void } + +define void @PR29139() { +; CHECK-LABEL: @PR29139( +; CHECK: bb1: +; CHECK-NEXT: ret void +bb1: + %e.7.sroa.6.i = alloca i32, align 1 + %e.7.sroa.6.0.load81.i = load i32, i32* %e.7.sroa.6.i, align 1 + %0 = bitcast i32* %e.7.sroa.6.i to i8* + call void @llvm.lifetime.end(i64 2, i8* %0) + ret void +}