<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - GVN removes necessary load iff store to the same address uses data-cast"
   href="https://bugs.llvm.org/show_bug.cgi?id=43780">43780</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVN removes necessary load iff store to the same address uses data-cast
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>kaz-marukawa@xr.jp.nec.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Following code is compiled wrongly with "-O3 -fno-unroll-loops" option.

```
#include <stdint.h>

#define SIZE 9
void test(float const* kern, float* output)
{
    float buf[SIZE];
    float* ptr = buf;
    extern void func(float*, float);

    for(int i = 0; i < 1; ++i){                 // loop_i
        for (int j = 0; j < SIZE; ++j){         // loop_j
            ((int32_t*)ptr)[0] = ((int32_t*)kern)[j];
            ptr += 1;
            // we have calculations here originally
        }
        // we have calculations here originally
    }
    func(output, buf[0]);
}
```

The point is 2nd argument of func function call.  LLVM generates undef
instead of buf[0] through optimizations.

To reproduce the problem, please save this test program as tp.c and does:
```
$ clang -O3 -fno-unroll-loops -S -emit-llvm tp.c
$ grep undef tp.ll
  tail call void @func(float* %output, float undef) #3
```

This test program is compiled fine for following cases, so this is not
a real problem, but it is better to be fixed...

- -O1 -fno-unroll-loops
- -O3 (without -fno-unroll-loops)
- Modify source code to copy data as float without cast.
- Modify source code to use single loop instead of doubly nested loops.

The debug message shows GVN is removing a load of buf[0] like below.  I

```
$ clang -O3 -fno-unroll-loops -S -emit-llvm tp.c -mllvm -debug
...
; we have load and call here
IC: Visiting:   %1 = load float, float* %arraydecay, align 16, !tbaa !2
IC: Visiting:   tail call void @func(float* %output, float %1) #3
...
; GVN removes the load by unknown reason
GVN REMOVING NONLOCAL LOAD:   %1 = load float, float* %arraydecay, align 16,
!tbaa !2
GVN removed:   %1 = load float, float* %arraydecay, align 16, !tbaa !2
...
; Now, %1 become undef.
  tail call void @func(float* %output, float undef) #3
```

I tried to investigate this issue by myself, but didn't find the reason of
this.
Hope someone help me or solve this issue.  Thanks.

In addition, I'm using fresh llvm 9.0.0.

```
$ clang --version
clang version 9.0.0 (git@...:.../llvm-project.git
0399d5a9682b3cef71c653373e38890c63c4c365)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: ...
```</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>