https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92291
Bug ID: 92291 Summary: Non-optimal code generated for H8 Product: gcc Version: 9.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: mti-1 at tillenius dot com Target Milestone: --- I am using a cross compiler for Renesas H8S. In a few places it generates really bad code. Given the following program: struct s { char a, b; char c[11]; } x[2]; void test(int n) { struct s *sp = &x[n]; sp->a = 1; sp->b = 1; } I would expect that the pointer "sp" is calculated once and reused to access the fields "a" and "b". But instead the pointer is recalculated for each access. This generates a lot of extra code, including calls to __mulhi3. I have tested with gcc 8.2 and 9.2 and with different optimization levels (-O1, -O2, -Os) all with the same result. With -O0 "sp" is only calculated once and kept as a variable on the stack but the rest of the code is not as good as it could be. --- Using built-in specs. COLLECT_GCC=h8300-none-elf-gcc Target: h8300-none-elf Configured with: /home/mti/abs/arm-none-eabi-gcc/h8/src/gcc-9.2.0/configure --target=h8300-none-elf --prefix=/usr --with-native-system-header-dir=/include --libexecdir=/usr/lib --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-libstdcxx --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-system-zlib --without-headers --with-python-dir=share/gcc-arm-none-eabi --with-gmp --with-mpfr --with-mpc --with-isl --with-libelf --enable-gnu-indirect-function --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='Arch Repository' --with-bugurl=https://bugs.archlinux.org/ --with-multilib-list=rmprofile Thread model: single gcc version 9.2.0 (Arch Repository) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O1' '-S' '-Wall' /usr/lib/gcc/h8300-none-elf/9.2.0/cc1 -E -quiet -v test.c -Wall -O1 -fpch-preprocess -o test.i ignoring nonexistent directory "/usr/lib/gcc/h8300-none-elf/9.2.0/../../../../h8300-none-elf/sys-include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/h8300-none-elf/9.2.0/include /usr/lib/gcc/h8300-none-elf/9.2.0/include-fixed /usr/lib/gcc/h8300-none-elf/9.2.0/../../../../h8300-none-elf/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O1' '-S' '-Wall' /usr/lib/gcc/h8300-none-elf/9.2.0/cc1 -fpreprocessed test.i -quiet -dumpbase test.c -auxbase test -O1 -Wall -version -o test.s GNU C17 (Arch Repository) version 9.2.0 (h8300-none-elf) compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.19-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C17 (Arch Repository) version 9.2.0 (h8300-none-elf) compiled by GNU C version 9.2.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.19-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 67bb4ca8e2b97056926c3ecedb8a3eae COMPILER_PATH=/usr/lib/gcc/h8300-none-elf/9.2.0/:/usr/lib/gcc/h8300-none-elf/9.2.0/:/usr/lib/gcc/h8300-none-elf/:/usr/lib/gcc/h8300-none-elf/9.2.0/:/usr/lib/gcc/h8300-none-elf/:/usr/lib/gcc/h8300-none-elf/9.2.0/../../../../h8300-none-elf/bin/ LIBRARY_PATH=/usr/lib/gcc/h8300-none-elf/9.2.0/:/usr/lib/gcc/h8300-none-elf/9.2.0/../../../../h8300-none-elf/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O1' '-S' '-Wall'