https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61837
--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Xiong Hu Luo <luo...@gcc.gnu.org>: https://gcc.gnu.org/g:8a15faa730f99100f6f3ed12663563356ec5a2c0 commit r11-407-g8a15faa730f99100f6f3ed12663563356ec5a2c0 Author: Xionghu Luo <luo...@linux.ibm.com> Date: Thu May 14 21:03:24 2020 -0500 Fold (add -1; zero_ext; add +1) operations to zero_ext when not overflow(PR37451, PR61837) This "subtract/extend/add" existed for a long time and still annoying us (PR37451, part of PR61837) when converting from 32bits to 64bits, as the ctr register is used as 64bits on powerpc64, Andraw Pinski had a patch but caused some issue and reverted by Joseph S. Myers(PR37451, PR37782). Andraw: http://gcc.gnu.org/ml/gcc-patches/2008-09/msg01070.html http://gcc.gnu.org/ml/gcc-patches/2008-10/msg01321.html Joseph: https://gcc.gnu.org/legacy-ml/gcc-patches/2011-11/msg02405.html We still can do the simplification from "subtract/zero_ext/add" to "zero_ext" when loop iterations is known to be LT than MODE_MAX (only do simplify when counter+0x1 NOT overflow). Bootstrap and regression tested pass on Power8-LE. gcc/ChangeLog 2020-05-15 Xiong Hu Luo <luo...@linux.ibm.com> PR rtl-optimization/37451, part of PR target/61837 * loop-doloop.c (doloop_simplify_count): New function. Simplify (add -1; zero_ext; add +1) to zero_ext when not wrapping. (doloop_modify): Call doloop_simplify_count. gcc/testsuite/ChangeLog 2020-05-15 Xiong Hu Luo <luo...@linux.ibm.com> PR rtl-optimization/37451, part of PR target/61837 * gcc.target/powerpc/doloop-2.c: New test.