[llvm-bugs] [Bug 50735] New: Missing optimization for member function with const attribute

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 16 05:50:13 PDT 2021


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

            Bug ID: 50735
           Summary: Missing optimization for member function with const
                    attribute
           Product: libraries
           Version: 12.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: C
          Assignee: unassignedbugs at nondot.org
          Reporter: zhongyunde at tom.com
                CC: llvm-bugs at lists.llvm.org

refer to https://developer.arm.com/documentation/dui0491/c/Cacgigch, if we
defined the following function Function_Attributes_const_0 with __attribute__
((const)),  code Function_Attributes_const_0 might be called once only, with
the result being doubled to obtain the correct return value.

int Function_Attributes_const_0(int b) __attribute__ ((const));

int test (int b)
{
    int aLocal=0;
    aLocal += Function_Attributes_const_0(b);
    aLocal += Function_Attributes_const_0(b);
    return aLocal;
}

while we change the function into member function as following, then code
Function_Attributes_const_0 might be called twice, so it seems missing
optimization for member function.

class foo {
public:
  int Function_Attributes_const_0(int b) const;
};

int test (int b)
{
    int aLocal=1;
    class foo fuc;
    aLocal += fuc.Function_Attributes_const_0(b);
    aLocal += fuc.Function_Attributes_const_0(b);
    return aLocal;
}

-- 
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/20210616/dec735f8/attachment.html>


More information about the llvm-bugs mailing list