From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33245 invoked by alias); 24 Apr 2017 08:54:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 32645 invoked by uid 89); 24 Apr 2017 08:54:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=BAYES_00,GIT_PATCH_2,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=opportunity X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Apr 2017 08:54:22 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id BC1BEAC39 for ; Mon, 24 Apr 2017 08:54:22 +0000 (UTC) Date: Mon, 24 Apr 2017 09:06:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR79201 (half-way) Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SW-Source: 2017-04/txt/msg01010.txt.bz2 One issue in PR79201 is that we don't sink pure/const calls which is what the following simple patch fixes. Bootstrap and regtest running on x86_64-unknown-linux-gnu. Richard. 2017-04-24 Richard Biener PR tree-optimization/79201 * tree-ssa-sink.c (statement_sink_location): Handle calls. * gcc.dg/tree-ssa/ssa-sink-16.c: New testcase. Index: gcc/tree-ssa-sink.c =================================================================== *** gcc/tree-ssa-sink.c (revision 247091) --- gcc/tree-ssa-sink.c (working copy) *************** statement_sink_location (gimple *stmt, b *** 256,263 **** *zero_uses_p = false; ! /* We only can sink assignments. */ ! if (!is_gimple_assign (stmt)) return false; /* We only can sink stmts with a single definition. */ --- 257,268 ---- *zero_uses_p = false; ! /* We only can sink assignments and non-looping const/pure calls. */ ! int cf; ! if (!is_gimple_assign (stmt) ! && (!is_gimple_call (stmt) ! || !((cf = gimple_call_flags (stmt)) & (ECF_CONST|ECF_PURE)) ! || (cf & ECF_LOOPING_CONST_OR_PURE))) return false; /* We only can sink stmts with a single definition. */ Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c =================================================================== *** gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c (nonexistent) --- gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c (working copy) *************** *** 0 **** --- 1,14 ---- + /* { dg-do compile } */ + /* Note PRE rotates the loop and blocks the sinking opportunity. */ + /* { dg-options "-O2 -fno-tree-pre -fdump-tree-sink -fdump-tree-optimized" } */ + + int f(int n) + { + int i,j=0; + for (i = 0; i < 31; i++) + j = __builtin_ffs(i); + return j; + } + + /* { dg-final { scan-tree-dump "Sinking j_. = __builtin_ffs" "sink" } } */ + /* { dg-final { scan-tree-dump "return 2;" "optimized" } } */