[llvm-bugs] [Bug 33657] New: ThinLTO doesn't apply all interprocedural GlobalOptimzation optimizations

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jun 30 08:33:56 PDT 2017


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

            Bug ID: 33657
           Summary: ThinLTO doesn't apply all interprocedural
                    GlobalOptimzation optimizations
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Interprocedural Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: charles.saternos at gmail.com
                CC: llvm-bugs at lists.llvm.org

LTO will apply the globalopt pass, but ThinLTO can't apply all these
optimizations right now.

$ cat a.cc
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

char x = 0; // shrunk to bool
char b = 1; // localized
bool c = false; // deleted
int p[] = {1, 2, 3}; // scalarized

void bb() {
    if(rand() % 8) {
        x = 1;
    }
}

int jj() {
    b = (rand() % 2);
    return b == 0;
}
$ cat b.cc
#include <stdio.h>
#include <stdlib.h>
extern char x;
extern bool c;
extern int p[];

extern int jj();
extern void bb();


void cc() {
  if(rand() % 8) {
    x = 1;
  }
}

int main(void) {
  printf("%d\n", p[1]++);
  bb();
  cc();
  if(x) {
    puts("Hi");
  }
  for(int i = 0; i < 200; i++) {
    printf("%d\n", jj());
  }
  if(c)
    puts("yo");
}

$ ../build/bin/clang++ a.cc b.cc -O3 --for-linker=-mllvm --for-linker=-stats
-flto=thin -fuse-ld=lld -o thin &>&1 | grep globalopt
         1 globalopt             - Number of globals deleted
$ ../build/bin/clang++ a.cc b.cc -O3 --for-linker=-mllvm --for-linker=-stats
-flto -fuse-ld=lld -o lto &>&1 | grep globalopt
   1 globalopt             - Number of globals deleted
   2 globalopt             - Number of functions converted to fastcc
   1 globalopt             - Number of globals localized
   1 globalopt             - Number of aggregate globals broken into scalars
   1 globalopt             - Number of global vars shrunk to booleans
   6 globalopt             - Number of globals marked unnamed_addr

-- 
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/20170630/4a434ef0/attachment.html>


More information about the llvm-bugs mailing list