From patchwork Wed Aug 20 07:54:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 381570 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 EDE2014013F for ; Wed, 20 Aug 2014 17:57:47 +1000 (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:subject:message-id:mime-version:content-type; q=dns; s= default; b=WvUFxjVBJmKpmycC4jz0YYt+y5f9xXdg8oMiqu996ciPp+O2NzyeR 81P70atVdth0VVf698GqhWNtkFzsBbVlTMtpAgnJHehkc5ZzHkiWda9uRj4MnsFn nGDA2R8fPlIZBcK4zmCqStBbY/DqxyYklQegwpg81tHla0i/DBO9Cw= 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=CD1PvN4SXk0FEc3YbvvvtYonm4E=; b=e14F4MPFsBVlR1mQtx00 XFxm7GiEetldkVt2fIZUelMW1bFHpxsOygGtACNCLnQj/acVtoP60wNNyBACajdR +fbmDeRGG7F+gf9TgVsFcoYo1hz1HQ1ir/ygdg2Z3tqKFrK6AaiECkllM6IhLTqv 3S23J0mV0ex2HUdDKMWVxK4= Received: (qmail 7674 invoked by alias); 20 Aug 2014 07:57:30 -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 7659 invoked by uid 89); 20 Aug 2014 07:57:29 -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, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Wed, 20 Aug 2014 07:57:28 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 0C70FAC98 for ; Wed, 20 Aug 2014 07:57:25 +0000 (UTC) Date: Wed, 20 Aug 2014 09:54:09 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH][match-and-simplify] Fix comparison pattern Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Committed. Also makes visible a desirable change I plan for if-exprs. They should behave like outer ifs and allow us to write that series of pattern as (for op in eq ne /* Simplify X * C1 CMP 0 to X CMP 0 if C1 is not zero. */ (simplify (op (mult @0 INTEGER_CST@1) integer_zerop@2) /* In fold-const.c we have this and the following patterns combined because there we can "compute" the operator to use by using swap_tree_comparison. */ (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) (if (tree_int_cst_sgn (@1) > 0) (op @0 @2)) (if (tree_int_cst_sgn (@1) < 0 && op == EQ_EXPR) (ne @0 @2)) (if (tree_int_cst_sgn (@1) < 0 && op == NE_EXPR) (eq @0 @2))))) that is, inner ifs have two operands, one condition and one "result" (which can be another if). And the simplify now has one mandatory match operand and at least one result operand (if which all but the last have to be an 'if'). Richard. 2014-08-20 Richard Biener * match-comparison.pd (X * CST == 0 -> X == 0): Properly guard with TYPE_OVERFLOW_UNDEFINED. Index: gcc/match-comparison.pd =================================================================== --- gcc/match-comparison.pd (revision 214146) +++ gcc/match-comparison.pd (working copy) @@ -5,13 +5,16 @@ /* In fold-const.c we have this and the following patterns combined because there we can "compute" the operator to use by using swap_tree_comparison. */ - (if (tree_int_cst_sgn (@1) > 0)) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) + && tree_int_cst_sgn (@1) > 0)) (op @0 @2)) (simplify (op (mult @0 INTEGER_CST@1) integer_zerop@2) - (if (tree_int_cst_sgn (@1) < 0 && op == EQ_EXPR)) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) + && tree_int_cst_sgn (@1) < 0 && op == EQ_EXPR)) (ne @0 @2)) (simplify (op (mult @0 INTEGER_CST@1) integer_zerop@2) - (if (tree_int_cst_sgn (@1) < 0 && op == NE_EXPR)) + (if (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)) + && tree_int_cst_sgn (@1) < 0 && op == NE_EXPR)) (eq @0 @2)))