From patchwork Tue Nov 5 13:09:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 288509 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 85B8E2C0097 for ; Wed, 6 Nov 2013 00:10:19 +1100 (EST) 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:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=iKjcsFUTkKcUpONsNdXkLaXZ1JIBJ 4s5lmRFa0QAof4DoDp9+Z3DeE9bQO1cG4BRpemiuwtjV5R4vtcE55/wBaF47GCX+ fyOsaw1FpiMqhjNO8LFtTprr4LEnYiKdYXxtw0uI3/F02OCpPoLSt7zHXCpfueA2 0gG51jKCoBNAN8= 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:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=mnfxA2TyuloXMvkNBuXBOG9O5Hs=; b=F8q CnbgEVYA4wy8+MNujf6xO8Grvl/HU0RomlaVEMRnqumSi3kGQEK3uMD4YpM1WQwp sskzpOttmiLG4AtyzLNdZP/v68w6A3L5nlNw2M8Yr9w03zGvY68UM5/vgmgbPokN nST+0/OTe40bzNfhNyf3e+WIffWHJsDF6BFMxJdM= Received: (qmail 11778 invoked by alias); 5 Nov 2013 13:10:08 -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 11757 invoked by uid 89); 5 Nov 2013 13:10:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Nov 2013 13:10:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA5D9w8d028200 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Nov 2013 08:09:58 -0500 Received: from tucnak.zalov.cz (vpn1-7-123.ams2.redhat.com [10.36.7.123]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rA5D9uKZ018506 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 5 Nov 2013 08:09:57 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id rA5D9t5l010595; Tue, 5 Nov 2013 14:09:55 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id rA5D9tWD010594; Tue, 5 Nov 2013 14:09:55 +0100 Date: Tue, 5 Nov 2013 14:09:55 +0100 From: Jakub Jelinek To: Richard Biener , Zdenek Dvorak , Jan Hubicka Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] loop-{iv,unswitch}.c fixes (PR rtl-optimization/58997) Message-ID: <20131105130955.GM27813@tucnak.zalov.cz> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! Apparently, for iv->extend == IV_UNKNOWN_EXTEND if iv->mode != iv->extend_mode get_iv_value returns a value in iv->mode mode, while otherwise in iv->extend_mode. This makes some sense, because with IV_UNKNOWN_EXTEND the upper bits are unknown, so there is nothing reasonable to return in the extended mode. But e.g. iv_subreg when it calls assumed unconditionally the value would be in iv->extend_mode (the reason for the ICE on the attached testcase). Furthermore, for iv_extend, IMHO if iv->extend isn't IV_UNKNOWN_EXTEND, but is different from the new extend, the middle bits might be incorrect. And, lastly, I think may_unswitch_on assumes the returned values will be in the expected mode (iv->mode), but they can be wider and that can result in invalid RTL (say comparing of SImode with DImode rtl), or wrong code. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk and for 4.8 later? 2013-11-05 Jakub Jelinek PR rtl-optimization/58997 * loop-iv.c (iv_subreg): For IV_UNKNOWN_EXTEND, expect get_iv_value to be in iv->mode rather than iv->extend_mode. (iv_extend): Likewise. Otherwise, if iv->extend != extend, use lowpart_subreg on get_iv_value before calling simplify_gen_unary. * loop-unswitch.c (may_unswitch_on): Make sure op[i] is in the right mode. * gcc.c-torture/compile/pr58997.c: New test. Jakub --- gcc/loop-iv.c.jj 2013-10-17 22:30:56.000000000 +0200 +++ gcc/loop-iv.c 2013-11-05 10:10:31.685719102 +0100 @@ -436,7 +436,9 @@ iv_subreg (struct rtx_iv *iv, enum machi && !iv->first_special) { rtx val = get_iv_value (iv, const0_rtx); - val = lowpart_subreg (mode, val, iv->extend_mode); + val = lowpart_subreg (mode, val, + iv->extend == IV_UNKNOWN_EXTEND + ? iv->mode : iv->extend_mode); iv->base = val; iv->extend = IV_UNKNOWN_EXTEND; @@ -476,8 +478,14 @@ iv_extend (struct rtx_iv *iv, enum iv_ex && !iv->first_special) { rtx val = get_iv_value (iv, const0_rtx); + if (iv->extend_mode != iv->mode + && iv->extend != IV_UNKNOWN_EXTEND + && iv->extend != extend) + val = lowpart_subreg (iv->mode, val, iv->extend_mode); val = simplify_gen_unary (iv_extend_to_rtx_code (extend), mode, - val, iv->extend_mode); + val, + iv->extend == extend + ? iv->extend_mode : iv->mode); iv->base = val; iv->extend = IV_UNKNOWN_EXTEND; iv->mode = iv->extend_mode = mode; --- gcc/loop-unswitch.c.jj 2013-10-17 22:30:41.780251692 +0200 +++ gcc/loop-unswitch.c 2013-11-05 10:28:57.172719881 +0100 @@ -191,6 +191,7 @@ may_unswitch_on (basic_block bb, struct if (!test) return NULL_RTX; + mode = VOIDmode; for (i = 0; i < 2; i++) { op[i] = XEXP (test, i); @@ -205,11 +206,15 @@ may_unswitch_on (basic_block bb, struct return NULL_RTX; op[i] = get_iv_value (&iv, const0_rtx); + if (iv.extend != IV_UNKNOWN_EXTEND + && iv.mode != iv.extend_mode) + op[i] = lowpart_subreg (iv.mode, op[i], iv.extend_mode); + if (mode == VOIDmode) + mode = iv.mode; + else + gcc_assert (mode == iv.mode); } - mode = GET_MODE (op[0]); - if (mode == VOIDmode) - mode = GET_MODE (op[1]); if (GET_MODE_CLASS (mode) == MODE_CC) { if (at != BB_END (bb)) --- gcc/testsuite/gcc.c-torture/compile/pr58997.c.jj 2013-11-05 10:26:30.802517924 +0100 +++ gcc/testsuite/gcc.c-torture/compile/pr58997.c 2013-11-05 10:26:15.000000000 +0100 @@ -0,0 +1,19 @@ +/* PR rtl-optimization/58997 */ + +int a, b, c, e; +short d; +char h; + +void +foo () +{ + while (b) + { + d = a ? c : 1 % a; + c = d; + h = d; + if (!h) + while (e) + ; + } +}