From patchwork Tue Sep 1 10:23:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sujoy Saraswati X-Patchwork-Id: 512761 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 49013140273 for ; Tue, 1 Sep 2015 20:23:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=C2Hh8ehO; 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 :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=JHcUdHJRmARdgPt1gFUoBLueq40uge4LsHqU/TmgmvSTUH 0O4fOPnGGDkg2tFIKlGqIsr3kQzJfhz0ALbOxJ9TD2+GJiqkX1VfTjV5G/QVrdNv pyOI93u5pKA9NOVemCIp6FzKjkQ4rtpEPWdgnIDi+zqWXbC6ivMy+4V6rYITY= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=3SOpPUJ5d9xEzhCtgWxWi92xDfQ=; b=C2Hh8ehOwEZPcQg9tPYp HkHatnt0GRejBVaSO/23SK+uRrbQ2jGKhYBAKVKHkV87o7DG79gxeD/Tx6FrZKxK 0KGKBXGOytZTuCsnoTFaohHpYxzPNUkq1bHi5k8jOLCQ5dyRtxrWEaWPbYdzDMne WloH3YwEUUuQTi5lo5UtU1Q= Received: (qmail 7264 invoked by alias); 1 Sep 2015 10:23:27 -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 7251 invoked by uid 89); 1 Sep 2015 10:23:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-la0-f54.google.com Received: from mail-la0-f54.google.com (HELO mail-la0-f54.google.com) (209.85.215.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 01 Sep 2015 10:23:25 +0000 Received: by labnh1 with SMTP id nh1so64315054lab.3 for ; Tue, 01 Sep 2015 03:23:22 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.152.9.37 with SMTP id w5mr12648781laa.43.1441103001888; Tue, 01 Sep 2015 03:23:21 -0700 (PDT) Received: by 10.25.24.71 with HTTP; Tue, 1 Sep 2015 03:23:21 -0700 (PDT) Date: Tue, 1 Sep 2015 15:53:21 +0530 Message-ID: Subject: Fix 61441 From: Sujoy Saraswati To: gcc-patches@gcc.gnu.org X-IsSubscribed: yes The following patch fixes 61441. It converts sNaN to qNaN on folding when -fno-signaling-nans is used. Bootstrap and regression tests on x86_64-linux-gnu and aarch64-unknown-linux-gnu passed with changes done on trunk. Is this fix fine ? Regards, Sujoy 2015-09-01 Sujoy Saraswati PR tree-optimization/61441 * tree-ssa-ccp.c (convert_snan_to_qnan): Convert sNaN to qNaN when flag_signaling_nans is off. (ccp_fold_stmt, visit_assignment, visit_cond_stmt): call convert_snan_to_qnan to convert sNaN to qNaN on constant folding. PR tree-optimization/61441 * gcc.dg/pr61441.c: New testcase. Index: gcc/tree-ssa-ccp.c =================================================================== --- gcc/tree-ssa-ccp.c (revision 226965) +++ gcc/tree-ssa-ccp.c (working copy) @@ -560,6 +560,24 @@ value_to_wide_int (ccp_prop_value_t val) return 0; } +/* Convert sNaN to qNaN when flag_signaling_nans is off */ + +static void +convert_snan_to_qnan (tree expr) +{ + if (expr + && (TREE_CODE (expr) == REAL_CST) + && !flag_signaling_nans) + { + REAL_VALUE_TYPE *d = TREE_REAL_CST_PTR (expr); + + if (HONOR_NANS (TYPE_MODE (TREE_TYPE (expr))) + && REAL_VALUE_ISNAN (*d) + && d->signalling) + d->signalling = 0; + } +} + /* Return the value for the address expression EXPR based on alignment information. */ @@ -2156,6 +2174,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) if (val.lattice_val != CONSTANT || val.mask != 0) return false; + convert_snan_to_qnan (val.value); if (dump_file) { @@ -2197,7 +2216,10 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) bool res; if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (new_rhs))) + { new_rhs = fold_convert (TREE_TYPE (lhs), new_rhs); + convert_snan_to_qnan (new_rhs); + } res = update_call_from_tree (gsi, new_rhs); gcc_assert (res); return true; @@ -2216,6 +2238,7 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) tree new_rhs = fold_builtin_alloca_with_align (stmt); if (new_rhs) { + convert_snan_to_qnan (new_rhs); bool res = update_call_from_tree (gsi, new_rhs); tree var = TREE_OPERAND (TREE_OPERAND (new_rhs, 0),0); gcc_assert (res); @@ -2260,7 +2283,10 @@ ccp_fold_stmt (gimple_stmt_iterator *gsi) { tree rhs = unshare_expr (val); if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs))) + { rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs); + convert_snan_to_qnan (rhs); + } gimple_assign_set_rhs_from_tree (gsi, rhs); return true; } @@ -2292,6 +2318,7 @@ visit_assignment (gimple stmt, tree *output_p) /* Evaluate the statement, which could be either a GIMPLE_ASSIGN or a GIMPLE_CALL. */ val = evaluate_stmt (stmt); + convert_snan_to_qnan (val.value); /* If STMT is an assignment to an SSA_NAME, we only have one value to set. */ @@ -2324,6 +2351,7 @@ visit_cond_stmt (gimple stmt, edge *taken_edge_p) if (val.lattice_val != CONSTANT || val.mask != 0) return SSA_PROP_VARYING; + convert_snan_to_qnan (val.value); /* Find which edge out of the conditional block will be taken and add it to the worklist. If no single edge can be determined statically, Index: gcc/testsuite/gcc.dg/pr61441.c =================================================================== --- gcc/testsuite/gcc.dg/pr61441.c (revision 0) +++ gcc/testsuite/gcc.dg/pr61441.c (working copy) @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-options "-O1 -lm" } */ + +#define _GNU_SOURCE +#include +#include + +int main (void) +{ + float sNaN = __builtin_nansf (""); + double x = (double) sNaN; + if (issignaling(x)) + { + __builtin_abort(); + } + return 0; +}