This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Enhance ifcombine to recover non short circuit branches
- From: Zhenqiang Chen <zhenqiang dot chen at linaro dot org>
- To: Andrew Pinski <pinskia at gmail dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 18 Oct 2013 18:40:45 +0800
- Subject: Re: [PATCH] Enhance ifcombine to recover non short circuit branches
- Authentication-results: sourceware.org; auth=none
- References: <CACgzC7AbQLh+uv=vzC51DiHjZZn12yEjvtrcyo61z7KjeYCe7Q at mail dot gmail dot com> <CA+=Sn1mm+3Zv9HxgGt4T_utu+-nsvhhCWRF-aWk05K=_704LRw at mail dot gmail dot com> <CAFiYyc2AgJg2r6mzQ69gYo2chBSRFgdVSkSnFU_tQXEanU+NGQ at mail dot gmail dot com> <CA+=Sn1nuUbrX2_KcLf=dG0xwC7cpqn8UxAMMs1=+TUjAMPHKvg at mail dot gmail dot com> <CA+=Sn1mcRkm_FBOywC99cPQJXqM1xHRLnQEefvVcaDex5_gJVQ at mail dot gmail dot com>
On 18 October 2013 10:13, Andrew Pinski <pinskia@gmail.com> wrote:
> On Thu, Oct 17, 2013 at 6:39 PM, Andrew Pinski <pinskia@gmail.com> wrote:
>> On Thu, Oct 17, 2013 at 4:03 AM, Richard Biener
>> <richard.guenther@gmail.com> wrote:
>>> On Thu, Oct 17, 2013 at 4:14 AM, Andrew Pinski <pinskia@gmail.com> wrote:
>>>> 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?
>>>>
>>>> I had a much simpler change which did basically the same from 4.7 (I
>>>> can update it if people think this is a better approach).
>>>
>>> I like that more (note you can now use is_gimple_condexpr as predicate
>>> for force_gimple_operand).
>>
>>
>> Ok, with both this email and Jakub's email, I decided to port the
>> patch to the trunk but I ran into a bug in reassoc which I submitted
>> as PR 58775 (with a testcase which shows the issue without this
>> patch).
>
> I forgot to say that the tree-ssa-ifcombine.c hunk of the 4.7 patch
> applies correctly. Once PR 58775 is fixed, I will be testing and
> submitting the full patch including with the testcases from Zhenqiang.
I just post a patch to fix PR 58775. With the patch, your changes can
bootstrap on X86-64.
Thanks!
-Zhenqiang
> Thanks,
> Andrew
>
>>
>>
>>>
>>> With that we should be able to kill the fold-const.c transform?
>>
>>
>> I think so but I have never tested removing it.
>>
>> Thanks,
>> Andrew Pinski
>>
>>
>>>
>>> Thanks,
>>> Richard.
>>>
>>>> Thanks,
>>>> Andrew Pinski
>>>>
>>>>
>>>> 2012-09-29 Andrew Pinski <apinski@cavium.com>
>>>>
>>>> * tree-ssa-ifcombine.c: Include rtl.h and tm_p.h.
>>>> (ifcombine_ifandif): Handle cases where
>>>> maybe_fold_and_comparisons fails, combining the branches
>>>> anyways.
>>>> (tree_ssa_ifcombine): Inverse the order of
>>>> the basic block walk, increases the number of combinings.
>>>> * Makefile.in (tree-ssa-ifcombine.o): Update dependencies.
>>>>
>>>> * testsuite/gcc.dg/tree-ssa/phi-opt-2.c: Expect zero ifs as the compiler
>>>> produces a & b now.
>>>> * testsuite/gcc.dg/tree-ssa/phi-opt-9.c: Use a function call
>>>> to prevent conditional move to be used.
>>>> * testsuite/gcc.dg/tree-ssa/ssa-dom-thread-3.c: Remove check for
>>>> "one or more intermediate".
>>>>
>>>>
>>>>>
>>>>> 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.