From patchwork Wed Aug 25 17:01:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 62725 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]) by ozlabs.org (Postfix) with SMTP id 2F890B6F14 for ; Thu, 26 Aug 2010 03:01:34 +1000 (EST) Received: (qmail 26306 invoked by alias); 25 Aug 2010 17:01:28 -0000 Received: (qmail 25975 invoked by uid 22791); 25 Aug 2010 17:01:23 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Aug 2010 17:01:17 +0000 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7PH1F7r001444 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Aug 2010 13:01:15 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7PH1EWU003261 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 25 Aug 2010 13:01:15 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o7PH1wFU031112 for ; Wed, 25 Aug 2010 19:01:58 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7PH1vpN031111 for gcc-patches@gcc.gnu.org; Wed, 25 Aug 2010 19:01:57 +0200 Date: Wed, 25 Aug 2010 19:01:57 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Don't optimize through mode class changing subregs in simplify_shift_const_1 (PR rtl-optimization/45400) Message-ID: <20100825170157.GW702@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes 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 Hi! On this testcase, simplify_shift_const_1 is called on LSHIFTRT 24 (subreg:SI (ashift:V4HI (reg:V4HI ...) (const_int 16)) varop and happily first optimizes this into AND 255 on the reg:V4HI and then crashes soon afterwards. IMHO the only case when we should look through low part subregs is when both modes are MODE_INT, when crossing mode class boundary it will be wrong (e.g. vector mode shift is something completely Jakub different from integral shift) and even when changing vector mode size, or doing subreg between different floating point modes etc. isn't going to work very well. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux. Ok for trunk/4.5? 2010-08-25 Jakub Jelinek PR rtl-optimization/45400 * combine.c (simplify_shift_const_1) : Only use SUBREG_REG if both modes are of MODE_INT class. * g++.dg/other/i386-8.C: New test. --- gcc/combine.c.jj 2010-08-12 11:12:13.000000000 +0200 +++ gcc/combine.c 2010-08-25 11:10:01.694939344 +0200 @@ -9505,7 +9505,9 @@ simplify_shift_const_1 (enum rtx_code co > GET_MODE_SIZE (GET_MODE (varop))) && (unsigned int) ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (varop))) + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD) - == mode_words) + == mode_words + && GET_MODE_CLASS (GET_MODE (varop)) == MODE_INT + && GET_MODE_CLASS (GET_MODE (SUBREG_REG (varop))) == MODE_INT) { varop = SUBREG_REG (varop); if (GET_MODE_SIZE (GET_MODE (varop)) > GET_MODE_SIZE (mode)) --- gcc/testsuite/g++.dg/other/i386-8.C.jj 2010-08-25 11:19:54.799157615 +0200 +++ gcc/testsuite/g++.dg/other/i386-8.C 2010-08-25 11:21:20.688108083 +0200 @@ -0,0 +1,23 @@ +// PR rtl-optimization/45400 +// { dg-do compile { target i?86-*-* x86_64-*-* } } +// { dg-options "-O2 -msse2" } +// { dg-options "-O2 -msse2 -fpic" { target fpic } } +// { dg-require-effective-target sse2 } + +#include + +static inline unsigned short +bar (unsigned short x) +{ + return ((x << 8) | (x >> 8)); +} + +unsigned int +foo (float *x, short *y) +{ + __m128 a = _mm_set_ps1 (32767.5f); + __m128 b = _mm_mul_ps (_mm_load_ps (x), a); + __m64 c = _mm_cvtps_pi16 (b); + __builtin_memcpy (y, &c, sizeof (short) * 4); + y[0] = bar (y[0]); +}