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: [email protected]
          Reporter: [email protected]
                CC: [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to