Hi all, In this PR we end up removing a widening multiplication. I suspect it's some path in combine that doesn't handle the case where we return clobber of 0 properly. This started with my recent combine patch r230326. Changing the subst hunk from that patch to just return x when handling a no-op substitution fixes the testcase for me and doesn't regress the widening-mult cases that r230326 improved. In fact, with this patch I'm seeing improved codegen for aarch64 with some widening multiplications combined with constant operands and ending up in bitfield move/insert instructions.
Bootstrapped and tested on aarch64, arm, x86_64. Ok for trunk? Thanks, Kyrill 2015-11-19 Kyrylo Tkachov <kyrylo.tkac...@arm.com> PR rtl-optimization/68381 * combine.c (subst): Do not return clobber of zero in widening mult case. Just return x unchanged if it is a no-op substitution. 2015-11-19 Kyrylo Tkachov <kyrylo.tkac...@arm.com> PR rtl-optimization/68381 * gcc.c-torture/execute/pr68381.c: New test.
commit 58ec17169da2bb864d2bcaeb34a33e8c5a93348f Author: Kyrylo Tkachov <kyrylo.tkac...@arm.com> Date: Tue Nov 17 15:33:58 2015 +0000 [combine] PR rtl-optimization/68381: Only restrict pure simplification in mult-extend subst case, allow other substitutions diff --git a/gcc/combine.c b/gcc/combine.c index 26b14bf..3791abf 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -5286,7 +5286,7 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) || GET_CODE (SET_DEST (x)) == PC)) fmt = "ie"; - /* Substituting into the operands of a widening MULT is not likely + /* Trying to simplify the operands of a widening MULT is not likely to create RTL matching a machine insn. */ if (code == MULT && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND @@ -5294,13 +5294,10 @@ subst (rtx x, rtx from, rtx to, int in_dest, int in_cond, int unique_copy) && (GET_CODE (XEXP (x, 1)) == ZERO_EXTEND || GET_CODE (XEXP (x, 1)) == SIGN_EXTEND) && REG_P (XEXP (XEXP (x, 0), 0)) - && REG_P (XEXP (XEXP (x, 1), 0))) - { - if (from == to) - return x; - else - return gen_rtx_CLOBBER (GET_MODE (x), const0_rtx); - } + && REG_P (XEXP (XEXP (x, 1), 0)) + && from == to) + return x; + /* Get the mode of operand 0 in case X is now a SIGN_EXTEND of a constant. */ diff --git a/gcc/testsuite/gcc.c-torture/execute/pr68381.c b/gcc/testsuite/gcc.c-torture/execute/pr68381.c new file mode 100644 index 0000000..33012a3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr68381.c @@ -0,0 +1,22 @@ +/* { dg-options "-fexpensive-optimizations -fno-tree-bit-ccp" } */ + +__attribute__ ((noinline, noclone)) +int +foo (unsigned short x, unsigned short y) +{ + int r; + if (__builtin_mul_overflow (x, y, &r)) + __builtin_abort (); + return r; +} + +int +main (void) +{ + int x = 1; + int y = 2; + if (foo (x, y) != x * y) + __builtin_abort (); + return 0; +} +