[llvm-bugs] [Bug 44805] New: `-fmerge-functions` incorrectly overrides __attribute__((always_inline)) and __attribute__((flatten))

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Feb 5 13:26:22 PST 2020


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

            Bug ID: 44805
           Summary: `-fmerge-functions` incorrectly overrides
                    __attribute__((always_inline)) and
                    __attribute__((flatten))
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mike.k at digitalcarbide.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

When `-Xclang -fmerge-functions` is supplied to Clang (trunk [10] until 3.6,
before 3.6 does not support `merge-functions`), attributes `always_inline` and
`flatten` are ignored, while GCC with equivalent `-fipa-icf` (supplied via
`-O3` by default) does not do such.

Observe (https://godbolt.org/z/5vJKDF):

```
__attribute__((always_inline))
static int func (int a, int b) {
    return a / b;
}

int func_a(int a, int b) {
    return func(a, b);
}

int func_b(int a, int b) {
    return func(a, b);
}

__attribute__((flatten))
int func_c(int a, int b) {
    return func(a, b);
}
```

On GCC with the `-O3` flag, this produces:

```
func_a(int, int):
  mov eax, edi
  cdq
  idiv esi
  ret
func_b(int, int):
  mov eax, edi
  cdq
  idiv esi
  ret
func_c(int, int):
  mov eax, edi
  cdq
  idiv esi
  ret
```

On Clang with only the `-O3` flag, this produces the identical:

```
func_a(int, int): # @func_a(int, int)
  mov eax, edi
  cdq
  idiv esi
  ret
func_b(int, int): # @func_b(int, int)
  mov eax, edi
  cdq
  idiv esi
  ret
func_c(int, int): # @func_c(int, int)
  mov eax, edi
  cdq
  idiv esi
  ret
```

However, when `-Xclang -fmerge-functions` is supplied to match GCC's
`-fipa-icf` (#44804), both `always_inline` _and_ `flatten` are ignored, despite
GCC not ignoring them:

```
func_a(int, int): # @func_a(int, int)
  mov eax, edi
  cdq
  idiv esi
  ret

func_b(int, int): # @func_b(int, int)
  jmp func_a(int, int) # TAILCALL

func_c(int, int): # @func_c(int, int)
  jmp func_a(int, int) # TAILCALL
```

-- 
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/20200205/a876cdbd/attachment.html>


More information about the llvm-bugs mailing list