From patchwork Tue Jul 26 03:13:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 72765 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1459698qga; Mon, 25 Jul 2016 20:14:08 -0700 (PDT) X-Received: by 10.66.226.201 with SMTP id ru9mr35056148pac.55.1469502848482; Mon, 25 Jul 2016 20:14:08 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id rx5si23686474pab.143.2016.07.25.20.14.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jul 2016 20:14:08 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-432508-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-432508-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-432508-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=OhWPDG06QYI4zh81Iq9NZ+ir9MyUUnEm7PsUUILAE+uqWm8y4y NxKuRuQry3DYkl9JMtWQeLbssIsFsk30GqfV0AOvnRmKP9mB0J/rehyvY1gcC5TB x5n7rDtc8mGE5KkHfeHrQygY1JjmhcDn2e9g1MY+RgnEMrlgjdNLKtJwk= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=synYHxX6y9u92hYcKqiFWt42SyA=; b=eLIiGe3zyFVtBfXu5siO +1A8zyNHY74v+YX5oPQVNQupNqt1TX0m6meoibjuXHPgWpcpTxs4MhlMxbUkEuWk UReZmuLC2cfM0uYb5Bt18S3GB/mwjG3wY8cxKT3NDDgLUMU7F7XDWz+doIxP1u81 lfVhgbKCwNhvbHxvNArvTtg= Received: (qmail 53206 invoked by alias); 26 Jul 2016 03:13:53 -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 53170 invoked by uid 89); 26 Jul 2016 03:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=use_operand_p, 2016-07-26, 20160726 X-HELO: mail-pf0-f174.google.com Received: from mail-pf0-f174.google.com (HELO mail-pf0-f174.google.com) (209.85.192.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jul 2016 03:13:39 +0000 Received: by mail-pf0-f174.google.com with SMTP id y134so70343570pfg.0 for ; Mon, 25 Jul 2016 20:13:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version; bh=SFuB4FFnCIOWMvt5RWUr4F/nqfqzXmgctM1YuQJkwfI=; b=cphZ6KyPxRVTtleZsZnULC4Zk8zI7h3P5nZk64G4dEwttXv6hbtpO4QbfUS2izB2zy +i8ehq9hA7G056a1u7SykkgXpok+OGomofunor+wgT8n6Vz5wkmqO1WAvtkaveGgbtxv lBWVKMrQzUBZakyEpAe5sz7rgH18dPEue5TpC7/Bw193OuVKG2gLM95Y9npemAOclxo7 3IAHqzZqBgesQ8cpx0dKSmcN6b5uL9y02Z2NkHVX+0j2nWZua6CkY496jPpHeI3wBHHZ AL54rtfzYlbK4QLxVDQ2wtP6hDQadISaZMW1uOuWIdAVYDu1BpF7CfgDXfEZgmsiAIZo 7Msw== X-Gm-Message-State: AEkoous9zS7dH4MaGxWplfVib7DUuR3u2RLIpR9uIX1YSLw0efM2uMWXtwj0zERmcOV+fnxO X-Received: by 10.98.7.200 with SMTP id 69mr35398065pfh.33.1469502817352; Mon, 25 Jul 2016 20:13:37 -0700 (PDT) Received: from [10.1.1.4] (58-6-183-210.dyn.iinet.net.au. [58.6.183.210]) by smtp.gmail.com with ESMTPSA id h125sm43225706pfg.54.2016.07.25.20.13.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jul 2016 20:13:36 -0700 (PDT) To: "gcc-patches@gcc.gnu.org" Cc: Jeff Law , Richard Biener From: kugan Subject: [Bug tree-optimization] Fix for PR71994 Message-ID: Date: Tue, 26 Jul 2016 13:13:10 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, For testcase in pr71994, type of bb conditional result and the type of the PHI stmt are different (as om.0_1 is int and the first PHI argument is _bool; PHI stmt uses a constant zero that comes from edge 2). Therefore when we optimize final range test stmt, we end up setting integer 1 for other PHI argument. This results in ICE. : om.0_1 = om; _2 = om.0_1 >= 0; int _3 = (int) _2; if (om.0_1 != 0) goto ; else goto ; : int _4 = om.0_1 & _3; _Bool _12 = _4 != 0; : # _Bool _13 = PHI <0(2), _12(3)> IMHO, the fix should be that, we should check the type before replacing the value (punt otherwise). Attached patch does that. Bootstrapped and regression tested on x86_64-linux-gnu with no new regressions. Is this OK for trunk? Thanks, Kugan gcc/testsuite/ChangeLog: 2016-07-26 Kugan Vivekanandarajah * gcc.dg/torture/pr71994.c: New test. gcc/ChangeLog: 2016-07-26 Kugan Vivekanandarajah * tree-ssa-reassoc.c (maybe_optimize_range_tests): Check type compatibility. diff --git a/gcc/testsuite/gcc.dg/torture/pr71994.c b/gcc/testsuite/gcc.dg/torture/pr71994.c index e69de29..8f5e92c 100644 --- a/gcc/testsuite/gcc.dg/torture/pr71994.c +++ b/gcc/testsuite/gcc.dg/torture/pr71994.c @@ -0,0 +1,14 @@ +/* PR tree-optimization/71994 */ +/* { dg-do compile } */ +int om, h6; + +void eo (void) +{ + const int tl = 1; + int ln; + + h6 = (om + tl) > 0; + ln = om && (om & h6); + h6 = om; + om = ln < h6; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 18cf978..91d7f06 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3635,8 +3635,15 @@ maybe_optimize_range_tests (gimple *stmt) { gcc_assert (bb == last_bb); new_op = ops[bbinfo[idx].first_idx++]->op; + if (!types_compatible_p (TREE_TYPE (new_op), + TREE_TYPE (bbinfo[idx].op)) + && TREE_CODE (new_op) == INTEGER_CST) + new_op = fold_convert (TREE_TYPE (bbinfo[idx].op), + new_op); } - if (bbinfo[idx].op != new_op) + if (bbinfo[idx].op != new_op + && types_compatible_p (TREE_TYPE (new_op), + TREE_TYPE (bbinfo[idx].op))) { imm_use_iterator iter; use_operand_p use_p;