From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id 6F8793858D34 for ; Thu, 2 May 2024 09:26:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F8793858D34 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F8793858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714642015; cv=none; b=taGRe1pSJ+i991vVnAM0hKg3Pvzkfoncs9w3em9eub4wBPiEGBe3JbczIGnW6/8OTThNvug2pzqtyJzsYsdoVZbQS3bWcDUhGKJtttHXfEabv718VgPlB/iekeiVV6W8N20o2WhTJ4VBWNpk+XekmkLUbvDytQRdhhXdjHsbtxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714642015; c=relaxed/simple; bh=hiKPut8M5dmHeQV3lhtuAPghF04E5x7ymHD2bD3ysU4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=DjRxJbMC5zOb8dr0UI+/UtWy9yFwEX4MsZCoTJKx3osVeXWRkPMiz/dU5Z0VMbKDL8T2inpTmn1oKbZGaPsN3HW1Wvx5DbLpVx8N284jSswmbn32qek5WuVx54p6ROdZJK0iHSKqL3yzusCjUoXv5324uwAweqht0YK8+j2p2ZQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2e20f2db068so764261fa.2 for ; Thu, 02 May 2024 02:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714642012; x=1715246812; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=iDFCooGug/4qjxp2Y1CurE81U24bXOBrgy4rV80qDUU=; b=Vm4atZFUN2mUkpvx84FVHiutjshOalyiR1sMAhCT/r/f8Be94K9BGzlRQVoeG8AyXc RwBOY65RezpbL42OyEy6oqnpT3xByUntI6FR0P6s0yHbvWtjJPDawQ5AoWt+CgRsYx1s xtIPsJOs+W6jdI4wPNSowRAn1eQYUMvLigtQhmUxgRXP36JfimeVNs0sYAOiaaUYiyoN jFiu+/M9ijmB9Fcv0a4GfOt3dOO+Nl/mgNG2Ey12jG1gNmV7YtiKqkviZGL0UoGPq8wK QexqvmZutEN+wSouP7zBcr5btA7a9pNk1gCjpaq+jvosWJ6kwqIBbUdtwPxbTAi18Kfv wtSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714642012; x=1715246812; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iDFCooGug/4qjxp2Y1CurE81U24bXOBrgy4rV80qDUU=; b=r01e8mWAtk60moIWY4t6iSs+J1NE5KlrlHGI2iuURQ5636eeXtsSn0kR5TKLvVHxXB f0lOqScnb+Z4JY9foBQ7lfITji4L2rTkjhcF9dtX8DdA6QD6A3OdiJ5DFNPY77V1iQZi KoITw6MR4QGu6SHnRhah9VmR252tDWf3LvanttKGelVuOlzio/qFw2P8hSdat3GRDQcM vTHLkdcXPPQ4zBmppEpfih+1oFV17tlyHwmpJEdAGOSJ02KHlRW6GfmlFGOwEFUE+nt4 h7J9caFu/O1/2bFXkXWextEcfV1NT7vYQB/YDkOstOjJkjW/2zzCm2/LvHRXtFHxMHT8 C5eA== X-Gm-Message-State: AOJu0Yx5iPYcvkmzCG6LRSQ0vKeAxLx1CoqBcTYD7yt7vyPaTC+tni+d 1uYNFioehYFjzZvC/WIHWYyakS5wjfOMeQrPGEMrSCm/amDoJY0y4iaAEsSnZjrU5UJmcQAnmdY bkD1KGBFacvOJT/9jb8yN0OMiX1Vukgpi X-Google-Smtp-Source: AGHT+IExnWNExVVWU+LIonUWxlful919Zr8vfPAR4ALoWc+brci8FceJK0eL+ODir6KS+PFpbZe23iTeMFPLUPIBT7Y= X-Received: by 2002:a2e:84d5:0:b0:2df:a8e1:c24 with SMTP id q21-20020a2e84d5000000b002dfa8e10c24mr3091729ljh.34.1714642011566; Thu, 02 May 2024 02:26:51 -0700 (PDT) MIME-Version: 1.0 References: <003c01da994c$085826d0$19087470$@nextmovesoftware.com> In-Reply-To: <003c01da994c$085826d0$19087470$@nextmovesoftware.com> From: Richard Biener Date: Thu, 2 May 2024 11:26:40 +0200 Message-ID: Subject: Re: [PATCH] PR tree-opt/113673: Avoid load merging from potentially trapping additions. To: Roger Sayle Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,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 List-Id: On Sun, Apr 28, 2024 at 11:11=E2=80=AFAM Roger Sayle wrote: > > > This patch fixes PR tree-optimization/113673, a P2 ice-on-valid regressio= n > caused by load merging of (ptr[0]<<8)+ptr[1] when -ftrapv has been > specified. When the operator is | or ^ this is safe, but for addition > of signed integer types, a trap may be generated/required, so merging thi= s > idiom into a single non-trapping instruction is inappropriate, confusing > the compiler by transforming a basic block with an exception edge into on= e > without. One fix is to be more selective for PLUS_EXPR than for > BIT_IOR_EXPR or BIT_XOR_EXPR in gimple-ssa-store-merging.cc's > find_bswap_or_nop_1 function. > > An alternate solution might be to notice that in this idiom the addition > can't overflow, but that this detail wasn't apparent when exception edges > were added to the CFG. In which case, it's safe to remove (or mark for > removal) the problematic exceptional edge. Unfortunately updating the > CFG is a part of the compiler that I'm less familiar with. > > This patch has been tested on x86_64-pc-linux-gnu with make bootstrap > and make -k check, both with and without --target_board=3Dunix{-m32} > with no new failures. Ok for mainline? Instead of + case PLUS_EXPR: + /* Don't perform load merging if this addition can trap. */ + if (cfun->can_throw_non_call_exceptions + && INTEGRAL_TYPE_P (TREE_TYPE (rhs1)) + && TYPE_OVERFLOW_TRAPS (TREE_TYPE (rhs1))) + return NULL; please check stmt_can_throw_internal (cfun, stmt) - the find_bswap_or_no_lo= ad call in the function suffers from the same issue, so this should probably be checked before that call even. Thanks, Richard. > > 2024-04-28 Roger Sayle > > gcc/ChangeLog > PR tree-optimization/113673 > * gimple-ssa-store-merging.cc (find_bswap_or_nop_1) PLUS_EXPR>: > Don't perform load merging if a signed addition may trap. > > gcc/testsuite/ChangeLog > PR tree-optimization/113673 > * g++.dg/pr113673.C: New test case. > > > Thanks in advance, > Roger > -- >