[llvm-bugs] [Bug 37231] New: Dead code partially eliminated

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 25 03:23:53 PDT 2018


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

            Bug ID: 37231
           Summary: Dead code partially eliminated
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lukasz.kuszner at intel.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Created attachment 20224
  --> https://bugs.llvm.org/attachment.cgi?id=20224&action=edit
bad and good dump as described

Given two files:

foo.c
---
void foo(double *x, double *y, double *result, int arr_sizes, int iter) {
  while (iter-->0) {
    double sum=0;
    for (int j=0; j<arr_sizes; j++) {
      for (int i=0; i<arr_sizes; i++)
        sum += x[i]*y[i];
      result[j] = sum;
    }
  }
}
---

reproducer.c
---
#include<stdlib.h>
#include<stdio.h>

void foo(double *x, double *y, double *result, int arr_sizes, int iter);

int main() {
  int N = 1024;
  double *Y = (double*) malloc(sizeof(double)*N);
  double *X = (double*) malloc(sizeof(double)*N);
  double *R = (double*) malloc(sizeof(double)*N);

  int collatz=11;

  int cycles=1;
  while(collatz>1) {
    if (collatz%2==0) {
      collatz/=2;
    } else {
        collatz*=3;
        collatz++;
    }
    foo(X,Y,R,N,cycles);
    cycles *= 2;
  }
  printf("%d\n", cycles);
  free(X);
  free(Y);
  free(R);
  return 0;
}
---

Compiled with clang (tested with trunk build from 2018 March 16):
clang -O3  -fno-unroll-loops -g -flto reproduce.c foo.c


Results in the assembly with the function foo partially eliminated from the
code (bad case). That is the 
---
sum += x[i]*y[i];
---
instruction is replaced by dummy increment.

The -fno-unroll-loops is not necessary but makes the assembly analysis easier.

Merging two files into one file makes the thing easier (good case) for the
compiler and the whole foo is eliminated as expected.

Attached dump files: bad_dump.txt for bad case and good_dump.txt for good case
were produced by:

---
objdump -S -d -M intel <executable>  >  <dump_file.txt> 
---

-- 
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/20180425/f47ee061/attachment.html>


More information about the llvm-bugs mailing list