[PATCH] D12923: Add support for function attribute "notail"

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 22:59:55 PDT 2015


sanjoy added a comment.

In http://reviews.llvm.org/D12923#247639, @ahatanak wrote:

> No, tail call optimization doesn't have to be disabled on indirect calls.


An IR example of the issue I'm trying to point out is this:

  define i32 @caller(i32 %a) {
  entry:
    %p = alloca i32(i32)*
    store i32(i32)* @callee, i32(i32)** %p
  
    %ptr = load i32(i32)*, i32(i32)** %p
    %call = call i32 %ptr(i32 %a)
    ret i32 %call
  }
  
  declare i32 @callee(i32) #0
  
  attributes #0 = { notail }

If you pass the above through `opt -tailcallelim -mem2reg` (opt built with this patch) you'll get

  define i32 @caller(i32 %a) {
  entry:
    %call = tail call i32 @callee(i32 %a)
    ret i32 %call
  }
  
  ; Function Attrs: notail
  declare i32 @callee(i32) #0
  
  attributes #0 = { notail }

which is what you're trying to avoid with `notail`, if I understand this change correctly.


http://reviews.llvm.org/D12923





More information about the llvm-commits mailing list