[llvm-bugs] [Bug 51411] New: Semantic error - - different output are observed on changing flags

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 9 03:09:22 PDT 2021


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

            Bug ID: 51411
           Summary: Semantic error - - different output are observed on
                    changing flags
           Product: new-bugs
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: Rohit.Aggarwal at amd.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

The issue is present in main stream LLVM. I tired the example code on clang-12
release.

## Sample Code (inline_ex.c)

int main() {
  double dbl;

  unsigned i[1000], j[1000], k[1000], l[1000];
  int index;

  for (index = 0; index < 1000; index++) {
    i[index] = j[index] = k[index] = l[index] = 10000;
  }
  unsigned long r1=0, r2=0, r3=0, r4=0;
  for (int a = 0; a < 1000; a++) {
    r1 += i[a];
    r2 += j[a];
    r3 += k[a];
    r4 += l[a];
  }

  double R1 = DBL_MAX + (double)r1;
  double R2 = DBL_MAX + (double)r2;
  double R3 = DBL_MAX + (double)r3;
  double R4 = DBL_MAX + (double)r4;
  // printf("%lf\n%lf\n%lf\n%lf\n", R1, R2, R3, R4);
  dbl = R1 + R2 + R3 + R4;

  printf("Result: %lf\n", dbl);

  return 0;
}


## GCC

(gcc   inline_ex.c   -o a.out && ./a.out )
Result: inf

(gcc   inline_ex.c  -O3 -ffast-math -o a.out && ./a.out )
Result: inf

## CLANG 12
clang-12 -O3  -flto -ffast-math -fno-unroll-loops  inline_ex.c   -o a.out &&
./a.out )                 
Result: 0.000000

(clang-12 -O3  -ffast-math   inline_ex.c   -o a.out && ./a.out )
Result: 0.000000

(clang-12 -O3  -flto  -fno-unroll-loops  inline_ex.c   -o a.out && ./a.out )
Result: inf

(clang-12 -O3   inline_ex.c   -o a.out && ./a.out )
Result: inf

(clang-12   inline_ex.c   -o a.out && ./a.out )
Result: inf



Observation

The problem occurs when we use fast-math flag with O3. This flag enables
certain transformation in instCombine pass which leads to creation of poison
value. The poison value is not handle properly and is propagated to it's uses.
In the end, a poison value remains as the operand in printf. The value of
poison depends upon type and for double the value is 0.0000.

-- 
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/20210809/fc3461c1/attachment.html>


More information about the llvm-bugs mailing list