From patchwork Tue Jul 26 12:34:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kugan Vivekanandarajah X-Patchwork-Id: 652759 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 3rzHcx5r6hz9t18 for ; Tue, 26 Jul 2016 22:34:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=b53ho3Rk; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=VFBQitcgnkznLmNZF OkLcLwTLA1H8QuW9VkISOOBKnbi/jaRIOaNk4FM1U/nWkHUMRtmoC0tsPo3hfmTY X9Kbcx7piUQQRQyn6pFo17deLCwwcn0v6WTQzlJEyA8Tz8+T/vPGhciCllXVrmOt NeHFgHnRKLevMGB7nHgSRWARMQ= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=OGyDlQbiA5jHEvLzxikenyV jxkk=; b=b53ho3RkdFkd3MxDGQ9VNVwnbAdz8hvF/pPGwiWSXgjY8a/Zs0/1zbN YGiAToFjvELwcQlTx13VJDpqknS7t3B5ImwbIyLU4Pjkv5KM9GHjwj05P4WM6wKq 7OP36QmGJWOhZwTg9ToviO64b4IMAHucXBphyhD3gdhc2IL36Hs8= Received: (qmail 93085 invoked by alias); 26 Jul 2016 12:34:33 -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 93056 invoked by uid 89); 26 Jul 2016 12:34:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2528, 2016-07-26 X-HELO: mail-pa0-f48.google.com Received: from mail-pa0-f48.google.com (HELO mail-pa0-f48.google.com) (209.85.220.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 26 Jul 2016 12:34:22 +0000 Received: by mail-pa0-f48.google.com with SMTP id fi15so71916563pac.1 for ; Tue, 26 Jul 2016 05:34:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=Nwu39NiyLcHlw0CYRghrOOnf85g8ae+eu+XMyRIovEk=; b=HCE4TXYwvT6x9p+GjLC8ityt9iLMTLlH5KM6s5hdMjvLMQ36XH/YK7HQzRXkwIuFIh oM6Xro2hGGwyBLmHhdtav6bbPH1uexR1ojNa1xHzLXL7QNKEeaGlnwXcnJFTVHijNecs ivGxJWtjEG8IRT07kRbIZ7oQOTVa/2uTJQ3E0fz2JOUoj1L5eGxA/Nm15/gpk0XKekjr eiKpxNijt68sK3vTO0eyibiZPx48BgvG0coqNpk60IpLObJKnmAf6lzQdCtPdJnx3YYY CO7/PdEsl3y9yx7Xekjhlhd7AZf/Fyg19NP12Ym9uByO8jvpGc/flGMohKZVn1+Lycgd zqfQ== X-Gm-Message-State: AEkoouvbXA/XyPAt25IyzWuq40sVxwxu62FGE47RycvO28t1mSZ4lR98HJBGSkiBlv06gjmj X-Received: by 10.66.127.10 with SMTP id nc10mr38716016pab.109.1469536460345; Tue, 26 Jul 2016 05:34:20 -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 x126sm1374668pfx.61.2016.07.26.05.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jul 2016 05:34:19 -0700 (PDT) Subject: Re: [Bug tree-optimization] Fix for PR71994 To: Richard Biener References: Cc: "gcc-patches@gcc.gnu.org" , Jeff Law From: kugan Message-ID: <0bf1d171-3ff8-3be5-ba84-63d6d69b5c4f@linaro.org> Date: Tue, 26 Jul 2016 22:34:15 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes Hi Richard, On 26/07/16 21:48, Richard Biener wrote: > On Tue, Jul 26, 2016 at 5:13 AM, kugan > wrote: >> 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? > > Ugh, this is undocumented spaghetti code I am not familiar with. I > can't see if it > is safe to truncate a constant here so I'd feel safer to just punt instead. > Please see the attached patch, which now constant truncation. Testing in progress. Is this OK for trunk if there is no new regressions? 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..21742dd 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -3636,7 +3636,9 @@ maybe_optimize_range_tests (gimple *stmt) gcc_assert (bb == last_bb); new_op = ops[bbinfo[idx].first_idx++]->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;