From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101355 invoked by alias); 17 Aug 2015 09:25:33 -0000 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 Received: (qmail 101288 invoked by uid 48); 17 Aug 2015 09:25:29 -0000 From: "amker at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/43174] Teaching SCEV about ADDR_EXPR causes regression Date: Mon, 17 Aug 2015 09:25:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: amker at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-08/txt/msg01105.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43174 --- Comment #3 from amker at gcc dot gnu.org --- Note for the three levels of loop example, GCC chooses one IV for both j and k loops, thus generates pretty clean output on x86_64 with O2. For the simple example, now gcc can eliminate comparison iv with the address candidate, and generates below codes: : ivtmp.18_14 = (unsigned long) &a; _10 = &a + 60516; _28 = (unsigned long) _10; goto ; : : # s_18 = PHI # ivtmp.9_12 = PHI _22 = (void *) ivtmp.9_12; _8 = MEM[base: _22, offset: 0B]; s_9 = _8 + s_18; ivtmp.9_1 = ivtmp.9_12 + 4; if (ivtmp.9_1 != _27) goto ; else goto ; : # s_17 = PHI ivtmp.18_15 = ivtmp.18_5 + 492; if (ivtmp.18_15 != _28) goto ; else goto ; : : # s_19 = PHI # ivtmp.18_5 = PHI ivtmp.9_4 = ivtmp.18_5; _29 = ivtmp.18_5 + 492; _27 = _29; goto ; : # s_16 = PHI return s_16; With this, following gimple optimizers are able to CSE the opportunity of "ivtmp.18_5 + 492". As a result, optimal code is generated as in optimized dump: : ivtmp.18_14 = (unsigned long) &a; _28 = (unsigned long) &MEM[(void *)&a + 60516B]; goto ; : # s_18 = PHI # ivtmp.9_12 = PHI _22 = (void *) ivtmp.9_12; _8 = MEM[base: _22, offset: 0B]; s_9 = _8 + s_18; ivtmp.9_1 = ivtmp.9_12 + 4; if (ivtmp.9_1 != _29) goto ; else goto ; : if (_28 != _29) goto ; else goto ; : # s_19 = PHI # ivtmp.18_5 = PHI <_29(4), ivtmp.18_14(2)> _29 = ivtmp.18_5 + 492; goto ; : return s_9; This in effect is the transformation you wanted in this PR, but I doubt if GCC can do this if it can't eliminate the inner loop's comparison using ivtmp.9_1 at the first place. On the other hand, for cases that we can use IV's final value, it maybe likely for GCC to eliminate the comparison IV.