[llvm-bugs] [Bug 44304] New: tailcallelim change the semantic of my program

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Dec 15 00:22:38 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=44304

            Bug ID: 44304
           Summary: tailcallelim change the semantic of my program
           Product: new-bugs
           Version: 8.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: hzx19990925 at mail.ustc.edu.cn
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

Created attachment 22937
  --> https://bugs.llvm.org/attachment.cgi?id=22937&action=edit
code before optimization

I got the LLVM IR Code from
/llvm/test/Transforms/TailCallEli/accum_recursion.ll

I add a main function to test it.
The code is below.Also,I will add an attachment of my LLVM IR code and the code
after optimization.

I use tailcallelim pass to optimize it,use lli to test the output:
lli accum_recursion.ll
echo $?
2
opt -tailcallelim accum_recursion.ll -o accum_recursion_opt.ll
lli lli accum_recursion_opt.ll
echo $?
6

The output is different.So I think this optimization change the semantic of the
program.

This is the code before optimization:

define i64 @test3_fib(i64 %n) nounwind readnone {
; CHECK: @test3_fib
entry:
; CHECK: tailrecurse:
; CHECK: %accumulator.tr = phi i64 [ %n, %entry ], [ %3, %bb1 ]
; CHECK: %n.tr = phi i64 [ %n, %entry ], [ %2, %bb1 ]
  switch i64 %n, label %bb1 [
; CHECK: switch i64 %n.tr, label %bb1 [
    i64 0, label %bb2
    i64 1, label %bb2
  ]

bb1:
; CHECK: bb1:
  %0 = add i64 %n, -1
; CHECK: %0 = add i64 %n.tr, -1
  %1 = tail call i64 @test3_fib(i64 %0) nounwind
; CHECK: %1 = tail call i64 @test3_fib(i64 %0)
  %2 = add i64 %n, -2
; CHECK: %2 = add i64 %n.tr, -2
  %3 = tail call i64 @test3_fib(i64 %2) nounwind
; CHECK-NOT: tail call i64 @test3_fib
  %4 = add nsw i64 %3, %1
; CHECK: add nsw i64 %accumulator.tr, %1
  ret i64 %4
; CHECK: br label %tailrecurse

bb2:
; CHECK: bb2:
  ret i64 %n
; CHECK: ret i64 %accumulator.tr
}

define i64 @main()
{
  %1 = call i64 @test3_fib(i64 3)
  ret i64 %1
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191215/64da6ba5/attachment.html>


More information about the llvm-bugs mailing list