PATCH: fix PR tree-optimization/39874

H.J. Lu hjl.tools@gmail.com
Sun Dec 12 19:47:00 GMT 2010


On Mon, May 31, 2010 at 5:32 PM, Sandra Loosemore
<sandra@codesourcery.com> wrote:
> This patch adds some more sophisticated logic for simplifying logical AND
> and OR expressions to fix PR39874, one of the sub-cases of PR28685.
>
> The test case illustrates the problem:
>
> void func();
> void test(char *signature)
> {
>  char ch = signature[0];
>  if (ch == 15 || ch == 3)
>  {
>    if (ch == 15) func();
>  }
> }
>
> Here, the ifcombine pass was being too stupid to optimize away the outer
> "if" because it was relying on combine_comparisons only to detect when it
> can do that.  So, the basic idea of my patch is to provide better logic for
> optimizing logical ANDs and ORs in the ifcombine pass.  I recently added a
> patch to tree_ssa_reassoc that also used combine_comparisons for a similar
> purpose to fix another one of the PR28685 sub-cases, and my new functions
> can apply there as well.
>
> This patch didn't really start out being quite this complicated, but once I
> got started I figured I might as well add all the usual boolean identities
> and comparison simplifications.  Much of this duplicates simplifications
> that are performed on trees in fold-const.c, but my code deals with gimple
> representations and simplifications that can be performed by
> copy-propagating SSA variables.  (E.g., in the example above, the "ch == 15"
> expression is PRE'ed coming into the ifcombine pass.)
>
> This patch passed 3-stage bootstrap and testing on native x86_64 Linux.  I
> also tested on ARM Linux, and ran SPEC benchmarks on ARM to make sure this
> wasn't accidentally un-optimizing something else.  OK to check in?
>
> -Sandra
>
>
> 2010-05-31  Sandra Loosemore  <sandra@codesourcery.com>
>
>        PR tree-optimization/39874
>        PR middle-end/28685
>
>        gcc/
>        * gimple.h (maybe_fold_and_comparisons, maybe_fold_or_comparisons):
>        Declare.
>        * gimple-fold.c (canonicalize_bool, same_bool_comparison_p,
>        same_bool_result_p): New.
>        (and_var_with_comparison, and_var_with_comparison_1,
>        and_comparisons_1, and_comparisons, maybe_fold_and_comparisons): New.
>        (or_var_with_comparison, or_var_with_comparison_1,
>        or_comparisons_1, or_comparisons, maybe_fold_or_comparisons): New.
>        * tree-ssa-reassoc.c (eliminate_redundant_comparison): Use
>        maybe_fold_and_comparisons or maybe_fold_or_comparisons instead
>        of combine_comparisons.
>        * tree-ssa-ifcombine.c (ifcombine_ifandif, ifcombine_iforif):
> Likewise.
>

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46909


-- 
H.J.



More information about the Gcc-patches mailing list