From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30476 invoked by alias); 9 Nov 2011 07:37:31 -0000 Received: (qmail 30278 invoked by uid 22791); 9 Nov 2011 07:37:30 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 09 Nov 2011 07:37:15 +0000 From: "liujiangning at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/51049] New: A regression caused by "Improve handling of conditional-branches on targets with high branch costs" Date: Wed, 09 Nov 2011 07:49:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: liujiangning at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg00867.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51049 Bug #: 51049 Summary: A regression caused by "Improve handling of conditional-branches on targets with high branch costs" Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: liujiangning@gcc.gnu.org int f(char *i, int j) { if (*i && j!=2) return *i; else return j; } Before the check-in r180109, we have D.4710 = *i; D.4711 = D.4710 != 0; D.4712 = j != 2; D.4713 = D.4711 & D.4712; if (D.4713 != 0) goto ; else goto ; : D.4710 = *i; D.4716 = (int) D.4710; return D.4716; : D.4716 = j; return D.4716; After check-in r180109, we have D.4711 = *i; if (D.4711 != 0) goto ; else goto ; : if (j != 2) goto ; else goto ; : D.4711 = *i; D.4714 = (int) D.4711; return D.4714; : D.4714 = j; return D.4714; the code below in function fold_truth_andor makes difference, /* Transform (A AND-IF B) into (A AND B), or (A OR-IF B) into (A OR B). For sequence point consistancy, we need to check for trapping, and side-effects. */ else if (code == icode && simple_operand_p_2 (arg0) && simple_operand_p_2 (arg1)) return fold_build2_loc (loc, ncode, type, arg0, arg1); for "*i != 0" simple_operand_p(*i) returns false. Originally this is not checked by the code. Please refer to http://gcc.gnu.org/ml/gcc-patches/2011-10/msg02445.html for discussion details. This change accidently made some benchmarks significantly improved due to some other reasons, but Michael gave the comments below. ======Michael's comment====== It's nice that it caused a benchmark to improve significantly, but that should be done via a proper analysis and patch, not as a side effect of a supposed non-change. ======End of Michael's comment====== The potential impact would be hurting other scenarios on performance. The key point is for this small case I gave RHS doesn't have side effect at all, so the optimization of changing it to AND doesn't violate C specification. ======Kai's comment====== As for the case that left-hand side has side-effects but right-hand not, we aren't allowed to do this AND/OR merge. For example 'if ((f = foo ()) != 0 && f < 24)' we aren't allowed to make this transformation. This shouldn't be that hard. We need to provide to simple_operand_p_2 an additional argument for checking trapping or not. ======End of Kai's comment====== This optimization change is blocking some other optimizations I am working on in back-ends. For example, the problem I described at http://gcc.gnu.org/ml/gcc/2011-09/msg00175.html disappeared. But it is not a proper behavior. Thanks, -Jiangning