From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 55535 invoked by alias); 5 Oct 2016 11:38:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 55518 invoked by uid 89); 5 Oct 2016 11:38:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=BAYES_00,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Oct 2016 11:38:07 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D1CCFACF7 for ; Wed, 5 Oct 2016 11:38:04 +0000 (UTC) Date: Wed, 05 Oct 2016 11:38:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Fix PR77826 In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2016-10/txt/msg00223.txt.bz2 On Tue, 4 Oct 2016, Richard Biener wrote: > > The following will fix PR77826, the issue that in match.pd matching > up two things uses operand_equal_p which is too lax about the type > of the toplevel entity (at least for integer constants). > > Bootstrap / regtest pending on x86_64-unknown-linux-gnu. The following is what I have applied. Richard. 2016-10-05 Richard Biener PR middle-end/77826 * genmatch.c (dt_operand::gen_match_op): Amend operand_equal_p with types_match for GIMPLE code gen to handle type mismatched constants properly. (dt_operand::gen): Adjust. * match.pd ((X /[ex] A) * A -> X): Properly handle converted and constant A. * gcc.dg/torture/pr77826.c: New testcase. Index: gcc/testsuite/gcc.dg/torture/pr77826.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr77826.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr77826.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +void +fi(unsigned long int *v0, unsigned int ow, int q2) +{ + if (ow + q2 != 0) + if (q2 == 1) + { + *v0 |= q2; + q2 ^= *v0; + } +} Index: gcc/genmatch.c =================================================================== --- gcc/genmatch.c (revision 240744) +++ gcc/genmatch.c (working copy) @@ -1562,7 +1562,7 @@ struct dt_operand : public dt_node void gen (FILE *, int, bool); unsigned gen_predicate (FILE *, int, const char *, bool); - unsigned gen_match_op (FILE *, int, const char *); + unsigned gen_match_op (FILE *, int, const char *, bool); unsigned gen_gimple_expr (FILE *, int); unsigned gen_generic_expr (FILE *, int, const char *); @@ -2589,12 +2589,18 @@ dt_operand::gen_predicate (FILE *f, int a capture-match. */ unsigned -dt_operand::gen_match_op (FILE *f, int indent, const char *opname) +dt_operand::gen_match_op (FILE *f, int indent, const char *opname, bool gimple) { char match_opname[20]; match_dop->get_name (match_opname); - fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n", - opname, match_opname, opname, match_opname); + if (gimple) + fprintf_indent (f, indent, "if (%s == %s || (operand_equal_p (%s, %s, 0) " + "&& types_match (%s, %s)))\n", + opname, match_opname, opname, match_opname, + opname, match_opname); + else + fprintf_indent (f, indent, "if (%s == %s || operand_equal_p (%s, %s, 0))\n", + opname, match_opname, opname, match_opname); fprintf_indent (f, indent + 2, "{\n"); return 1; } @@ -2991,7 +2997,7 @@ dt_operand::gen (FILE *f, int indent, bo else if (type == DT_TRUE) ; else if (type == DT_MATCH) - n_braces = gen_match_op (f, indent, opname); + n_braces = gen_match_op (f, indent, opname, gimple); else gcc_unreachable (); Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 240770) +++ gcc/match.pd (working copy) @@ -1773,9 +1803,13 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* (X /[ex] A) * A -> X. */ (simplify - (mult (convert? (exact_div @0 @1)) @1) - /* Look through a sign-changing conversion. */ - (convert @0)) + (mult (convert1? (exact_div @0 @1)) (convert2? @2)) + /* We cannot use matching captures here, since in the case of + constants we don't see the second conversion. Look through + a sign-changing or widening conversions. */ + (if (operand_equal_p (@1, @2, 0) + && element_precision (@0) <= element_precision (type)) + (convert @0))) /* Canonicalization of binary operations. */