From patchwork Fri Aug 3 15:59:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 953299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-483118-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="unwXMrt3"; dkim-atps=neutral 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 41hsDq0cK0z9s0n for ; Sat, 4 Aug 2018 01:59:38 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=C/Hsk5Zi+r9l+9zLyITXCzlLnLcb7 B3hZtIOpa4l7OcaPR96b7k537SkM8+D5d9NtUoQ3HIrgqtNQf4A2N/p+i3bQ3DQi 0zbx3lSPWcA8kxKaOZOyifxUiJCV7luXNdRpogww15tHK1/xwdOiDXgYbCurZZ0H R1jS+oxa98iXiE= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=NfR51dNIncvHhgSrBY+wkxZUtY0=; b=unw XMrt3PhpbDVBQWqZ56cQTchx6NfMhJJ35kANJX6Lbacql5AsVWfb4A7wzyq5OOjQ hLYTKXQGGguyEEcHpe+ErYC9bIQY+YOaaFGjUTcep+AkGrIjBiq6sZRujK95IrY/ IVw2Tt2Zw9TB16QquiQvL172Ob8TvSKQ4XuHX3iQ= Received: (qmail 75828 invoked by alias); 3 Aug 2018 15:59:30 -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 75815 invoked by uid 89); 3 Aug 2018 15:59:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sole X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Aug 2018 15:59:28 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B1A7430E6870 for ; Fri, 3 Aug 2018 15:59:27 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-71.ams2.redhat.com [10.36.117.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F8906FEFB; Fri, 3 Aug 2018 15:59:26 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w73FxPqS024783; Fri, 3 Aug 2018 17:59:25 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w73FxOgM023678; Fri, 3 Aug 2018 17:59:24 +0200 Date: Fri, 3 Aug 2018 17:59:24 +0200 From: Jakub Jelinek To: Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix thinko in insert_reciprocals (PR tree-optimization/86835) Message-ID: <20180803155924.GR17988@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! As the comment say, we want to insert (if should_insert_square_recip is true) new_square_stmt right after new_stmt. The current code does that correctly if new_stmt is inserted with gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT); because the following gsi_insert_before (&gsi, new_square_stmt, GSI_SAME_STMT); will keep inserting before whatever gsi points to. But one of the 3 cases inserts new_stmt instead after def_gsi, and the current gsi = *def_gsi; gsi_insert_after (def_gsi, new_stmt, GSI_NEW_STMT); gsi_insert_before (&gsi, new_square_stmt, GSI_SAME_STMT); certainly doesn't do that, it inserts new_stmt after the def_gsi stmt and then inserts new_square_stmt before the def_gsi stmt, so we have order of: new_square_stmt whatever-def_gsi-pointed-to-stmt new_stmt where new_square_stmt uses the lhs of new_stmt. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-08-03 Jakub Jelinek PR tree-optimization/86835 * tree-ssa-math-opts.c (insert_reciprocals): Even when inserting new_stmt after def_gsi, make sure to insert new_square_stmt after that stmt, not 2 stmts before it. * gcc.dg/pr86835.c: New test. Jakub --- gcc/tree-ssa-math-opts.c.jj 2018-07-12 21:31:27.698410833 +0200 +++ gcc/tree-ssa-math-opts.c 2018-08-03 12:58:27.475961037 +0200 @@ -422,6 +422,8 @@ insert_reciprocals (gimple_stmt_iterator gsi_next (&gsi); gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT); + if (should_insert_square_recip) + gsi_insert_before (&gsi, new_square_stmt, GSI_SAME_STMT); } else if (def_gsi && occ->bb == def_gsi->bb) { @@ -429,21 +431,19 @@ insert_reciprocals (gimple_stmt_iterator never happen if the definition statement can throw, because in that case the sole successor of the statement's basic block will dominate all the uses as well. */ - gsi = *def_gsi; gsi_insert_after (def_gsi, new_stmt, GSI_NEW_STMT); + if (should_insert_square_recip) + gsi_insert_after (def_gsi, new_square_stmt, GSI_NEW_STMT); } else { /* Case 3: insert in a basic block not containing defs/uses. */ gsi = gsi_after_labels (occ->bb); gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT); + if (should_insert_square_recip) + gsi_insert_before (&gsi, new_square_stmt, GSI_SAME_STMT); } - /* Regardless of which case the reciprocal as inserted in, - we insert the square immediately after the reciprocal. */ - if (should_insert_square_recip) - gsi_insert_before (&gsi, new_square_stmt, GSI_SAME_STMT); - reciprocal_stats.rdivs_inserted++; occ->recip_def_stmt = new_stmt; --- gcc/testsuite/gcc.dg/pr86835.c.jj 2018-08-03 13:07:28.834159126 +0200 +++ gcc/testsuite/gcc.dg/pr86835.c 2018-08-03 13:07:14.119126559 +0200 @@ -0,0 +1,29 @@ +/* PR tree-optimization/86835 */ +/* { dg-do run } */ +/* { dg-options "-O2 -ffast-math -Wuninitialized" } */ + +__attribute__((noipa)) void +foo (int n, double *x, double *y) +{ /* { dg-bogus "is used uninitialized in this function" "" { target *-*-* } 0 } */ + int i; + double b = y[4]; + for (i = 0; i < n; ++i) + y[3] += __builtin_sin (x[i] / b); + y[0] /= b; + y[1] /= b * b; + y[2] /= b; +} + +int +main () +{ + double y[] = { 16.0, 64.0, 128.0, 0.0, 2.0 }; + foo (0, y, y); + if (__builtin_fabs (y[0] - 8.0) > 0.0001 + || __builtin_fabs (y[1] - 16.0) > 0.0001 + || __builtin_fabs (y[2] - 64.0) > 0.0001 + || y[3] != 0.0 + || y[4] != 2.0) + __builtin_abort (); + return 0; +}