Skip to content

Commit 29dc663

Browse files
committed
[LSR] Do not consider uses in lifetime intrinsics
We should ignore uses of pointers in lifetime intrinsics, as these are not actually materialized in the final code, so don't affect register pressure or anything else LSR needs to model. Handling these only results in peculiar rewrites where additional intermediate GEPs are introduced.
1 parent 76a87fd commit 29dc663

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,6 +3790,11 @@ LSRInstance::CollectLoopInvariantFixupsAndFormulae() {
37903790
continue;
37913791
}
37923792

3793+
// Do not consider uses inside lifetime intrinsics. These are not
3794+
// actually materialized.
3795+
if (UserInst->isLifetimeStartOrEnd())
3796+
continue;
3797+
37933798
std::pair<size_t, Immediate> P =
37943799
getUse(S, LSRUse::Basic, MemAccessTy());
37953800
size_t LUIdx = P.first;

llvm/test/Transforms/LoopStrengthReduce/X86/lifetime-use.ll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ define void @test(ptr %p, i64 %idx) {
66
; CHECK-SAME: ptr [[P:%.*]], i64 [[IDX:%.*]]) {
77
; CHECK-NEXT: [[ENTRY:.*]]:
88
; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [4 x [4 x i32]], align 16
9-
; CHECK-NEXT: [[SCEVGEP10:%.*]] = getelementptr nuw i8, ptr [[ALLOCA]], i64 48
10-
; CHECK-NEXT: [[SCEVGEP11:%.*]] = getelementptr i8, ptr [[SCEVGEP10]], i64 -48
119
; CHECK-NEXT: call void @llvm.lifetime.start.p0(i64 64, ptr [[ALLOCA]])
1210
; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[IDX]], 6
1311
; CHECK-NEXT: [[TMP1:%.*]] = add nuw nsw i64 [[TMP0]], 48
@@ -33,7 +31,7 @@ define void @test(ptr %p, i64 %idx) {
3331
; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[LSR_IV_NEXT]], 0
3432
; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT:.*]], label %[[LOOP]]
3533
; CHECK: [[EXIT]]:
36-
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr [[SCEVGEP11]])
34+
; CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 64, ptr [[ALLOCA]])
3735
; CHECK-NEXT: ret void
3836
;
3937
entry:

0 commit comments

Comments
 (0)