[llvm-bugs] [Bug 50110] New: Use noalias information to optimize pointer comparisons

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Apr 24 05:31:24 PDT 2021


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

            Bug ID: 50110
           Summary: Use noalias information to optimize pointer
                    comparisons
           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

extern void *alloc(int) __attribute__((malloc));
char global_arr[128];
char *__restrict__ global_noalias_ptr;

int test1(void) {
  if (global_arr == global_noalias_ptr) return 1;
  return 0;
}

int test2(char *__restrict__ noalias_ptr_arg1) {

  if (noalias_ptr_arg1 == global_arr) return 1;
  return 0;
}

int test3(char *__restrict__ noalias_ptr_arg1) {

   if (noalias_ptr_arg1 == global_noalias_ptr) return 1;
  return 0;
}

int test4(char *__restrict__ noalias_ptr_arg1, char *__restrict__
noalias_ptr_arg2) {

   if (noalias_ptr_arg1 == noalias_ptr_arg2) return 1;
  return 0;
}

int test5( char *unknown_ptr) {
  char *__restrict__ noalias_local_ptr = unknown_ptr;
  if (noalias_local_ptr == global_arr) return 1;
  return 0;
}

int test6( char *__restrict__ noalias_ptr_arg1,char *unknown_ptr) {
  char *__restrict__ noalias_local_ptr = unknown_ptr;
  if (noalias_local_ptr == noalias_ptr_arg1) return 1;
  return 0;
}

int test7( char *unknown_ptr) {
  char *__restrict__ noalias_local_ptr = unknown_ptr;
 if (noalias_local_ptr == global_noalias_ptr) return 1;
  return 0;
}

int test8(void) {
  char *allocated_noalias_ptr = (char *)alloc(64);
  if (allocated_noalias_ptr == global_arr) return 1;
  return 0;
}

int test9(char *unknown_ptr) {
  char *__restrict__ noalias_local_ptr = unknown_ptr;
  char *allocated_noalias_ptr = (char *)alloc(64);
  if (allocated_noalias_ptr == noalias_local_ptr) return 1;
  return 0;
}

int test10(char *__restrict__ noalias_ptr_arg1) {
  char *allocated_noalias_ptr = (char *)alloc(64);
  if (allocated_noalias_ptr == noalias_ptr_arg1) return 1;
  return 0;
}

int test11(void) {
  char *allocated_noalias_ptr = (char *)alloc(64);
  if (allocated_noalias_ptr == global_noalias_ptr) return 1;
  return 0;
}

https://godbolt.org/z/dz3zv4fTh

LLVM does not optimize these cases, GCC can optimize atleast test1 and test8.

-- 
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/20210424/9608ac14/attachment.html>


More information about the llvm-bugs mailing list