On Mon, Apr 28, 2014 at 10:05 PM, Richard Henderson <r...@redhat.com> wrote: > On 04/17/2014 06:09 AM, Yuri Rumyantsev wrote: >> + /* Build cond expression using COND and constant operand >> + of reduction rhs. */ >> + c = fold_build_cond_expr (TREE_TYPE (rhs1), >> + unshare_expr (cond), >> + swap? zero: op1, >> + swap? op1: zero); > > Do we recognize somewhere the canonical value for the comparison is -1, and > simplify this further? > > E.g. > > if (A[i] != 0) num += 1; > > _vec_cmp = (_vec_A != _vec_ZERO); > _vec_num -= _vec_cmp; > > > if (A[i] != 0) num += x; > > _vec_cmp = (_vec_A != _vec_ZERO); > _vec_cmp *= _vec_x; > _vec_num -= _vec_cmp;
While the middle-end knows that vector comparisons result in {0,0...} or {-1,-1,...} I doubt that anyone implemented the above transform. Note that it depends on the target on whether the transform would be profitable - a target may only implement a vector conditional move for example (the XOP vcond one). So the correct place for the optimization would be the expander or combine (unless we apply some canonicalization rule on GIMPLE - but the back-transform is certainly more complicated than optimally expanding vec_A != vec_ZERO ? 0 : 1) Richard. > > > r~