From patchwork Tue Apr 16 14:00:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1924184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Jx2ZumBF; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=GdIvR/6u; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=Jx2ZumBF; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=GdIvR/6u; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VJm1F6LZTz1yXv for ; Wed, 17 Apr 2024 00:01:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 33AF13858C60 for ; Tue, 16 Apr 2024 14:01:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id C60F53858C50 for ; Tue, 16 Apr 2024 14:01:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C60F53858C50 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C60F53858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276072; cv=none; b=xGydfzNStd8l4pg2ui8PcSAzL41lODOc3oXGKeY/gNrOoWC6h+fgH1QDwmv/1laaK+YBm0CslZO1dWEu49WmLzCjLcWwsHbd8axq8G2xwKjJd+jbmrtSqZZliy+YEtdlKkNa8H2eeIJSaEGC7tLkOqGKtVcSMs8L99lb2H5L4OA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713276072; c=relaxed/simple; bh=MRc4kKBE68bX7KT7Vrs8cl8eLz3AstwV2/fSThUqHbw=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=SRsyNUBLEqkXav9OSzSX1ySenHZv5FJU0JnJIEXUiN3IAONmb7KK0um9zmPlQnH5CCY1X1XAtl/UFkuflLrLJnsl1mZijN490Fz/BUgvHo8ip0nbCC4KxPIjYkYjsLjX25Y9TmrZnm+TB56SSRlr+MAkV5k5EqWAogy8XwSmWeQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.5.241] (unknown [10.168.5.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 605E65F87B; Tue, 16 Apr 2024 14:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713276059; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=oNR8zNuO7BCbcWTRft34/co1It7iDC5cM7T9ymyhnTI=; b=Jx2ZumBFj8z1ha1+A7KSGtBw54L+PwPKgw0o2wcELhTAE67F5hZb7lai27eGkO/WTTcnLZ YqHak823hRvT2c7WFWr2HzMl5ur5eFUIN5wyGyo8zzyonKqUzpX7h6SJiVRN1cuQG0TvFr puvyjREirHU1Z2J5KgmiknIMKl5HvUE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713276059; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=oNR8zNuO7BCbcWTRft34/co1It7iDC5cM7T9ymyhnTI=; b=GdIvR/6upbIahCPSz6dUSPOfrFWbB7NXEfXyAa2hXnXujIdwzx6MHFfXZ8eBquE5seUMXm 8YyjG90/WYPwSdCA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1713276059; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=oNR8zNuO7BCbcWTRft34/co1It7iDC5cM7T9ymyhnTI=; b=Jx2ZumBFj8z1ha1+A7KSGtBw54L+PwPKgw0o2wcELhTAE67F5hZb7lai27eGkO/WTTcnLZ YqHak823hRvT2c7WFWr2HzMl5ur5eFUIN5wyGyo8zzyonKqUzpX7h6SJiVRN1cuQG0TvFr puvyjREirHU1Z2J5KgmiknIMKl5HvUE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1713276059; h=from:from:reply-to:date:date:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=oNR8zNuO7BCbcWTRft34/co1It7iDC5cM7T9ymyhnTI=; b=GdIvR/6upbIahCPSz6dUSPOfrFWbB7NXEfXyAa2hXnXujIdwzx6MHFfXZ8eBquE5seUMXm 8YyjG90/WYPwSdCA== Date: Tue, 16 Apr 2024 16:00:59 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek Subject: [PATCH] middle-end/13421 - -ftrapv vs. POINTER_DIFF_EXPR MIME-Version: 1.0 X-Spam-Score: 1.21 X-Spamd-Result: default: False [1.21 / 50.00]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.17)[-0.874]; MIME_GOOD(-0.10)[text/plain]; BAYES_HAM(-0.01)[49.61%]; RCVD_COUNT_ZERO(0.00)[0]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[] X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Message-Id: <20240416140134.33AF13858C60@sourceware.org> Currently we expand POINTER_DIFF_EXPR using subv_optab when -ftrapv (but -fsanitize=undefined does nothing). That's not consistent with the behavior of POINTER_PLUS_EXPR which never uses addv_optab with -ftrapv. Both are because of the way we select whether to use the trapping or the non-trapping optab - we look at the result type of the expression and check trapv = INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type); the bugreport correctly complains that -ftrapv affects pointer subtraction (there's no -ftrapv-pointer). Now that we have POINTER_DIFF_EXPR we can honor that appropriately. The patch moves both POINTER_DIFF_EXPR and POINTER_PLUS_EXPR handling so they will never consider trapping (or saturating) optabs. Bootstrapped and tested on x86_64-unknown-linux-gnu. OK for stage1? Thanks, Richard. PR middle-end/13421 * optabs-tree.cc (optab_for_tree_code): Do not consider {add,sub}v or {us,ss}{add,sub} optabs for POINTER_DIFF_EXPR or POINTER_PLUS_EXPR. --- gcc/optabs-tree.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/optabs-tree.cc b/gcc/optabs-tree.cc index e7bd0d10892..b69a5bc3676 100644 --- a/gcc/optabs-tree.cc +++ b/gcc/optabs-tree.cc @@ -135,6 +135,12 @@ optab_for_tree_code (enum tree_code code, const_tree type, case MIN_EXPR: return TYPE_UNSIGNED (type) ? umin_optab : smin_optab; + case POINTER_PLUS_EXPR: + return add_optab; + + case POINTER_DIFF_EXPR: + return sub_optab; + case REALIGN_LOAD_EXPR: return vec_realign_load_optab; @@ -249,13 +255,11 @@ optab_for_tree_code (enum tree_code code, const_tree type, trapv = INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_TRAPS (type); switch (code) { - case POINTER_PLUS_EXPR: case PLUS_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? usadd_optab : ssadd_optab; return trapv ? addv_optab : add_optab; - case POINTER_DIFF_EXPR: case MINUS_EXPR: if (TYPE_SATURATING (type)) return TYPE_UNSIGNED (type) ? ussub_optab : sssub_optab;