https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83518
Bug ID: 83518 Summary: Missing optimization: useless instructions should be dropped Product: gcc Version: tree-ssa Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zamazan4ik at tut dot by Target Milestone: --- gcc (trunk) with '-O3 -std=c++17' for this code: unsigned test() { int arr[] = {5,4,3,2,1}; int sum = 0; for(int i = 0;i < 5;++i) { for(int j = 0; j < 5; ++j) { int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } for(int i = 0; i < 5; ++i) { sum += arr[i]; } return sum; } generates it: test(): movdqa xmm0, XMMWORD PTR .LC0[rip] movaps XMMWORD PTR [rsp-40], xmm0 mov rax, QWORD PTR [rsp-32] mov DWORD PTR [rsp-32], 1 mov QWORD PTR [rsp-40], rax mov DWORD PTR [rsp-28], 5 movdqa xmm0, XMMWORD PTR [rsp-40] movdqa xmm1, xmm0 psrldq xmm1, 8 paddd xmm0, xmm1 movdqa xmm1, xmm0 psrldq xmm1, 4 paddd xmm0, xmm1 movd eax, xmm0 add eax, 4 ret .LC0: .long 5 .long 4 .long 3 .long 2 clang (trunk) with '-O3 -std=c++17': test(): # @test() mov eax, 15 ret