[llvm-bugs] [Bug 51962] New: Missing constant propagation with "const" functions, works with "pure" functions

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Sep 24 14:58:37 PDT 2021


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

            Bug ID: 51962
           Summary: Missing constant propagation with "const" functions,
                    works with "pure" functions
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

int c;

__attribute__((noinline, pure)) int *pure_test(int *b) {
  return *b && c ? &c : 0;
}
__attribute__((noinline, const)) int *const_test(int *b) { return b ? &c : 0; }
void escape(int *);


int test_pure() {
  int a = 42;
  escape(pure_test(&a));
  return a; // OK, LLVM: mov     eax, 42
}

int test_const() {
  int a = 42;
  escape(const_test(&a));
  return a; // LLVM: mov eax, dword ptr [rsp + 4], GCC can optimize it to mov  
  eax, 42
}


https://godbolt.org/z/PKEKeEhM4

-- 
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/20210924/19c4ff25/attachment.html>


More information about the llvm-bugs mailing list