From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id BD2383858C5F for ; Fri, 12 May 2023 11:48:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD2383858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EDD7E20241 for ; Fri, 12 May 2023 11:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683892079; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ztQWH4FEsfjAow7q2oBPa9uQA64JIvp56s68p3F27qA=; b=Nu0bRXVfCFvlK+34f6SQkjsiUk5dpngVffcQhGZXKnDQ5zJLP2tOB1OVCP1J4U7L46F3MM +m4CZYCcApBJwKPyWvoUcqyrLBUwKYIGfYF7FU9KvfR0D03/HQJPXuIHoMkiyQo5QLeAia FdRSBcKypb2IYW5Wo1TSCJt88isY7XI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683892079; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=ztQWH4FEsfjAow7q2oBPa9uQA64JIvp56s68p3F27qA=; b=EAqpAbr05dW5KbpQJtF+wkFSBN+yj1GsF/N5flXNFKB23PUuGmpLyEUnKFUL38eicD2olr ubl8Mx+31gsywTCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DA50A13499 for ; Fri, 12 May 2023 11:47:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eownNG8nXmTZCgAAMHmgww (envelope-from ) for ; Fri, 12 May 2023 11:47:59 +0000 Date: Fri, 12 May 2023 13:47:59 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/109791 - simplify (unsigned)&foo - (unsigned)(&foo + o) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230512114759.DA50A13499@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The following adds another variant of address difference simplification. The utility ptr_difference_const only handles constant differences (we also cannot code generate anything else), so exposing a possible POINTER_PLUS_EXPR in the match and computing the difference on the base only makes it possible to handle one case of a variable offset. This simplifies (unsigned long) &MEM [(void *)&str + 2B] - (unsigned long) (&str + (_69 + 1)) down to (1 - (unsigned long) _69) during niter analysis, allowing ranger to eliminate a condition later and avoiding a bogus -Wstringop-overflow diagnostic for the testcase in the PR. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/109791 * match.pd (minus (convert ADDR_EXPR@0) (convert (pointer_plus @1 @2))): New pattern. (minus (convert (pointer_plus @1 @2)) (convert ADDR_EXPR@0)): Likewise. --- gcc/match.pd | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index b7f28ab074c..2e46e074e93 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2572,6 +2572,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_and @0 { algn; }))) /* Try folding difference of addresses. */ +(simplify + (minus (convert ADDR_EXPR@0) (convert (pointer_plus @1 @2))) + (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) + (with { poly_int64 diff; } + (if (ptr_difference_const (@0, @1, &diff)) + (minus { build_int_cst_type (type, diff); } (convert @2)))))) +(simplify + (minus (convert (pointer_plus @0 @2)) (convert ADDR_EXPR@1)) + (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) + (with { poly_int64 diff; } + (if (ptr_difference_const (@0, @1, &diff)) + (plus (convert @2) { build_int_cst_type (type, diff); }))))) (simplify (minus (convert ADDR_EXPR@0) (convert @1)) (if (tree_nop_conversion_p (type, TREE_TYPE (@0))) -- 2.35.3