[llvm-bugs] [Bug 38107] New: Aggressive optimization when computing GEP result.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 9 09:09:35 PDT 2018


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

            Bug ID: 38107
           Summary: Aggressive optimization when computing GEP result.
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: zahira.ammarguellat at intel.com
                CC: llvm-bugs at lists.llvm.org

Let's look at this test case:

#include <stdio.h>
char * __strrchr_c_a (const char *__s, int __c) {
  register unsigned long int __d0, __d1;
  register char *__res;

  __c = __c << 8;

  __asm__
    ("cmpb  %h2,%b2\n\t"
     "cmove %1,%0\n\t"
     : "=d" (__res), "=&S" (__d0), "=&a" (__d1)
     : "0" (1), "1" (__s), "2" (__c));


  return __res - 1;
}

int main() {
  char * res =   __strrchr_c_a("Hello, world!", 'S');
  (res) ? printf("failed\n") : printf("passed\n");
}

bash-4.2$ gcc -O0 t1.c
bash-4.2$ ./a.out
passed
bash-4.2$ gcc -O2 t1.c
bash-4.2$ ./a.out
passed
bash-4.2$

Clang over optimizes.

bash-4.2$ clang -O0 t1.c
bash-4.2$ ./a.out
passed
bash-4.2$ clang -O2 t1.c
bash-4.2$ ./a.out
failed
bash-4.2$

ValueTracking is too aggressive optimizing away the argument to the tail call.

-- 
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/20180709/22f09004/attachment.html>


More information about the llvm-bugs mailing list