From patchwork Fri Mar 30 13:38:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 149652 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 4D569B6EF4 for ; Sat, 31 Mar 2012 00:38:34 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1333719515; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Date: From:To:Subject:Message-ID:MIME-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=NJEOzQxXz6Ow4xn0xjUF 969vyEU=; b=Pu+p30Zskx3MGh3AWpIGl90crBJ8h36qrCMtrYlxuAyywPRRiIhS RTEeS+7ZWvvuQQ2e+V9MaoBCuMXw2SfbnAIqWKZ0tuIozOmXNPrpkvGhVf/417R0 tw8rwoyvQyVfk3YccYrzyl52KBPFu9SeRnn+w+bZdU3tVE5RlcCX+eA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=DT5wPZUxurKs2F4WNIDUQE7TomeE80fmIPUX/EjG/4CwISa8NyQigUymSTZxrF msd7BG+EWahlHJ/4EF+92d0Rq9zTYfySdKokLWqRZsgSNRS7iXLGHKbkfEvgQUrU jLmtYewrJJ5Z91HuR3KzIeM2ah6Ra1NMxV/OEOeLVhHMw=; Received: (qmail 6887 invoked by alias); 30 Mar 2012 13:38:27 -0000 Received: (qmail 6698 invoked by uid 22791); 30 Mar 2012 13:38:25 -0000 X-SWARE-Spam-Status: No, hits=-5.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 30 Mar 2012 13:38:02 +0000 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 3B7AE8BB22 for ; Fri, 30 Mar 2012 15:38:01 +0200 (CEST) Date: Fri, 30 Mar 2012 15:38:01 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR52754 Message-ID: MIME-Version: 1.0 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 This fixes another case of bogusly reconstructed array references. The symptom is that predictive commoning creates negative array indices (and in a wrong way, too). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2012-03-30 Richard Guenther PR tree-optimization/52754 * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Only propagate arbitrary addresses into really plain dereferences. * gcc.target/i386/pr52754.c: New testcase. Index: gcc/tree-ssa-forwprop.c =================================================================== --- gcc/tree-ssa-forwprop.c (revision 185999) +++ gcc/tree-ssa-forwprop.c (working copy) @@ -905,6 +905,7 @@ forward_propagate_addr_expr_1 (tree name that of the pointed-to type of the address we can put the dereferenced address on the LHS preserving the original alias-type. */ else if (gimple_assign_lhs (use_stmt) == lhs + && integer_zerop (TREE_OPERAND (lhs, 1)) && useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (def_rhs, 0)), TREE_TYPE (gimple_assign_rhs1 (use_stmt)))) @@ -917,9 +918,8 @@ forward_propagate_addr_expr_1 (tree name if (TREE_CODE (*def_rhs_basep) == MEM_REF) { new_base = TREE_OPERAND (*def_rhs_basep, 0); - new_offset - = int_const_binop (PLUS_EXPR, TREE_OPERAND (lhs, 1), - TREE_OPERAND (*def_rhs_basep, 1)); + new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (lhs, 1)), + TREE_OPERAND (*def_rhs_basep, 1)); } else { @@ -989,6 +989,7 @@ forward_propagate_addr_expr_1 (tree name that of the pointed-to type of the address we can put the dereferenced address on the RHS preserving the original alias-type. */ else if (gimple_assign_rhs1 (use_stmt) == rhs + && integer_zerop (TREE_OPERAND (rhs, 1)) && useless_type_conversion_p (TREE_TYPE (gimple_assign_lhs (use_stmt)), TREE_TYPE (TREE_OPERAND (def_rhs, 0)))) @@ -1001,9 +1002,8 @@ forward_propagate_addr_expr_1 (tree name if (TREE_CODE (*def_rhs_basep) == MEM_REF) { new_base = TREE_OPERAND (*def_rhs_basep, 0); - new_offset - = int_const_binop (PLUS_EXPR, TREE_OPERAND (rhs, 1), - TREE_OPERAND (*def_rhs_basep, 1)); + new_offset = fold_convert (TREE_TYPE (TREE_OPERAND (rhs, 1)), + TREE_OPERAND (*def_rhs_basep, 1)); } else { Index: gcc/testsuite/gcc.target/i386/pr52754.c =================================================================== --- gcc/testsuite/gcc.target/i386/pr52754.c (revision 0) +++ gcc/testsuite/gcc.target/i386/pr52754.c (revision 0) @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -fpredictive-commoning -msse2 -std=c99" } */ +/* { dg-require-effective-target sse2 } */ + +#include + +#include "isa-check.h" +#include "sse-os-support.h" + +int main() +{ + const float mem[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; + + unsigned int indexes[8]; + for (unsigned int i = 0; i < 8; ++i) indexes[i] = i; + + check_isa (); + + if (!sse_os_support ()) + exit (0); + + __m128 x = _mm_setr_ps(0, 1, 2, 3); + for (unsigned int i = 0; i + 4 < 6; ++i) { + const unsigned int *ii = &indexes[i]; + const __m128 tmp = _mm_setr_ps(mem[ii[0]], mem[ii[1]], mem[ii[2]], mem[ii[3]]); + if (0xf != _mm_movemask_ps(_mm_cmpeq_ps(tmp, x))) { + __builtin_abort(); + } + x = _mm_add_ps(x, _mm_set1_ps(1)); + } + + return 0; +}