From patchwork Fri Apr 1 04:54:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Segher Boessenkool X-Patchwork-Id: 604597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qbpw451lvz9s5J for ; Fri, 1 Apr 2016 15:54:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=XjcV/QmC; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=p5/LAg8g6Nzy CV/X2BgIhY+3YNF+Z1hZX+mbuyFOoSd0cKQPnqopJGFTiNsRXua0jrbu8QtuTY+p LZFf8Bc5kjH8Ll/lOism4ExKZm98HhCBzRrBSUFKcwjaKaU7t2e2TYrAgOG/bo6V mErfFhLPZfPHJGpKls4bJSdiETC3NuY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=pXh7pxtVUQYMi9tN9e tXdcnkq7c=; b=XjcV/QmC+uUvzUhXRcQokES7BSUPVqWa7QljSvhJzN7vs2HUqj 5icuAT0iKAHQl3jIJdp/ixS7JExR3JsoM/TZ8gNBP8sD5V5tyIYY52Pl6dhLG7zi OcF+ppuVSAd0EBhvs15b0s04NMWXCglrxXjzN0xbmkgBN9Tq9+xxJ7ssM= Received: (qmail 63252 invoked by alias); 1 Apr 2016 04:54:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 63242 invoked by uid 89); 1 Apr 2016 04:54:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL, BAYES_20, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=2016-04-01, U*segher, 916, D*kernel.crashing.org X-HELO: gcc1-power7.osuosl.org Received: from gcc1-power7.osuosl.org (HELO gcc1-power7.osuosl.org) (140.211.15.137) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Apr 2016 04:54:40 +0000 Received: by gcc1-power7.osuosl.org (Postfix, from userid 10019) id 582551C0677; Fri, 1 Apr 2016 04:54:35 +0000 (UTC) From: Segher Boessenkool To: gcc-patches@gcc.gnu.org Cc: Segher Boessenkool Subject: [PATCH] Prevent loops from being optimized away Date: Fri, 1 Apr 2016 04:54:30 +0000 Message-Id: <9fc51a58cc354a934ff5a5e2b232dae520090e2b.1459485314.git.segher@kernel.crashing.org> X-IsSubscribed: yes Sometimes people write loops that they do not want optimized away, even when the compiler can replace those loops by a simple expression (or nothing). For such people, this patch adds a compiler option. Bootstrapped on powerpc64-linux; regression check still in progress (with Init(1) to actually test anything). Segher 2016-04-01 Segher Boessenkool * loop-init.c: Include some more stuff that really doesn't belong here, oh well. (loop_optimizer_init): Add empty asm statements in all gimple loops, if asked to. * common.opt: Add new option. --- gcc/common.opt | 4 ++++ gcc/loop-init.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/loop-init.c b/gcc/loop-init.c index 8634591..7c5dc24 100644 --- a/gcc/loop-init.c +++ b/gcc/loop-init.c @@ -24,6 +24,8 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "rtl.h" #include "tree.h" +#include "gimple.h" +#include "gimple-iterator.h" #include "cfghooks.h" #include "df.h" #include "regs.h" @@ -91,6 +93,19 @@ loop_optimizer_init (unsigned flags) /* Find the loops. */ current_loops = flow_loops_find (NULL); + + if (flag_never_gonna_give_you_up && current_ir_type () == IR_GIMPLE) + { + struct loop *loop; + FOR_EACH_LOOP (loop, 0) + if (loop->latch) + { + gasm *p = gimple_build_asm_vec ("", 0, 0, 0, 0); + gimple_asm_set_volatile (p, true); + gimple_stmt_iterator bsi = gsi_after_labels (loop->latch); + gsi_insert_before (&bsi, p, GSI_SAME_STMT); + } + } } else { diff --git a/gcc/common.opt b/gcc/common.opt index 0f3bb4e..b7c0a6a 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -2002,6 +2002,10 @@ frerun-loop-opt Common Ignore Does nothing. Preserved for backward compatibility. +frickroll-all-loops +Common Report Var(flag_never_gonna_give_you_up) Init(0) Optimization +You know the rules, and so do I. + frounding-math Common Report Var(flag_rounding_math) Optimization SetByCombined Disable optimizations that assume default FP rounding behavior.