Summary: | Unexpected stringop-overflow Warnings on POWER CPU | ||
---|---|---|---|
Product: | gcc | Reporter: | David Christensen <drc> |
Component: | tree-optimization | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | NEW --- | ||
Severity: | normal | CC: | guihaoc, rguenth, sergiodj, sjames, xtkoba |
Priority: | P3 | Keywords: | diagnostic |
Version: | 11.2.1 | ||
Target Milestone: | --- | ||
See Also: | https://bugs.dpdk.org/show_bug.cgi?id=743 | ||
Host: | Target: | powerpc64le | |
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2022-08-25 00:00:00 | |
Bug Depends on: | |||
Bug Blocks: | 88443 |
Description
David Christensen
2021-09-13 20:15:57 UTC
Looks like it is unrolling ... A workaround would be to __builtin_unreachable(), as usual: @@ -9,6 +9,7 @@ char* b; int p() { + if (a > LEN) __builtin_unreachable(); for (int i = 0; i < a; i++) { d.c[i] = b[i]; } I can confirm this bug. We're facing the problem when compiling NSS on Ubuntu Kinetic (development version) on ppc64el, because the build uses -O3. #define LEN 4 struct { char c[LEN] } d; extern int a; extern char* b; int p() { for (int i = 0; i < a; i++) { d.c[i] = b[i]; } return 0; } Above codes cause the same errors on x86. When setting the LEN to 8, it can be also reproduced on aarch64. It's a common problem. The iteration number of reset loop after vectorization should not only decided by variable "a" but also by the length of array. If the len is 5 and vector size is 4, the reset loop should be only executed once. Currently iteration number only depends on variable "a". Then it is complete unrolled 3 times if vector size is 4. That causes the warning. <bb 17> [local count: 398179264]: # i_30 = PHI <i_36(18), tmp.9_40(20)> _32 = (sizetype) i_30; _33 = b.0_1 + _32; _34 = *_33; d.c[i_30] = _34; i_36 = i_30 + 1; if (i_36 < a.1_13) // iterations depend on "a" only, the length of array is not take into consideration goto <bb 18>; [89.00%] else goto <bb 19>; [11.00%] (In reply to HaoChen Gui from comment #4) > #define LEN 4 > > struct { > char c[LEN] > } d; > > extern int a; > extern char* b; > > int p() { > for (int i = 0; i < a; i++) { > d.c[i] = b[i]; > } > return 0; > } > > Above codes cause the same errors on x86. When setting the LEN to 8, it can > be also reproduced on aarch64. It's a common problem. > > The iteration number of reset loop after vectorization should not only > decided by variable "a" but also by the length of array. If the len is 5 and > vector size is 4, the reset loop should be only executed once. Currently > iteration number only depends on variable "a". Then it is complete unrolled > 3 times if vector size is 4. That causes the warning. > > <bb 17> [local count: 398179264]: > # i_30 = PHI <i_36(18), tmp.9_40(20)> > _32 = (sizetype) i_30; > _33 = b.0_1 + _32; > _34 = *_33; > d.c[i_30] = _34; > i_36 = i_30 + 1; > if (i_36 < a.1_13) // iterations depend on "a" only, the length of array > is not take into consideration > goto <bb 18>; [89.00%] > else > goto <bb 19>; [11.00%] It does take this into account when unrolling. The issue is - at least for the vectorized epilogue - that when we set the iteration bound based on the VF we do not factor in the iteration bound of the scalar loop when we know the vector loop is iterating at least once. That's something we could improve. The real issue is of course that the diagnostic code is too trigger-happy and the unroll code is prone to leaving one not executable iteration (part). |