From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 7FB583857C44; Wed, 5 Aug 2020 18:08:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7FB583857C44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596650916; bh=XBeqmL86SuxCM89vUNuS2sgj6VASX8yOVYlAc4kkBdg=; h=From:To:Subject:Date:From; b=nYm7G2jxqJJQ1Uju/DbyY86+ZDxPEYG/bP43JvdE8ZXqeqfNQjfG3sB+lTEc7rx60 a58ciF+Enfocnv3mp+G25/pvbvIfoXNjlZ155VoWFx2o9Zo2+QehX1TWJsOgpyFcKO W8D8/D5eeT1tcdVsnZMsAvdHMDVkD77HdwxUuIJg= From: "sandra at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/96487] New: cddce1 optimizer depends on order of basic blocks Date: Wed, 05 Aug 2020 18:08:35 +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-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sandra at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Aug 2020 18:08:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96487 Bug ID: 96487 Summary: cddce1 optimizer depends on order of basic blocks Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: sandra at gcc dot gnu.org Target Milestone: --- Created attachment 49007 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D49007&action=3Dedit c and c++ dump files If the test case gcc.dg/tree-ssa/ssa-dce-3.c is compiled as C++ code instead of as C, it fails to reduce to an empty loop as expected. It seems to be triggered by a slight difference in the input coming into the cddce1 pass. The C front end canonicalizes the test to the end of the loop so the latch (bb 5) falls through to the header (bb 6). The C++ front end orders the latch (bb 6) last with a goto to the header (bb 3). I did some additional tracing of the flow through the pass beyond the dump file output. Because the latch in the C input does not end with a control statement, it is ignored by mark_last_stmt_necessary, via the call to mark_control_dependent_edges_necessary at the end of find_obviously_necessary_stmts. So in the C case, nothing gets added to the work list, while for C++ it does process the latch block, follow the control flow out of it, and ends up marking the loop end test etc as necessary. I am wondering if this is a bug in the way the C output is handled and it is incorrectly optimizing away the loop body. It seems like it should not matter if the control transfer between blocks is done via explicit goto or via fallthrough, anyway; either it ought to handle the fallthrough case like the explicit goto case, or vice versa. I originally noticed this problem in conjunction with these patches to unify the loop handling in the C and C++ front ends: https://gcc.gnu.org/pipermail/gcc-patches/2019-November/534142.html But it can be reproduced with unmodified sources just by compiling with g++ instead of gcc. The commands used to produce the attached dump files were x86_64-linux-gnu-gcc /path/to/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-3.c -O2 -fdump-tree-dse1 -fdump-tree-cddce1-details -S x86_64-linux-gnu-g++ /path/to/gcc/testsuite/gcc.dg/tree-ssa/ssa-dce-3.c -O2 -fdump-tree-dse1 -fdump-tree-cddce1-details -S=