https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111006
Bug ID: 111006 Summary: [SVE] Extra neg for storing to short from int comparison Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: pinskia at gcc dot gnu.org Target Milestone: --- Take: ``` void __attribute__ ((noipa)) f0 (unsigned short *__restrict r, int *__restrict a, int *__restrict pred) { for (int i = 0; i < 1024; ++i) { int p = pred[i]?-1:0; r[i] = p ; } } ``` Compile with `-march=armv8.5+sve2 -O3`. Currently we get: ``` .L2: ld1w z31.s, p7/z, [x2, x1, lsl 2] cmpne p15.s, p6/z, z31.s, #0 mov z31.s, p15/z, #1 neg z31.h, p6/m, z31.h st1h z31.s, p7, [x0, x1, lsl 1] incw x1 whilelo p7.s, w1, w3 b.any .L2 ``` But we should just get: ``` .L2: ld1w z31.s, p7/z, [x2, x1, lsl 2] cmpne p15.s, p6/z, z31.s, #0 mov z31.s, p15/z, #-1 st1h z31.s, p7, [x0, x1, lsl 1] incw x1 whilelo p7.s, w1, w3 b.any .L2 ```