From patchwork Sun May 21 21:21:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 765193 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 3wWF9s6TDnz9ryr for ; Mon, 22 May 2017 07:22:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="dO/yTTdb"; 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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=y0gyaY50gLY6JL+wFB1xLizz60jYwIp5Wpd554jBhmKta+OSzGhHY W1Shkui6akb0IVYJtUQh8rBSGXCL3AzPyHCOoIKTwrP7MIM6wbQ04BQonoXGpCso Vw0OsYFYWqCEPOvG/5Qhe+GaALI1Hgm8iQEgrP2ad2BRNcyqOnn7ug= 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:subject:message-id:mime-version:content-type; s= default; bh=y5pewxxw9j/thtZ/sdxEqYYuliM=; b=dO/yTTdbJNC5u9f6gHS4 xMBt4DGyX46DCennbwAiJvh9cza7MXSdsxdZLrLxjXWQhKEsOPWGPOXg+3ZfwbEG McGxPo1359fr5CauzSQv3GuRfdKHV+lvxz45ApwM5DWpjjv/UHAUUbM/x+ukSWVH KBxhkrP+hmoOCpCTuKH0C84= Received: (qmail 6229 invoked by alias); 21 May 2017 21:22:07 -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 6218 invoked by uid 89); 21 May 2017 21:22:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=ab, H*MI:2140, H*M:2140, H*c:HHHH X-HELO: mail3-relais-sop.national.inria.fr Received: from mail3-relais-sop.national.inria.fr (HELO mail3-relais-sop.national.inria.fr) (192.134.164.104) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 21 May 2017 21:22:05 +0000 Received: from 187.57.140.77.rev.sfr.net (HELO stedding) ([77.140.57.187]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 21 May 2017 23:21:43 +0200 Date: Sun, 21 May 2017 23:21:31 +0200 (CEST) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Relax VIEW_CONVERT_EXPR - CONVERT_EXPR combination Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Hello, SRA uses char when scalarizing bool, and we end up with _6 = u_1(D) == 0.0; _7 = (unsigned char) _6; _3 = VIEW_CONVERT_EXPR<_Bool>(_7); which we currently do not simplify. I am not completely sure what happens with types whose precision does not cover their size, I hope this is safe. Bootstrap+testsuite on powerpc64le-unknown-linux-gnu. 2017-05-22 Marc Glisse gcc/ * match.pd (view_convert (convert@0 @1)): Handle zero-extension. gcc/testsuite/ * gcc.dg/tree-ssa/vce-1.c: New file. Index: match.pd =================================================================== --- match.pd (revision 248312) +++ match.pd (working copy) @@ -1798,27 +1798,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* For integral conversions with the same precision or pointer conversions use a NOP_EXPR instead. */ (simplify (view_convert @0) (if ((INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)) && (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0))) && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0))) (convert @0))) -/* Strip inner integral conversions that do not change precision or size. */ +/* Strip inner integral conversions that do not change precision or size, or + zero-extend while keeping the same size (for bool-to-char). */ (simplify (view_convert (convert@0 @1)) (if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0))) && (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1))) - && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1))) - && (TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1)))) + && TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1)) + && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)) + || (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (TREE_TYPE (@1)) + && TYPE_UNSIGNED (TREE_TYPE (@1))))) (view_convert @1))) /* Re-association barriers around constants and other re-association barriers can be removed. */ (simplify (paren CONSTANT_CLASS_P@0) @0) (simplify (paren (paren@1 @0)) @1) Index: testsuite/gcc.dg/tree-ssa/vce-1.c =================================================================== --- testsuite/gcc.dg/tree-ssa/vce-1.c (nonexistent) +++ testsuite/gcc.dg/tree-ssa/vce-1.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +typedef struct { _Bool b; } A; +_Bool f(double u){ + A a; + if(u==0) + a.b=1; + else + a.b=0; + return a.b; +} + +/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR" "optimized" } } */