llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

llvm-reduce should remove lifetime.start/end when promoting alloca'd ptr to arg

Open ManuelJBrito opened this issue 2 years ago • 3 comments

Lifetime.start/end in general should only be used for alloca'd pointers. When running the "operands-to-args" pass the lifetimes should be dropped.

define void @src() {
entry:
  %p = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %p)
  store i32 10, ptr %p, align 4
  %a = load i32, ptr %p, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %p)
  ret void
}

Running llvm-reduce --delta-passes=operands-to-args --test=test.sh src.ll

; ModuleID = 'src.ll'
source_filename = "src.ll"

define void @src(ptr %p) {
entry:
  %p1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %p)
  store i32 10, ptr %p, align 4
  %a = load i32, ptr %p, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %p)
  ret void
}

cc @nunoplopes @regehr

ManuelJBrito avatar May 29 '24 17:05 ManuelJBrito

I don't think I agree with this. It is not structurally required to remove the intrinsics. Reductions should make minimal structurally correct changes, the semantics are not so relevant (unless we introduce a preserve-semantics mode).

The LangRef does not state that it's invalid IR and the verifier does not reject it. Unless the IR verifier rules change, I think this should be left alone. If the use of the pointer does not matter, the operand use reductions on the intrinsic call should strip the argument use later

arsenm avatar Apr 03 '25 09:04 arsenm

The smaller the file, usually the better. Often the lifetime markers are irrelevant to bug repros. IMO, having a pass in llvm-reduce that removes unused intrinsics is very useful.

nunoplopes avatar Apr 05 '25 10:04 nunoplopes

The smaller the file, usually the better. Often the lifetime markers are irrelevant to bug repros. IMO, having a pass in llvm-reduce that removes unused intrinsics is very useful.

Sure, they should eventually be removed as a consequence of the complete delta pass pipeline. I'm saying that operands-to-args need not be responsible for this, and these should be deleted later anyway

arsenm avatar Apr 07 '25 01:04 arsenm