From patchwork Thu Jul 12 07:10:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 942822 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-481402-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jaQus7Z5"; 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 41R6Xp0C7Vz9ryt for ; Thu, 12 Jul 2018 17:10:49 +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:subject:message-id:mime-version:content-type; q=dns; s= default; b=nomTXPO0Ju+Aq4zCM5hZmXbuiDfRcPazXwdvolsyYIS06UoInHohL xqld39vZJdSCtzcCdPL1cR4bsJH5ZHLSNYZNGhgnoAunM6S41EHGHvBeEECoezLZ tVrZTT+L1nObi0+U8lmKXohVUr3ps5r62+KvfIzXk9MSkNDB0Yzlhc= 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:subject:message-id:mime-version:content-type; s= default; bh=+jk7GcUQBu/noyOKCcnNpUXE63U=; b=jaQus7Z5IRRP+kp1x0p5 vuDnEgLOEKX6ZgUylvXkVeDdEsLf7cU0rjxPeByJhM+UzEu3/ZzvrMZkY8BEbULL aAxgCkKE6zS/vg+zdghy6bFNqCLk/0LMKFGoevOzXCkb0NRBXaDVar2c2QmQEfR5 hmdDuASlkBeKUTtucRuUGMY= Received: (qmail 74425 invoked by alias); 12 Jul 2018 07:10:43 -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 74413 invoked by uid 89); 12 Jul 2018 07:10:42 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy= 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; Thu, 12 Jul 2018 07:10:41 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2DAD4AE22 for ; Thu, 12 Jul 2018 07:10:39 +0000 (UTC) Date: Thu, 12 Jul 2018 09:10:39 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR86479 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following fixes fold_binary_op_with_conditional_arg to not move a possibly trapping operation into the conditional arms because this breaks later re-gimplification and also because we lose information this way (like dividend is nonzero on the unconditional path). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. From d705c926cd25d7794df6d5759a3f94c307c30c8c Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Wed, 11 Jul 2018 12:37:58 +0200 Subject: [PATCH] fix-pr86479 2018-07-11 Richard Biener PR middle-end/86479 * fold-const.c (fold_binary_op_with_conditional_arg): Do not move possibly trapping operations into the conditional. * gcc.dg/graphite/pr86479.c: New testcase. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 97c435fa5e0..ac65dcfaf1d 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6587,6 +6587,13 @@ fold_binary_op_with_conditional_arg (location_t loc, tree rhs = NULL_TREE; enum tree_code cond_code = COND_EXPR; + /* Do not move possibly trapping operations into the conditional as this + pessimizes code and causes gimplification issues when applied late. */ + if (operation_could_trap_p (code, FLOAT_TYPE_P (type), + ANY_INTEGRAL_TYPE_P (type) + && TYPE_OVERFLOW_TRAPS (type), op1)) + return NULL_TREE; + if (TREE_CODE (cond) == COND_EXPR || TREE_CODE (cond) == VEC_COND_EXPR) { diff --git a/gcc/testsuite/gcc.dg/graphite/pr86479.c b/gcc/testsuite/gcc.dg/graphite/pr86479.c new file mode 100644 index 00000000000..7df63546c05 --- /dev/null +++ b/gcc/testsuite/gcc.dg/graphite/pr86479.c @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -floop-nest-optimize -fnon-call-exceptions -fno-guess-branch-probability -fno-tree-loop-im" } */ + +__INTPTR_TYPE__ uf; + +void +m7 (__INTPTR_TYPE__ *aw, __INTPTR_TYPE__ ws) +{ + __INTPTR_TYPE__ *e5 = &ws; + + if (ws < 1) + { + int cq = 0; + + while (cq < 1) + { + int *ng; + int *ud; + + *e5 *= uf < 0; + + for (*ng = 0; *ng < 2; ++*ng) + { + } + + ws /= cq; + *aw *= ws; + + for (*ud = 0; *ud < 2; ++*ud) + { + } + } + } + + if (ws < 2) + e5 = &uf; + + *e5 = 0; +}