| Issue |
53082
|
| Summary |
struct path TBAA metadata not used in !tbaa.struct resulting in bad optimization of trivial copy / move operations
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zygoloid
|
Testcase:
```c++
struct Wrap {
Wrap(char x) : c(x) {}
#ifdef FAST
Wrap &operator=(const Wrap &o) { c = o.c; return *this; }
#endif
operator char() const { return c; }
char c;
};
void f(Wrap **p) {
(*p)[0] = 'a';
(*p)[1] = 'b';
(*p)[2] = 'c';
(*p)[3] = 'd';
}
```
Compiled without `-DFAST`, we generate four separate stores, reloading before `*p` each. With `-DFAST`, we generate a single four-byte store.
The problem is that, with a defaulted copy assignment operator, we generate an `llvm.memcpy` whose `!tbaa.struct` metadata directly references the TBAA info for the field types, rather than referencing struct-path TBAA metadata for the fields of `Wrap`. The `-DFAST` case generates this for the store to the `c` field during the assignment:
```llvm
store i8 %8, i8* %9, align 1, !tbaa !8
```
```llvm
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C++ TBAA"}
!8 = !{!9, !5, i64 0}
!9 = !{!"_ZTS4Wrap", !5, i64 0}
```
... whereas the `-UFAST` case generates this:
```llvm
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %11, i8* align 1 %12, i64 1, i1 false), !tbaa.struct !7
```
```llvm
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C++ TBAA"}
!7 = !{i64 0, i64 1, !8}
!8 = !{!5, !5, i64 0}
```
Presumably we could produce something like this instead:
```llvm
!5 = !{!"omnipotent char", !6, i64 0}
!6 = !{!"Simple C++ TBAA"}
!7 = !{i64 0, i64 1, !8}
!8 = !{!9, !5, i64 0}
!9 = !{!"_ZTS4Wrap", !5, i64 0}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs