<div dir="ltr">Does dead argument elimination work on recursive functions where the value of the recursive call is used to compute the next output?<div><br></div><div>I'm trying to have LLVM 7 eliminate the return value in the following code snippet, where the return value of rdac (and the add) could be eliminated but is not.</div><div><br></div><div>recurret.c</div><div>__attribute__((noinline))<br>static double rdac(double* x, unsigned n) {<br>    if (n == 1) {<br>        double val = x[0];<br>        x[0] = 0;<br>        return val;<br>    }<br>    return rdac(x, n/2) + rdac(x + n/2, n/2);<br>}<br><br>void dsum(double* x, unsigned n) {<br>    rdac(x, n);<br>}<br></div><div><br></div><div>recurret.ll:; ModuleID = 'recurret.c'</div>source_filename = "recurret.c"<br>target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"<br>target triple = "x86_64-unknown-linux-gnu"<br><br>; Function Attrs: nounwind uwtable<br>define dso_local void @dsum(double* %x, i32 %n) local_unnamed_addr #0 {<br>entry:<br>  %call = tail call fast fastcc double @rdac(double* %x, i32 %n)<br>  ret void<br>}<br><br>; Function Attrs: noinline nounwind uwtable<br>define internal fastcc double @rdac(double* %x, i32 %n) unnamed_addr #1 {<br>entry:<br>  %cmp = icmp eq i32 %n, 1<br>  br i1 %cmp, label %if.then, label %if.end<br><br>if.then:                                          ; preds = %entry<br>  %0 = load double, double* %x, align 8, !tbaa !2<br>  store double 0.000000e+00, double* %x, align 8, !tbaa !2<br>  ret double %0<br><br>if.end:                                           ; preds = %entry<br>  %div = lshr i32 %n, 1<br>  %call = tail call fast fastcc double @rdac(double* %x, i32 %div)<br>  %idx.ext = zext i32 %div to i64<br>  %add.ptr = getelementptr inbounds double, double* %x, i64 %idx.ext<br>  %call4 = tail call fast fastcc double @rdac(double* %add.ptr, i32 %div)<br>  %add = fadd fast double %call4, %call<br>  ret double %add<br>}<br><br>attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="true" "use-soft-float"="false" }<br>attributes #1 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="true" "no-jump-tables"="false" "no-nans-fp-math"="true" "no-signed-zeros-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="true" "use-soft-float"="false" }<br><br>!llvm.module.flags = !{!0}<br>!llvm.ident = !{!1}<br><br>!0 = !{i32 1, !"wchar_size", i32 4}<br>!1 = !{!"clang version 7.1.0 "}<br>!2 = !{!3, !3, i64 0}<br>!3 = !{!"double", !4, i64 0}<br>!4 = !{!"omnipotent char", !5, i64 0}<br>!5 = !{!"Simple C/C++ TBAA"}</div>