This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [PATCH 1/n] Add conditional compare support
- From: "Zhenqiang Chen" <zhenqiang dot chen at arm dot com>
- To: "'Richard Henderson'" <rth at redhat dot com>
- Cc: "Richard Earnshaw" <Richard dot Earnshaw at arm dot com>, "'Richard Biener'" <richard dot guenther at gmail dot com>, "GCC Patches" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 31 Oct 2013 17:06:10 +0800
- Subject: RE: [PATCH 1/n] Add conditional compare support
- Authentication-results: sourceware.org; auth=none
- References: <000001ce9e58$6dadf230$4909d690$ at arm dot com> <CAFiYyc25hLxrAnsOXbfqYo=Rsw_MDopxb66bygfac-CEsffOEw at mail dot gmail dot com> <521C9406 dot 6050901 at arm dot com> <CAFiYyc0zrBBUvRF0Vmv5PyvypfK75QYuc3D9AMTE+Fkh3nCq4Q at mail dot gmail dot com> <000001ceb453$ceaea3c0$6c0beb40$ at arm dot com> <523AC006 dot 5030706 at arm dot com> <000101ceb829$31ec9040$95c5b0c0$ at arm dot com> <000101cecf0b$148b33a0$3da19ae0$ at arm dot com> <5267F5DE dot 3050109 at redhat dot com> <000001ced090$98563e60$c902bb20$ at arm dot com> <000001ced3b8$4f8dcf60$eea96e20$ at arm dot com> <526E7D81 dot 7090805 at redhat dot com> <000001ced552$e5dcf220$b196d660$ at arm dot com> <5271688A dot 1000108 at redhat dot com>
> -----Original Message-----
> From: Richard Henderson [mailto:rth@redhat.com]
> Sent: Thursday, October 31, 2013 4:14 AM
> To: Zhenqiang Chen
> Cc: Richard Earnshaw; 'Richard Biener'; GCC Patches
> Subject: Re: [PATCH 1/n] Add conditional compare support
>
> > +/* RCODE0, RCODE1 and a valid return value should be enum rtx_code.
> > + TCODE should be enum tree_code.
> > + Check whether two compares are a valid combination in the target to
> generate
> > + a conditional compare. If valid, return the new compare after
> combination.
> > + */
> > +DEFHOOK
> > +(legitimize_cmp_combination,
> > + "This target hook returns the dominance compare if the two compares
> > +are\n\ a valid combination. This target hook is required only when
> > +the target\n\ supports conditional compare, such as ARM.", int, (int
> > +rcode0, int rcode1, int tcode),
> > + default_legitimize_cmp_combination)
> > +
> > +/* RCODE0, RCODE1 and a valid return value should be enum rtx_code.
> > + TCODE should be enum tree_code.
> > + Check whether two compares are a valid combination in the target to
> generate
> > + a conditional compare. If valid, return the new compare after
> combination.
> > + The difference from legitimize_cmp_combination is that its first
> compare is
> > + the result of a previous conditional compare, which leads to more
> constrain
> > + on it, since no way to swap the two compares. */ DEFHOOK
> > +(legitimize_ccmp_combination, "This target hook returns the
> > +dominance compare if the two compares are\n\ a valid combination.
> > +This target hook is required only when the target\n\ supports
> > +conditional compare, such as ARM.", int, (int rcode0, int rcode1,
> > +int tcode),
> > + default_legitimize_ccmp_combination)
> > +
>
> Why do these hooks still exist? They should be redundant with ...
They are not necessary. Will remove them.
> > +/* CMP0 and CMP1 are two compares. USED_AS_CC_P indicates whether
> the target
> > + is used as CC or not. TCODE should be enum tree_code.
> > + The hook will return a condtional compare RTX if all checkes are
> > +OK. */ DEFHOOK (gen_ccmp_with_cmp_cmp, "This target hook returns a
> > +condtional compare RTX if the two compares are\n\ a valid
> > +combination. This target hook is required only when the target\n\
> > +supports conditional compare, such as ARM.", rtx, (gimple cmp0,
> > +gimple cmp1, int tcode, bool used_as_cc_p),
> > + default_gen_ccmp_with_cmp_cmp)
> > +
> > +/* CC is the result of a previous conditional compare. CMP1 is a compare.
> > + USED_AS_CC_P indicates whether the target is used as CC or not.
> > + TCODE should be enum tree_code.
> > + The hook will return a condtional compare rtx if all checkes are
> > +OK. */ DEFHOOK (gen_ccmp_with_ccmp_cmp, "This target hook returns
> a
> > +condtional compare RTX if the CC and CMP1 are\n\ a valid combination.
> > +This target hook is required only when the target\n\ supports
> > +conditional compare, such as ARM.", rtx, (rtx cc, gimple cmp1, int
> > +tcode, bool used_as_cc_p),
> > + default_gen_ccmp_with_ccmp_cmp)
> > +
>
> ... these.
>
> Why in the world are you passing down gimple to the backends? The
> expand_operands done therein should have been done in expr.c.
> The hooks are still not what I suggested, particularly
> gen_ccmp_with_cmp_cmp is what I was trying to avoid, passing down two
> initial compares like that.
>
> To be 100% explicit this time, I think the hooks should be
Thank you very much!
> DEFHOOK
> (gen_ccmp_first,
> "This function emits a comparison insn for the first of a sequence of\n\
> conditional comparisions. It returns a comparison expression appropriate\n\
> for passing to @code{gen_ccmp_next} or to @code{cbranch_optab}.", rtx,
> (int code, rtx op0, rtx op1),
> NULL)
> DEFHOOK
> (gen_ccmp_next,
> "This function emits a conditional comparison within a sequence of\n\
> conditional comparisons. The @code{prev} expression is the result of a\n\
> prior call to @code{gen_ccmp_first} or @code{gen_ccmp_next}. It may
> return\n\ @code{NULL} if the combination of @code{prev} and this
> comparison is\n\ not supported, otherwise the result must be appropriate
> for passing to @code{gen_ccmp_next} or @code{cbranch_optab}.", rtx, (rtx
> prev, int code, rtx op0, rtx op1),
> NULL)
gen_ccmp_first and gen_ccmp_next are better. But need some improvement.
With two compares, we might swap the order of the two compares to get a valid combination. This is what current ARM does (Please refer arm_select_dominace_cc_mode, cmp_and, cmp_ior, and_scc_scc and ior_scc_scc). To improve gen_ccmp_first, we need another function/hook to determine which compare is done first. I will double check ARM backend to avoid hook.
Hook gen_ccmp_next needs one more parameter to indicate AND/IOR since they will generate different instructions.
I will update the patch.
> All of your existing tests for HAVE_ccmp should be replaced with
>
> if (targetm.gen_ccmp_first == NULL)
> return; /* No ccmp supported. */
> gcc_checking_assert(targetm.gen_ccmp_next != NULL);
Thanks. I will update it.
-Zhenqiang