From patchwork Mon Aug 10 21:27:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 505794 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 E2CB11402BC for ; Tue, 11 Aug 2015 07:27:28 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=kgqnf4LP; 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:to :from:subject:cc:message-id:date:mime-version:content-type; q= dns; s=default; b=TG/YO9BnjCmcHVcQlnCj+Bbc48tAZfiTmrPQaOgtgFSkm7 1WOejSrAo9e4iy5oWnDj7Fo+aTy38V/np/zkGR/GUGHfjgEs3Mw59i+ODV/gVmmZ bBKgihfNQtfp2tGA7XSXF/Zj7GKWbzljgiVoTMKlNrKb9ov+mTVK5A+hVT4/4= 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:to :from:subject:cc:message-id:date:mime-version:content-type; s= default; bh=CR+QH/voOSrhg3G2nvZqaH2mJ5s=; b=kgqnf4LPMkFyfxXdWWYP jkikOtb5NNpqw5krWAmWMZyM53bGU4t0Ig0vyTStc5xsMigU4np7FJdgLB5N0ND/ q978ho4cnNRPt2QB3SjTWDDqvOB7ZN7am8eIzN1hRpPauqyzlaecuDchADGBi0mD BsrPCpBD4/wP1zQ5Uq3o2Ig= Received: (qmail 67774 invoked by alias); 10 Aug 2015 21:27:22 -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 67765 invoked by uid 89); 10 Aug 2015 21:27:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f42.google.com Received: from mail-qg0-f42.google.com (HELO mail-qg0-f42.google.com) (209.85.192.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 10 Aug 2015 21:27:20 +0000 Received: by qgdd90 with SMTP id d90so26404193qgd.3 for ; Mon, 10 Aug 2015 14:27:18 -0700 (PDT) X-Received: by 10.140.85.42 with SMTP id m39mr41255258qgd.27.1439242038160; Mon, 10 Aug 2015 14:27:18 -0700 (PDT) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id 47sm10583245qgt.15.2015.08.10.14.27.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Aug 2015 14:27:17 -0700 (PDT) To: Richard Guenther From: Nathan Sidwell Subject: [optimize 1/3] Fix phi to min/max Cc: GCC Patches Message-ID: <55C91734.4010602@acm.org> Date: Mon, 10 Aug 2015 17:27:16 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Richard, This patch fixes the problem I described earlier about min/max generation propagating incorrect range information (https://gcc.gnu.org/ml/gcc/2015-08/msg00024.html). I went with creating a new name, if the PHI being modified has more than 2 edges. I also modified the testcase that my min/max vrp patch tickled -- it wasn't calling an init function and hence copying zeroes rather than the small values it thought it was copying. Also added a new test to convert zeroes, which was the failure mode I observed in the DFP lib. This patch was tested in combination with the new min max optimization I'll post momentarily. ok? nathan 2015-08-10 Nathan Sidwell * tree-ssa-phiopt.c (minmax_replacement): Create new ssa name if we're not the only contributor to target phi. testsuite/ * c-c++-common/dfp/operator-comma.c: Call init function. * c-c++-common/dfp/convert-dfp-2.c: New test. Index: tree-ssa-phiopt.c =================================================================== --- tree-ssa-phiopt.c (revision 226749) +++ tree-ssa-phiopt.c (working copy) @@ -1277,8 +1277,16 @@ minmax_replacement (basic_block cond_bb, gsi_move_before (&gsi_from, &gsi); } + /* Create an SSA var to hold the min/max result. If we're the only + things setting the target PHI, then we can clone the PHI + variable. Otherwise we must create a new one. */ + result = PHI_RESULT (phi); + if (EDGE_COUNT (gimple_bb (phi)->preds) == 2) + result = duplicate_ssa_name (result, NULL); + else + result = make_ssa_name (TREE_TYPE (result)); + /* Emit the statement to compute min/max. */ - result = duplicate_ssa_name (PHI_RESULT (phi), NULL); new_stmt = gimple_build_assign (result, minmax, arg0, arg1); gsi = gsi_last_bb (cond_bb); gsi_insert_before (&gsi, new_stmt, GSI_NEW_STMT); Index: testsuite/c-c++-common/dfp/convert-dfp-2.c =================================================================== --- testsuite/c-c++-common/dfp/convert-dfp-2.c (revision 0) +++ testsuite/c-c++-common/dfp/convert-dfp-2.c (working copy) @@ -0,0 +1,45 @@ +/* { dg-options "-O0" } */ + +/* Test decimal fp conversions of zero. */ + +#include "dfp-dbg.h" + +volatile _Decimal32 d32a, d32c; +volatile _Decimal64 d64a, d64c; +volatile _Decimal128 d128a, d128c; + +int +main () +{ + d32a = d32c; + if (d32a) + FAILURE + d32a = d64c; + if (d32a) + FAILURE + d32a = d128c; + if (d32a) + FAILURE + + d64a = d32c; + if (d64a) + FAILURE + d64a = d64c; + if (d64a) + FAILURE + d64a = d128c; + if (d64a) + FAILURE + + d128a = d32c; + if (d128a) + FAILURE + d128a = d64c; + if (d128a) + FAILURE + d128a = d128c; + if (d128a) + FAILURE + + FINISH +} Index: testsuite/c-c++-common/dfp/operator-comma.c =================================================================== --- testsuite/c-c++-common/dfp/operator-comma.c (revision 226749) +++ testsuite/c-c++-common/dfp/operator-comma.c (working copy) @@ -24,6 +24,8 @@ init () int main () { + init (); + d32a = (d32b, d32c); if (d32a != d32c) FAILURE