https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68714
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> (In reply to Jakub Jelinek from comment #4)
> > I'd add this regressed with r229128, and indeed before that change reassoc
> > has been able to optimize the comparisons, but now it is not. So, either we
> > defer the creation of vec_cond_expr until later time, or need to teach at
> > least reassoc pass about COND_EXPRs and VEC_COND_EXPRs.
>
> More than that, vec_cond_expr for non x86_64 AVX targets here is useless and
> makes it harder to optimize otherwise.
>
> Why again do we need the vec_cond_expr for those expressions again?
The same reason you need a conversion to do int i = a < b; in gimple.
Comparisons have a boolean type.
Btw, the patch from comment #1 would also help
int f(int x, int y)
{
return (x<y?-1:0) | (x==y?-1:0);
}
thus code with COND_EXPRs. Ok, that gets gimplified to if-then-else and
we don't optimize that either.
The allowed constants / bit operations can be extended to more cases as well I
guess.
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c (revision 232261)
+++ gcc/gimplify.c (working copy)
@@ -10723,8 +10723,22 @@ gimplify_expr (tree *expr_p, gimple_seq
goto expr_2;
}
- case FMA_EXPR:
case VEC_COND_EXPR:
+ {
+ enum gimplify_status r0, r1, r2;
+
+ r0 = gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p,
+ post_p, is_gimple_condexpr, fb_rvalue);
+ r1 = gimplify_expr (&TREE_OPERAND (*expr_p, 1), pre_p,
+ post_p, is_gimple_val, fb_rvalue);
+ r2 = gimplify_expr (&TREE_OPERAND (*expr_p, 2), pre_p,
+ post_p, is_gimple_val, fb_rvalue);
+
+ ret = MIN (MIN (r0, r1), r2);
+ break;
+ }
+
+ case FMA_EXPR:
case VEC_PERM_EXPR:
/* Classified as tcc_expression. */
goto expr_3;
helps gimplification to keep the condition inside the VEC_COND_EXPR:
f (vec x, vec y)
{
vec D.1765;
vector(4) int D.1766;
vector(4) int D.1767;
D.1766 = VEC_COND_EXPR <x < y, { -1, -1, -1, -1 }, { 0, 0, 0, 0 }>;
D.1767 = VEC_COND_EXPR <x == y, { -1, -1, -1, -1 }, { 0, 0, 0, 0 }>;
D.1765 = D.1766 | D.1767;
return D.1765;
}
forwprop is also supposed to re-store this.