Issue 53118
Summary Suboptimal codegen for tail call followed by unreachable
Labels backend:X86
Assignees
Reporter hyeongyukim
    
Suboptimal code for tail call followed by unreachable

```
declare void @callee(i64)

define void @endswith_unreachable(i64 %0) {    
    tail call void @callee(i64 %0)
    unreachable
}

define void @endswith_return(i64 %0) {    
    tail call void @callee(i64 %0)
    ret void
}
```
This IR is compiled as below. 
https://godbolt.org/z/G9jrEzYoW
```
endswith_unreachable:                   # @endswith_unreachable
        push    rax
        call    callee@PLT
endswith_return:                        # @endswith_return
        jmp     callee@PLT                      # TAILCALL
```


The function ends with `tail call` followed by `ret void` creates a tail call with `jmp.`
But when the function ends with `unreachable,` a `call` is created rather than a `tail call.`
I suggest changing from `call` to `tail call` even if the function ends with `unreachable.`

I found this issue while resolving the objtool's (linux kernel's tool) warning for [D105169](https://reviews.llvm.org/D105169).
If you want to check the original problem, you can find the reduced version of the kernel code at https://godbolt.org/z/sYxTsnh5K and generated IR code containing `unreachable` at https://alive2.llvm.org/ce/z/szhgAB.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to