Bug 44710 - [4.6 Regression] If-conversion generates redundant statements
Summary: [4.6 Regression] If-conversion generates redundant statements
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Sebastian Pop
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2010-06-29 09:10 UTC by Ira Rosen
Modified: 2010-07-08 16:40 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-29 13:56:58


Attachments
Full testcase (286 bytes, application/octet-stream)
2010-06-29 09:11 UTC, Ira Rosen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ira Rosen 2010-06-29 09:10:38 UTC
Starting from revision 160625 (http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01155.html) if-conversion generates redundant statements for 

  for (i = 0; i < N; i++)
    if (arr[i] < limit)
      {
        pos = i + 1;
        limit = arr[i];
      }


  # pos_22 = PHI <pos_1(4), 1(2)>
  # i_23 = PHI <prephitmp.8_2(4), 0(2)>
  # limit_24 = PHI <limit_4(4), 1.28e+2(2)>
  # ivtmp.9_18 = PHI <ivtmp.9_17(4), 64(2)>
  limit_9 = arr[i_23];
  pos_10 = i_23 + 1;
  D.4534_12 = limit_9 < limit_24;                       <-----
  pretmp.7_3 = i_23 + 1;
  D.4535_20 = limit_9 >= limit_24;                      <-----
  pos_1 = [cond_expr] limit_9 >= limit_24 ? pos_22 : pos_10;
  limit_4 = [cond_expr] limit_9 >= limit_24 ? limit_24 : limit_9;
  prephitmp.8_2 = [cond_expr] limit_9 >= limit_24 ? pretmp.7_3 : pos_10;
  ivtmp.9_17 = ivtmp.9_18 - 1;
  D.4536_19 = D.4534_12 || D.4535_20;                   <-----
  if (ivtmp.9_17 != 0)
    goto <bb 4>;
  else
    goto <bb 5>;

The statements are removed by later dce pass, but they interfere with my
attempts to vectorize this loop.
Comment 1 Ira Rosen 2010-06-29 09:11:46 UTC
Created attachment 21036 [details]
Full testcase
Comment 2 Sebastian Pop 2010-06-29 13:56:58 UTC
Mine.

Patch 0005 of http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02250.html
fixes exactly this problem.  I have not yet worked on correcting the patch
as Richi asked.
Comment 3 Sebastian Pop 2010-07-08 16:38:20 UTC
Subject: Bug 44710

Author: spop
Date: Thu Jul  8 16:38:00 2010
New Revision: 161964

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161964
Log:
Call maybe_fold_or_comparisons to fold OR-ed predicates.

2010-07-08  Sebastian Pop  <sebastian.pop@amd.com>

	PR tree-optimization/44710
	* tree-if-conv.c (parse_predicate): New.
	(add_to_predicate_list): Call it, call maybe_fold_or_comparisons.
	Make sure that the predicates are either SSA_NAMEs or gimple_condexpr.

	* gcc.dg/tree-ssa/ifc-6.c: New.
	* gcc.dg/tree-ssa/ifc-pr44710.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ifc-6.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ifc-pr44710.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-if-conv.c

Comment 4 Sebastian Pop 2010-07-08 16:40:50 UTC
Fixed.