Below is the motivating test case:
define dso_local i64 @test_lrint_fast(double %d) local_unnamed_addr { entry: %0 = call fast i64 @llvm.lrint.i64.f64(double %d) ret i64 %0 } declare i64 @llvm.lrint.i64.f64(double)
Compile it with llc, we see:
While deleting: double % Use still stuck around after Def is destroyed: <badref> = call addrspace(0) i64 @llvm.lrint.i64.f64(double %0) Assertion failed: (materialized_use_empty() && "Uses remain when a value is destroyed!"), function ~Value, file llvm-project/llvm/lib/IR/Value.cpp, line 96.
The reason is we still have an undeleted value referencing the argument.