This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Match-and-simplify and COND_EXPR
- From: Richard Biener <rguenther at suse dot de>
- To: Andrew Pinski <pinskia at gmail dot com>
- Cc: GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Thu, 6 Nov 2014 11:40:50 +0100 (CET)
- Subject: Re: Match-and-simplify and COND_EXPR
- Authentication-results: sourceware.org; auth=none
- References: <CA+=Sn1=ZrkDn8FS-5qFvh-ndF2isFD9xBQmE_gLvA6qAVmE02w at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1411061126240 dot 27850 at zhemvz dot fhfr dot qr>
On Thu, 6 Nov 2014, Richard Biener wrote:
> On Wed, 5 Nov 2014, Andrew Pinski wrote:
>
> > Hi,
> > I was trying to hook up tree-ssa-phiopt to match-and-simplify using
> > either gimple_build (or rather using gimple_simplify depending on if
> > we want to produce cond_expr for conditional move). I ran into a
> > problem.
> > With the pattern below:
> > /* a ? 0 : 1 -> a if 0 and 1 are integral types. */
> > (simplify
> > (cond_expr @0 integer_zerop integer_onep)
> > (if (INTEGRAL_TYPE_P (type))
> > (convert @0)))
>
> Ok, so you are capturing a GENERIC expr here but nothing knows that.
> It would work if you'd do (ugh)
>
> (for op (lt le eq ne ge gt)
> (simplify
> (cond_expr (op @0 @1) integer_zerop integer_onep)
> (if (INTEGRAL_TYPE_P (type))
> (convert (op @0 @1)))))
> (simplify
> (cond_expr SSA_NAME@0 integer_zerop integer_onep)
> (if (INTEGRAL_TYPE_P (type))
> (convert @0))))
>
> as a workaround. To make your version work will require (quite)
> some special-casing in the code generator or maybe the resimplify
> helper. Let me see if I can cook up a "simple" fix.
Sth like below (for the real fix this has to be replicated in
all gimple_resimplifyN functions). I'm missing a testcase
where the pattern would apply (and not be already folded by fold),
so I didn't check if it actually works.
Bah, of course we should fix COND_EXPRs to not embed a GENERIC
expr...
Richard.
Index: gcc/gimple-match-head.c
===================================================================
--- gcc/gimple-match-head.c (revision 217035)
+++ gcc/gimple-match-head.c (working copy)
@@ -90,6 +90,13 @@ gimple_resimplify1 (gimple_seq *seq,
code_helper *res_code, tree type, tree *res_ops,
tree (*valueize)(tree))
{
+ /* ??? Stupid tcc_comparison GENERIC trees in COND_EXPRs. */
+ if (COMPARISON_CLASS_P (res_ops[0]))
+ res_ops[0] = gimple_build (seq,
+ TREE_CODE (res_ops[0]), TREE_TYPE (res_ops[0]),
+ TREE_OPERAND (res_ops[0], 0),
+ TREE_OPERAND (res_ops[0], 1));
+
if (constant_for_folding (res_ops[0]))
{
tree tem = NULL_TREE;