Hi! While expand_mult correctly checks for multiplication by zero, expand_widening_mult does not and as floor_log2 (0) returns -1, it attempts to expand a double-word shift by -1 and on ppc32 happens to return 2 w* 0 = 1. Usually earlier optimizations just ensure that w* 0 isn't expanded using expand_widening_mult, e.g. expand_mul_overflow which expands widening multiply separately on highpart and lowpart of some value can end up with this. I think it is better to fix this on the expand_widening_mult side rather than having to bother with those special cases in every caller. In 4.9, I think ubsan_expand_si_overflow_mul_check can trigger the same thing.
Testcase for this is builtin-arith-overflow-14.c on ppc32. Bootstrapped/regtested on x86_64-linux and i686-linux, tested on the testcase with ppc cross. Ok for trunk/4.9? 2014-12-03 Jakub Jelinek <ja...@redhat.com> PR c/59708 * expmed.c (expand_widening_mult): Return const0_rtx if coeff is 0. --- gcc/expmed.c.jj 2014-11-18 08:26:45.000000000 +0100 +++ gcc/expmed.c 2014-12-03 11:12:37.519297971 +0100 @@ -3289,6 +3289,9 @@ expand_widening_mult (machine_mode mode, enum mult_variant variant; struct algorithm algorithm; + if (coeff == 0) + return CONST0_RTX (mode); + /* Special case powers of two. */ if (EXACT_POWER_OF_2_OR_ZERO_P (coeff)) { Jakub