On 10/07/2020 09:20, Xi Ruoyao wrote: > On 2020-07-09 17:11 +0100, Jonny Grant wrote: >> Due to the const' on the 'int i = 1;' gcc removes all the other branches >> unfortunately. >> (I'd rather not use any special build macro to remove the 'const' just to see >> all the generated redundant assembler.) >> >> main: >> push rbp >> mov rbp, rsp >> mov DWORD PTR [rbp-4], 1 >> mov eax, 1 >> pop rbp >> ret > > Use -O0. > > It's nothing to do with that `const`. With something like -O2 it would be > optimized away even if there is no `const`. `i` is a local variable and the > compiler can determine that nobody can modify it. Hello Today's trunk on godbolt.org, shows same optimised out with -O0 #1 with x86-64 gcc (trunk) g++ (Compiler-Explorer-Build) 11.0.0 20200709 (experimental) main: push rbp mov rbp, rsp mov DWORD PTR [rbp-4], 1 mov eax, 1 pop rbp ret Maybe I am misunderstanding. Is there a way to keep all redundant assembler in gcc latest version trunk? Thank you Jonny