From patchwork Mon Jul 24 08:43:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Cheng X-Patchwork-Id: 792677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-458744-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="CGa7v2h+"; dkim-atps=neutral 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 3xGFK14VMBz9s74 for ; Mon, 24 Jul 2017 18:43:47 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:content-type:mime-version; q=dns; s=default; b=EsS4/9zT6T4vrs42+tzw6YEoezFcnL0tDKUmOrVbUIVK+1AQVa yUeRQsjcz5hkuH98a9xZlEKL0pDenJF3zaoSehdNOCnrGOEI1Eb9Exvk990CcP4B MNL8ME7wKFPd3JVMFQXANLXMZlPhsucWoc66Aq02fjL7QfqQKxNkvFkqs= 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:from :to:cc:subject:date:message-id:content-type:mime-version; s= default; bh=Zj1y6aWEntEgmm1cVEpmdxf25sk=; b=CGa7v2h+7ftGKgxDre7E zljwkITSR1lPBaZJhrPXbweVjWspsEgMiCUh2883V89vlcWlrxpSKRZ46TiVVRNH 48/4p8hx5/81cOV6L/rVM8XjnfsOpy3Bq+TXxLgwcYdDbjJAGzHAmzHuIT3b/+9n Z70HTgxGI1jLMJEkli5voVw= Received: (qmail 48200 invoked by alias); 24 Jul 2017 08:43:39 -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 48190 invoked by uid 89); 24 Jul 2017 08:43:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: EUR01-VE1-obe.outbound.protection.outlook.com Received: from mail-ve1eur01on0056.outbound.protection.outlook.com (HELO EUR01-VE1-obe.outbound.protection.outlook.com) (104.47.1.56) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Jul 2017 08:43:34 +0000 Received: from DB5PR0801MB2742.eurprd08.prod.outlook.com (10.166.176.26) by DB5PR0801MB2744.eurprd08.prod.outlook.com (10.166.176.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1282.10; Mon, 24 Jul 2017 08:43:30 +0000 Received: from DB5PR0801MB2742.eurprd08.prod.outlook.com ([10.166.176.26]) by DB5PR0801MB2742.eurprd08.prod.outlook.com ([10.166.176.26]) with mapi id 15.01.1282.017; Mon, 24 Jul 2017 08:43:30 +0000 From: Bin Cheng To: "gcc-patches@gcc.gnu.org" CC: nd Subject: [PATCH GCC]Make pointer overflow always undefined and remove the macro Date: Mon, 24 Jul 2017 08:43:30 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Bin.Cheng@arm.com; x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB5PR0801MB2744; 7:gqmEakJ7/NTrESgP0vEw8BlK2No0taHs9UXq8E4epLZ2Z3FZcFC1Bm+XwAH1onYrgTrjCSaNq7dNJmWX6OuDqEXqNYJzJmPtVB85nPNlXg0jGGABv7NTI0nw4zpbY1rsjc9jXu41Yer9b5JY0cX8PGnWxUbTMuoYXfqm3+cDa+oQsJp8QqkqO/xDNz/0bhjVRXNTfN4Sjo6NSUHxzgHkPZWFeHMs1IW4Eg6ThPYKBH1K7SKDt4rlG34bLZ0ZVh3DnVjV+4mvpBg/q3awAx2hIKtuR+hkWnUx7THAOUfHzT84RMFL0TYXKgkBUlLm1K94Xm0Ijb/FdmX5XjF5W59LfyMDyB3rhcT5V9CGBtQfHUZIIWZ1T6iIOPHj2+1JRSdu6R5Oal3eEmln4h+9SfJuRb+ZewKZcCwp4gH83pTCXQx2AX5+NR9dQKchPmfMK7UaxfPhI3jXaZ6+aFsO2rBsQj0qhsrnZushRYi1+PGYd5VVXpYBILywmQgAGOPbzbae1m4HunItxW+KD5vsyGJ9Ns/3D0YPobH3c2ChLZ2Gj+I/mcqlUliX+d7tpVMjt/urTOdKLH70I28ePFvZ85wtZbYfTfoLCAhKnup08xTXck/t5sn/t9G3tvCS6BYbpri5coeLopX3VLHelx6baaItfgpUviFabnwaFbJNqAXsArz/4ToKKqmmnEaQNFXa7IFuVxdY1IlTz+3pGf4KJUPAlOoTUOXC2i4L6FFnCBRP61o0Zx3v5ZhRC6ICzbrWiACcfw4pKzEesJQwEbQbeyLDO8lI71dcKIAsrDdT0AKM5I4= x-ms-office365-filtering-correlation-id: e89fadb5-5ebd-428c-5451-08d4d2700fa2 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(48565401081)(300000503095)(300135400095)(2017052603031)(49563074)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DB5PR0801MB2744; x-ms-traffictypediagnostic: DB5PR0801MB2744: nodisclaimer: True x-exchange-antispam-report-test: UriScan:(180628864354917); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(102415395)(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(3002001)(6055026)(6041248)(20161123562025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DB5PR0801MB2744; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DB5PR0801MB2744; x-forefront-prvs: 0378F1E47A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(39840400002)(39450400003)(39400400002)(39860400002)(39410400002)(39850400002)(54534003)(189002)(377424004)(199003)(3280700002)(54356999)(9686003)(99936001)(2351001)(38730400002)(14454004)(102836003)(6116002)(33656002)(5640700003)(6506006)(97736004)(6436002)(55016002)(110136004)(99286003)(2501003)(77096006)(53936002)(189998001)(72206003)(86362001)(3846002)(50986999)(106356001)(2900100001)(6916009)(3660700001)(68736007)(105586002)(478600001)(74316002)(81166006)(4326008)(25786009)(8676002)(5660300001)(2906002)(8936002)(7696004)(305945005)(101416001)(66066001)(7736002)(81156014); DIR:OUT; SFP:1101; SCL:1; SRVR:DB5PR0801MB2744; H:DB5PR0801MB2742.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jul 2017 08:43:30.4674 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR0801MB2744 X-IsSubscribed: yes Hi, This is a followup patch to PR81388's fix. According to Richi, POINTER_TYPE_OVERFLOW_UNDEFINED was added in -fstrict-overflow warning work. Given: A) strict-overflow was removed; B) memory object can not wrap in address space; C) existing code doesn't take it in consideration, as in nowrap_type_p. This patch makes it always true thus removes definition/usage of the macro. Bootstrap and test on x86_64 and AArch64. Is it OK? Thanks, bin 2017-07-20 Bin Cheng * tree.h (POINTER_TYPE_OVERFLOW_UNDEFINED): Delete. * fold-const.c (fold_comparison, fold_binary_loc): Delete use of above macro. * match.pd: Ditto in address comparison pattern. gcc/testsuite/ChangeLog 2017-07-20 Bin Cheng * gcc.dg/no-strict-overflow-7.c: Revise comment and test string. * gcc.dg/tree-ssa/pr81388-1.c: Ditto. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1bcbbb5..78bb326 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8505,14 +8505,9 @@ fold_comparison (location_t loc, enum tree_code code, tree type, { /* We can fold this expression to a constant if the non-constant offset parts are equal. */ - if ((offset0 == offset1 - || (offset0 && offset1 - && operand_equal_p (offset0, offset1, 0))) - && (equality_code - || (indirect_base0 - && (DECL_P (base0) || CONSTANT_CLASS_P (base0))) - || POINTER_TYPE_OVERFLOW_UNDEFINED)) - + if (offset0 == offset1 + || (offset0 && offset1 + && operand_equal_p (offset0, offset1, 0))) { if (!equality_code && bitpos0 != bitpos1 @@ -8547,11 +8542,7 @@ fold_comparison (location_t loc, enum tree_code code, tree type, because pointer arithmetic is restricted to retain within an object and overflow on pointer differences is undefined as of 6.5.6/8 and /9 with respect to the signed ptrdiff_t. */ - else if (bitpos0 == bitpos1 - && (equality_code - || (indirect_base0 - && (DECL_P (base0) || CONSTANT_CLASS_P (base0))) - || POINTER_TYPE_OVERFLOW_UNDEFINED)) + else if (bitpos0 == bitpos1) { /* By converting to signed sizetype we cover middle-end pointer arithmetic which operates on unsigned pointer types of size @@ -9651,7 +9642,7 @@ fold_binary_loc (location_t loc, /* With undefined overflow prefer doing association in a type which wraps on overflow, if that is one of the operand types. */ - if ((POINTER_TYPE_P (type) && POINTER_TYPE_OVERFLOW_UNDEFINED) + if (POINTER_TYPE_P (type) || (INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type))) { if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)) @@ -9665,7 +9656,7 @@ fold_binary_loc (location_t loc, /* With undefined overflow we can only associate constants with one variable, and constants whose association doesn't overflow. */ - if ((POINTER_TYPE_P (atype) && POINTER_TYPE_OVERFLOW_UNDEFINED) + if (POINTER_TYPE_P (atype) || (INTEGRAL_TYPE_P (atype) && !TYPE_OVERFLOW_WRAPS (atype))) { if (var0 && var1) diff --git a/gcc/match.pd b/gcc/match.pd index 979085a..b89aed3 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3129,14 +3129,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) || TREE_CODE (base1) == STRING_CST)) equal = (base0 == base1); } - (if (equal == 1 - && (cmp == EQ_EXPR || cmp == NE_EXPR - /* If the offsets are equal we can ignore overflow. */ - || off0 == off1 - || POINTER_TYPE_OVERFLOW_UNDEFINED - /* Or if we compare using pointers to decls or strings. */ - || (POINTER_TYPE_P (TREE_TYPE (@2)) - && (DECL_P (base0) || TREE_CODE (base0) == STRING_CST)))) + (if (equal == 1) (switch (if (cmp == EQ_EXPR) { constant_boolean_node (off0 == off1, type); }) diff --git a/gcc/testsuite/gcc.dg/no-strict-overflow-7.c b/gcc/testsuite/gcc.dg/no-strict-overflow-7.c index 19e1b55..0e73d48 100644 --- a/gcc/testsuite/gcc.dg/no-strict-overflow-7.c +++ b/gcc/testsuite/gcc.dg/no-strict-overflow-7.c @@ -3,8 +3,8 @@ /* Source: Ian Lance Taylor. Dual of strict-overflow-6.c. */ -/* We can only simplify the conditional when using strict overflow - semantics. */ +/* We can simplify the conditional because pointer overflow always has + undefined semantics. */ int foo (char* p) @@ -12,4 +12,4 @@ foo (char* p) return p + 1000 < p; } -/* { dg-final { scan-tree-dump "\[+\]\[ \]*1000" "optimized" } } */ +/* { dg-final { scan-tree-dump "return 0" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c index ecfe129..0beb510 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81388-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -fno-strict-overflow -fdump-tree-ivcanon-details" } */ +/* { dg-options "-O2 -fno-strict-overflow -fdump-tree-tailc-details" } */ void bar(); void foo(char *dst) @@ -11,4 +11,6 @@ void foo(char *dst) } while (dst < end); } -/* { dg-final { scan-tree-dump-times " zero if " 1 "ivcanon" } } */ +/* The loop only iterates once because pointer overflow always has undefined + semantics. As a result, call to bar becomes tail call. */ +/* { dg-final { scan-tree-dump-times "Found tail call " 1 "tailc" } } */ diff --git a/gcc/tree.h b/gcc/tree.h index 91cf253..4e4edf2 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -859,9 +859,6 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, && !TYPE_OVERFLOW_WRAPS (TYPE) \ && (flag_sanitize & SANITIZE_SI_OVERFLOW)) -/* True if pointer types have undefined overflow. */ -#define POINTER_TYPE_OVERFLOW_UNDEFINED (!flag_wrapv) - /* Nonzero in a VAR_DECL or STRING_CST means assembler code has been written. Nonzero in a FUNCTION_DECL means that the function has been compiled. This is interesting in an inline function, since it might not need