Testcase: int f1(int a, int b) { return a == b; } ------ We produce right now: _f1: xor r4,r3,r4 cntlzw r4,r4 <--- sign never 1 srwi r4,r4,5 <--- upper bits defined as 0 extsw r3,r4 blr The sign extend is incorrect as r4's sign will never be 1 and all the upper bits will always be zero because of srwi. we have the same issue if the return value is unsigned int also in that there is an extra zero extend. This is even with -fsee.
I think this is a case where combine (and other passes) don't know that eq is always signed extended (when the true is not -1): (insn 9 8 10 2 (set (reg:SI 123) (eq:SI (reg:SI 3 3 [ a ]) (reg:SI 4 4 [ b ]))) 471 {*eqsi} (nil) (expr_list:REG_DEAD (reg:DI 3 3 [ a ]) (expr_list:REG_DEAD (reg:DI 4 4 [ b ]) (nil)))) (note 10 9 16 2 NOTE_INSN_DELETED) (insn 16 10 22 2 (set (reg/i:DI 3 3 [ <result> ]) (sign_extend:DI (reg:SI 123))) 27 {*rs6000.md:393} (insn_list:REG_DEP_TRUE 9 (nil)) (expr_list:REG_DEAD (reg:SI 123) (nil)))
Still happens on the trunk as of today.
Still happening. The problem now is that eq:SI is costed as one insn (which it is not), but eq:DI as three.
Author: segher Date: Wed May 13 19:14:07 2015 New Revision: 223174 URL: https://gcc.gnu.org/viewcvs?rev=223174&root=gcc&view=rev Log: PR rtl-optimization/30967 * config/rs6000/rs6000.c (rs6000_rtx_costs): Don't consider destination mode for the cost of scc patterns. Modified: trunk/gcc/ChangeLog trunk/gcc/config/rs6000/rs6000.c
Fixed on trunk. No backport planned.
Author: segher Date: Sat May 16 17:56:55 2015 New Revision: 223250 URL: https://gcc.gnu.org/viewcvs?rev=223250&root=gcc&view=rev Log: Backport from mainline 2015-05-13 Segher Boessenkool <segher@kernel.crashing.org> PR rtl-optimization/30967 * config/rs6000/rs6000.c (rs6000_rtx_costs): Don't consider destination mode for the cost of scc patterns. Modified: branches/gcc-5-branch/gcc/ChangeLog branches/gcc-5-branch/gcc/config/rs6000/rs6000.c