From patchwork Thu Nov 1 21:10:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 196381 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 EAEFB2C0093 for ; Fri, 2 Nov 2012 08:10:53 +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=1352409054; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Subject:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=KNI17iz ba4tK13HRYb8SrZWPGRI=; b=yNQU7l5EDTM9U6SsJTiO+ELsLOewUIS3msxDtl+ /2JurX68mVcPafhWA9YIWEyhKGl/Cb82Z9CFYtbmnkELixd/BH3x6B+rqwNKtMxT LDnKsyqJmFPvDAEyGjvNbXDn4EYt+ohXsmwQgntYWeswuHt/8rEePZhFfZSTSGub d7RI= 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:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=AMHgwv3+EXEhCv78sfaZpWs7xkxrGhRVGHugdouEkFiMVnIM6neyFZlWc3RS21 mnLo2sIpGfXEfhhq9k5x1El9EPahC/VjTrXeQpbfP1K5ZisUtc8iTxfmvxy8LePh Y5JOUkzbMKsGqSwwMEQ5M4HErn48HF8NZ45jX8ld+7MkQ=; Received: (qmail 5149 invoked by alias); 1 Nov 2012 21:10:46 -0000 Received: (qmail 5141 invoked by uid 22791); 1 Nov 2012 21:10:45 -0000 X-SWARE-Spam-Status: No, hits=-7.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail1-relais-roc.national.inria.fr (HELO mail1-relais-roc.national.inria.fr) (192.134.164.82) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Nov 2012 21:10:40 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail1-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 01 Nov 2012 22:10:38 +0100 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1TU229-0008Hl-QW for gcc-patches@gcc.gnu.org; Thu, 01 Nov 2012 22:10:37 +0100 Date: Thu, 1 Nov 2012 22:10:37 +0100 (CET) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Tighten checking of vector comparisons Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) 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 Hello, this patch makes gimple checking of vector comparisons more strict by ensuring that it doesn't return a boolean. It also fixes a bug that this check detected in fold-const.c: for (void)(x<0), the C front-end was calling fold_unary_loc on the conversion to void, which was then converted to if(x<0)(void)0. 2012-11-02 Marc Glisse * tree-cfg.c (verify_gimple_comparison): Verify that vector comparison returns a vector. * fold-const.c (fold_unary_loc): Disable conversion optimization for void type. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 193060) +++ gcc/fold-const.c (working copy) @@ -7742,21 +7742,22 @@ fold_unary_loc (location_t loc, enum tre /* If we have (type) (a CMP b) and type is an integral type, return new expression involving the new type. Canonicalize (type) (a CMP b) to (a CMP b) ? (type) true : (type) false for non-integral type. Do not fold the result as that would not simplify further, also folding again results in recursions. */ if (TREE_CODE (type) == BOOLEAN_TYPE) return build2_loc (loc, TREE_CODE (op0), type, TREE_OPERAND (op0, 0), TREE_OPERAND (op0, 1)); - else if (!INTEGRAL_TYPE_P (type) && TREE_CODE (type) != VECTOR_TYPE) + else if (!INTEGRAL_TYPE_P (type) && !VOID_TYPE_P (type) + && TREE_CODE (type) != VECTOR_TYPE) return build3_loc (loc, COND_EXPR, type, op0, constant_boolean_node (true, type), constant_boolean_node (false, type)); } /* Handle cases of two conversions in a row. */ if (CONVERT_EXPR_P (op0)) { tree inside_type = TREE_TYPE (TREE_OPERAND (op0, 0)); tree inter_type = TREE_TYPE (op0); Index: gcc/tree-cfg.c =================================================================== --- gcc/tree-cfg.c (revision 193060) +++ gcc/tree-cfg.c (working copy) @@ -3263,21 +3263,30 @@ verify_gimple_comparison (tree type, tre error ("mismatching comparison operand types"); debug_generic_expr (op0_type); debug_generic_expr (op1_type); return true; } /* The resulting type of a comparison may be an effective boolean type. */ if (INTEGRAL_TYPE_P (type) && (TREE_CODE (type) == BOOLEAN_TYPE || TYPE_PRECISION (type) == 1)) - ; + { + if (TREE_CODE (op0_type) == VECTOR_TYPE + || TREE_CODE (op1_type) == VECTOR_TYPE) + { + error ("vector comparison returning a boolean"); + debug_generic_expr (op0_type); + debug_generic_expr (op1_type); + return true; + } + } /* Or an integer vector type with the same size and element count as the comparison operand types. */ else if (TREE_CODE (type) == VECTOR_TYPE && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE) { if (TREE_CODE (op0_type) != VECTOR_TYPE || TREE_CODE (op1_type) != VECTOR_TYPE) { error ("non-vector operands in vector comparison"); debug_generic_expr (op0_type);