This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Enhance ifcombine to recover non short circuit branches


On Wed, Oct 16, 2013 at 2:12 AM, Zhenqiang Chen
<zhenqiang.chen@linaro.org> wrote:
> Hi,
>
> The patch enhances ifcombine pass to recover some non short circuit
> branches. Basically, it will do the following transformation:
>
> Case 1:
>   if (cond1)
>     if (cond2)
> ==>
>   if (cond1 && cond2)
>
> Case 2:
>   if (cond1)
>     goto L1
>   if (cond2)
>     goto L1
> ==>
>   if (cond1 || cond2)
>     goto L1
>
> Case 3:
>   if (cond1)
>     goto L1
>   else
>     goto L2
> L1:
>   if (cond2)
>     goto L2
> ==>
>   if (invert (cond1) || cond2)
>     goto L2
>
> Case 4:
>   if (cond1)
>     goto L1
>   if (cond2)
>     goto L2
> L1:
> ==>
>   if (invert (cond1) && cond2)
>     goto L2
>
> Bootstrap on X86-64 and ARM.
>
> Two new FAILs in regression tests:
> gcc.dg/uninit-pred-8_b.c
> gcc.dg/uninit-pred-9_b.c
> uninit pass should be enhanced to handle more complex conditions. Will
> submit a bug to track it and fix it later.
>
> Is it OK for trunk?
>
> Thanks!
> -Zhenqiang
>
> ChangeLog:
> 2013-10-16  Zhenqiang Chen  <zhenqiang.chen@linaro.org>
>
>         * fold-const.c (simple_operand_p_2): Make it global.
>         * tree.h (simple_operand_p_2): Declare it.
>         * tree-ssa-ifcombine.c: Include rtl.h and tm_p.h.
>         (bb_has_overhead_p, generate_condition_node,
>         ifcombine_ccmp): New functions.
>         (ifcombine_fold_ifandif): New function, extracted from
>         ifcombine_ifandif.
>         (ifcombine_ifandif): Call ifcombine_ccmp.
>         (tree_ssa_ifcombine_bb): Skip optimized bb.
>
> testsuite/ChangeLog
> 2013-10-16  Zhenqiang Chen  <zhenqiang.chen@linaro.org>
>
>         * gcc.dg/tree-ssa/ssa-ifcombine-ccmp-1.c: New test case.
>         * gcc.dg/tree-ssa/ssa-ifcombine-ccmp-2.c: New test case.
>         * gcc.dg/tree-ssa/ssa-ifcombine-ccmp-3.c: New test case.
>         * gcc.dg/tree-ssa/ssa-ifcombine-ccmp-4.c: New test case.
>         * gcc.dg/tree-ssa/ssa-ifcombine-ccmp-5.c: New test case.
>         * gcc.dg/tree-ssa/ssa-ifcombine-ccmp-6.c: New test case.
>         * gcc.dg/tree-ssa/ssa-dom-thread-3.c: Updated.


One quick review of this patch, you don't don't need to test
simple_operand_p_2 as in gimple, they will always be simple.  So it at
least reduces this patch.  Also your bb_has_overhead_p can be simply:
!gsi_one_before_end_p (gsi_start_nondebug_after_labels_bb (inner_cond_bb))

Where gsi_start_nondebug_after_labels_bb is defined as:
/* Return a new iterator pointing to the first non-debug non-label statement in
   basic block BB.  */

static inline gimple_stmt_iterator
gsi_start_nondebug_after_labels_bb (basic_block bb)
{
  gimple_stmt_iterator i = gsi_after_labels (bb);

  if (!gsi_end_p (i) && is_gimple_debug (gsi_stmt (i)))
    gsi_next_nondebug (&i);

  return i;
}

Thanks,
Andrew Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]