From patchwork Mon Aug 15 15:00:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 110046 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 79C63B6F67 for ; Tue, 16 Aug 2011 01:00:37 +1000 (EST) Received: (qmail 9001 invoked by alias); 15 Aug 2011 15:00:35 -0000 Received: (qmail 8990 invoked by uid 22791); 15 Aug 2011 15:00:32 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL, BAYES_00, 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; Mon, 15 Aug 2011 15:00:08 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id A5EDE8CC2B for ; Mon, 15 Aug 2011 17:00:07 +0200 (CEST) Date: Mon, 15 Aug 2011 17:00:07 +0200 (CEST) From: Richard Guenther To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR50082 Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) 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" PR50082 by passing comparison operands stripped off useless conversions to the canonicalization routine. This makes sure to fold the testcase early from a point where emitting a overflow warning is properly constrained. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2011-08-15 Richard Guenther PR middle-end/50082 * fold-const.c (maybe_canonicalize_comparison_1): Properly convert the modified operand to the other operand type. (fold_comparison): Call maybe_canonicalize_comparison_1 with useless conversions stripped from comparison operands. Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c (revision 177757) +++ gcc/fold-const.c (working copy) @@ -8446,6 +8446,7 @@ maybe_canonicalize_comparison_1 (locatio cst0, build_int_cst (TREE_TYPE (cst0), 1)); if (code0 != INTEGER_CST) t = fold_build2_loc (loc, code0, TREE_TYPE (arg0), TREE_OPERAND (arg0, 0), t); + t = fold_convert (TREE_TYPE (arg1), t); /* If swapping might yield to a more canonical form, do so. */ if (swap) @@ -8935,7 +8936,7 @@ fold_comparison (location_t loc, enum tr return fold_build2_loc (loc, cmp_code, type, variable1, const2); } - tem = maybe_canonicalize_comparison (loc, code, type, op0, op1); + tem = maybe_canonicalize_comparison (loc, code, type, arg0, arg1); if (tem) return tem;