[llvm-bugs] [Bug 43780] New: GVN removes necessary load iff store to the same address uses data-cast
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Oct 23 18:57:50 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43780
Bug ID: 43780
Summary: GVN removes necessary load iff store to the same
address uses data-cast
Product: new-bugs
Version: 9.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: kaz-marukawa at xr.jp.nec.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
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 at ...:.../llvm-project.git
0399d5a9682b3cef71c653373e38890c63c4c365)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: ...
```
--
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/20191024/e1185aaf/attachment.html>
More information about the llvm-bugs
mailing list