From patchwork Mon Dec 1 13:06: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: 416441 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 1BE77140174 for ; Tue, 2 Dec 2014 00:12:43 +1100 (AEDT) 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=cvAi7NTldOTJogptoMZOTjpoaIffOJG1+UmzjntTL/NV7sWJIIUYS 44M3Gs45eRetvBiCLGMA78op3XUOwbRIGKI0USWh1lSnnoobIMlDupelH8dS7TkA SOU2Edu/TRqdJLWcAvK2tWpJMolyBnPyZlKwBDGb3erlFXWj6z33JQ= 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=4F30Gj2z6I2/conH8CHBMSm+mos=; b=ySpOhca8Q9KVRQWcCfHv uMFkNrDBTM8RyXkk6JDC/scYVBmd6BLOqkeP0ItFtXx0ITSB0nCIMzBiDl1LnYNQ a27ejJTTOropfmKiZw+3YBjbrHZB5B3Nzi4H0TawtlyA1hICcxg6DXmYt4kS6otd 7HTDiZ+6b03QbgEkZ0f+OZk= Received: (qmail 15346 invoked by alias); 1 Dec 2014 13:12:35 -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 15325 invoked by uid 89); 1 Dec 2014 13:12:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, T_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; Mon, 01 Dec 2014 13:12:33 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 39D5EAB09 for ; Mon, 1 Dec 2014 13:12:30 +0000 (UTC) Date: Mon, 1 Dec 2014 14:06:09 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR15346 Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 The following fixes the oldest bug in my list of assigned PRs, namely combining A / CST / CST' to A / (CST * CST'). extract_muldiv does this in fold-const.c (but it fails to optimize to zero when CST * CST' overflows). Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2014-12-01 Richard Biener PR tree-optimization/15346 * Makefile.in (gimple-match.o-warn): Remove -Wno-unused-parameter, add -Wno-unused-but-set-variable. * match.pd: Combine two successive divisions. * gcc.dg/tree-ssa/forwprop-32.c: New testcase. Index: gcc/match.pd =================================================================== --- gcc/match.pd (revision 218140) +++ gcc/match.pd (working copy) @@ -129,6 +129,19 @@ (define_operator_list inverted_tcc_compa && TYPE_UNSIGNED (type)) (trunc_div @0 @1))) +/* Combine two successive divisions. */ +(for div (trunc_div ceil_div floor_div round_div exact_div) + (simplify + (div (div @0 INTEGER_CST@1) INTEGER_CST@2) + (with { + bool overflow_p; + wide_int mul = wi::mul (@1, @2, TYPE_SIGN (type), &overflow_p); + } + (if (!overflow_p) + (div @0 { wide_int_to_tree (type, mul); })) + (if (overflow_p) + { build_zero_cst (type); })))) + /* Optimize A / A to 1.0 if we don't care about NaNs or Infinities. */ (simplify Index: gcc/testsuite/gcc.dg/tree-ssa/forwprop-32.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/forwprop-32.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/forwprop-32.c (working copy) @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-forwprop1 -fdump-tree-ccp1" } */ + +int foo (int x) +{ + int tem = x / 3; + return tem / 5; +} +int bar (int x) +{ + int tem = x / 3; + return tem / (__INT_MAX__ / 2); +} + +/* { dg-final { scan-tree-dump "x_.\\(D\\) / 15" "forwprop1" } } */ +/* { dg-final { scan-tree-dump "return 0;" "ccp1" } } */ +/* { dg-final { cleanup-tree-dump "forwprop1" } } */ +/* { dg-final { cleanup-tree-dump "ccp1" } } */ Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 218142) +++ gcc/Makefile.in (working copy) @@ -209,8 +209,8 @@ gengtype-lex.o-warn = -Wno-error libgcov-util.o-warn = -Wno-error libgcov-driver-tool.o-warn = -Wno-error libgcov-merge-tool.o-warn = -Wno-error -gimple-match.o-warn = -Wno-unused-variable -Wno-unused-parameter -generic-match.o-warn = -Wno-unused-variable -Wno-unused-parameter +gimple-match.o-warn = -Wno-unused-variable -Wno-unused-but-set-variable +generic-match.o-warn = -Wno-unused-variable -Wno-unused-but-set-variable # All warnings have to be shut off in stage1 if the compiler used then # isn't gcc; configure determines that. WARN_CFLAGS will be either