From patchwork Tue Mar 22 17:40:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 600898 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 3qV0PW1TtCz9s9Z for ; Wed, 23 Mar 2016 04:41:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=I8zpfRct; 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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=l9K/InQpNzgxuA7fAkAxshvKVCB/Hqn6zWsatDQ5fk1/X5dUMv svVld6HBZEAT57yH++cRvlTYyKZFwzQ3cDwRFMkxYeV3X46kXvzKnrkxLksZzrdH vCN5nWpNaAQjne/cL0vt6ni2mjjHmozoWTms7bsJxdoogMu6su+IXWbx8= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=KPA90uIl4/Z+JlQ9c/kZRdcAMwQ=; b=I8zpfRctcWduvndqToRc 0oLBn+1mXzJQtTiKVF/U5r2WyIoeMmaDPZHak+XOAaBk5q0gmp7Xo56k0QJXq/rM 0xdmwk9Y/85tuEd+Qm49qdBODTYuFyz7eijNc1cit9Say3fNDFXoVTBlSVCgae7C S+8OueFT/3y9G4uDEwzR/V0= Received: (qmail 23052 invoked by alias); 22 Mar 2016 17:40:24 -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 22972 invoked by uid 89); 22 Mar 2016 17:40:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=1, 19, type_precision, TYPE_PRECISION, (unknown) X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 22 Mar 2016 17:40:17 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id C673C7F6B1; Tue, 22 Mar 2016 17:40:15 +0000 (UTC) Received: from anchor.twiddle.net (vpn-232-128.phx2.redhat.com [10.3.232.128]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2MHeFG4022729; Tue, 22 Mar 2016 13:40:15 -0400 To: Richard Biener Cc: GCC Patches From: Richard Henderson Subject: [PATCH] Fix 69845 Message-ID: <56F1837D.1000508@redhat.com> Date: Tue, 22 Mar 2016 10:40:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 X-IsSubscribed: yes In PR68142 you added a check for overflow + __INT_MIN__. I can't figure out why the check for __INT_MIN__, except that it seems specific to the test case you examined. And indeed, this test case shows how things go wrong with other distributed folding leading to overflow. I added two tests, one signed, one unsigned. The second verifies that we do still fold for the defined-overflow case. Ok? r~ diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 9d861c6..44fe2a2 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6116,11 +6116,9 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, { tree tem = const_binop (code, fold_convert (ctype, t), fold_convert (ctype, c)); - /* If the multiplication overflowed to INT_MIN then we lost sign - information on it and a subsequent multiplication might - spuriously overflow. See PR68142. */ - if (TREE_OVERFLOW (tem) - && wi::eq_p (tem, wi::min_value (TYPE_PRECISION (ctype), SIGNED))) + /* If the multiplication overflowed, we lost information on it. + See PR68142 and PR69845. */ + if (TREE_OVERFLOW (tem)) return NULL_TREE; return tem; } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69845-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69845-1.c new file mode 100644 index 0000000..92927ba --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr69845-1.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target int32 } */ +/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */ + +int +main () +{ + struct S { char s; } v; + v.s = 47; + int a = (int) v.s; + int b = (27005061 + (a + 680455)); + int c = ((1207142401 * (((8 * b) + 9483541) - 230968044)) + 469069442); + if (c != 1676211843) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "b \\\* 8" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69845-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69845-2.c new file mode 100644 index 0000000..e0b38e9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr69845-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target int32 } */ +/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */ + +int +main () +{ + struct S { char s; } v; + v.s = 47; + unsigned int a = (unsigned int) v.s; + unsigned int b = (27005061 + (a + 680455)); + unsigned int c + = ((1207142401u * (((8u * b) + 9483541u) - 230968044u)) + 469069442u); + if (c != 1676211843u) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump-times "b \\\* 1067204616" 1 "gimple" } } */ +/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */