https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115659

--- Comment #1 from Kewen Lin <linkw at gcc dot gnu.org> ---
Now isel has some handling on x CMP y ? -1 : 0 to x CMP y, 

          /* Try to fold x CMP y ? -1 : 0 to x CMP y.  */
          if (can_compute_op0
              && integer_minus_onep (op1)
              && integer_zerop (op2)
              && TYPE_MODE (TREE_TYPE (lhs)) == TYPE_MODE (TREE_TYPE (op0)))
            {
              tree conv_op = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), op0);
              gassign *new_stmt = gimple_build_assign (lhs, conv_op);
              gsi_replace (gsi, new_stmt, true);
              return new_stmt;
            }

it looks can be extended to cover:

   c = x CMP y 
   r = c ? -1 : z  =>  r = c ? c : z
   r = c ?  z : 0  =>  r = c ? z : c

, but better to be supported in match.pd?

The handling in rs6000_emit_vector_cond_expr already knows inversion happens or
not, so it further handles the case like:

   c = x CMP y  // c' = x OP y, c = ~c'

   r = c ?  0 : z   =>  r = c' ?  z  : c'
   r = c ?  z : -1  =>  r = c' ?  c' : z

it seems to need a helper to query whether if target would expand with
inversion for one given comparison operator?

Reply via email to