[LLVMbugs] [Bug 7969] New: tailcallelim not optimizing fib anymore

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Aug 22 23:17:13 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7969

           Summary: tailcallelim not optimizing fib anymore
           Product: libraries
           Version: 1.0
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: clattner at apple.com
                CC: llvmbugs at cs.uiuc.edu


Consider this code:

int fib(int n) {
  if (n == 1) return 0;
  if (n == 2) return 1;
  return fib(n-1) + fib(n-2);
}

We compile this into:


define i32 @fib(i32 %n) nounwind readnone ssp {
entry:
  switch i32 %n, label %bb3 [
    i32 1, label %bb4
    i32 2, label %bb2
  ]

bb2:                                              ; preds = %entry
  ret i32 1

bb3:                                              ; preds = %entry
  %0 = add nsw i32 %n, -1                         ; <i32> [#uses=1]
  %1 = tail call i32 @fib(i32 %0) nounwind ssp    ; <i32> [#uses=1]
  %2 = add nsw i32 %n, -2                         ; <i32> [#uses=1]
  %3 = tail call i32 @fib(i32 %2) nounwind ssp    ; <i32> [#uses=1]
  %4 = add nsw i32 %3, %1                         ; <i32> [#uses=1]
  ret i32 %4

bb4:                                              ; preds = %entry
  ret i32 0
}

The tailcallopt pass used to be able to transform the last call to fib into a
loop by eliminating the accumulator.  This isn't happening anymore.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list