From patchwork Thu Sep 16 09:02:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 45069 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F27F43857430 for ; Thu, 16 Sep 2021 09:02:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 7040C3858D3C for ; Thu, 16 Sep 2021 09:02:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7040C3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x333.google.com with SMTP id l18-20020a05600c4f1200b002f8cf606262so6828308wmq.1 for ; Thu, 16 Sep 2021 02:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ly6AFQAG/tG9QVZjdihDnfxai1RaeS4TmfjBRtjV3F8=; b=Ze3c4RJ4QmCUdNMbb0l0FTD8cSGlCjzwV5GPN7RK9ZLuY5NZav0k3YQI4UKmXnncs9 0dQ100zjRz4S6N96vli/71E5WmIzztAyORqq7CWPsPudr4f6Ml2MlAGevp/ML2NeKdfb QQX+gzxAuf5vLBLeRmSko4xyMoNxWx6gEdxTMJu4BJobdJkYzK4Y6dXyEp3BiuNi1kT6 8Ck2g8CmWeVkybcHerpT8FVf4O6WFbhp8kzl3FDtljq4QgESrcnQSU5UB7iC8I76dKdz JbSoDd9yrLDL27NCQFMEpcYxY1hBidgYGqakoVdvh2kKXifhE7Z4SlqRFIcZSjYuJnOq dkUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Ly6AFQAG/tG9QVZjdihDnfxai1RaeS4TmfjBRtjV3F8=; b=FCDFVUXq+6E9/YfKWZ5XgMD+SbdURtVRcGce2cl5TbNY4ZrP5wUFgTn5p8CjaUVA5d mk4uPaiFgwm6elMZLXM9eMGme3ItbtNE7E7/19Bw/vRWuDmQPe8r5NShCtGTKkkLnhzt gMlUp7VAk4ys5tHfL3vVX6tTaShSnOp1lwjPCzHRGFox9QXYC8fHMXs5wcFeDPmNODxX m0lyfK3AQXMtX1eA0jNEWyEdu9ARkAiQHheebOZoS+cejpIn5rM+AtyNuT/JlA5XLN3y 2yyZQC8/GmqR2Beew6nHZCJjFQfEu7CsRvMaxCqJnNTvuhcZX/k/NCjiFGikmZjNookd iaXw== X-Gm-Message-State: AOAM532sRbqyyLeL6BrzNUERT4j59lKsVg4qW/ZRL710DCumY5dx7Mxb ekbOWiQiZYUxq8oigV8fUZmEmEG5QPM8hp0s X-Google-Smtp-Source: ABdhPJzS5LvYCeoy9HRLcXSP+L62vfzasLfymQ1znJE56YDFcxu9ZY0XnTY4sfxf6SCDY+FA+4MI2Q== X-Received: by 2002:a7b:c2ef:: with SMTP id e15mr3903529wmk.54.1631782949466; Thu, 16 Sep 2021 02:02:29 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id z17sm2704166wrr.49.2021.09.16.02.02.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Sep 2021 02:02:28 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR rtl-optimization/102306 Date: Thu, 16 Sep 2021 11:02:27 +0200 Message-ID: <3130475.aeNJFYEL58@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this is a duplication of volatile loads introduced during GCC 9 development by the new 2->2 mechanism of the RTL combiner. There is already a substantial checking for volatile references in can_combine_p but it implicitly assumes that the combination reduces the number of instructions, which is of course not the case here. So the fix teaches try_combine to abort the combination when it is about to make a copy of volatile references to preserve them. Bootstrapped/regtested on x86-64/Linux, OK for mainline and release branches? 2021-09-16 Eric Botcazou PR rtl-optimization/102306 * combine.c (try_combine): Abort the combination if we are about to duplicate volatile references. 2021-09-16 Eric Botcazou * gcc.target/sparc/20210916-1.c: New test. diff --git a/gcc/combine.c b/gcc/combine.c index 290a3667c65..892c834a160 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -3063,6 +3063,16 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0, return 0; } + /* We cannot safely duplicate volatile references in any case. */ + + if ((added_sets_2 && volatile_refs_p (PATTERN (i2))) + || (added_sets_1 && volatile_refs_p (PATTERN (i1))) + || (added_sets_0 && volatile_refs_p (PATTERN (i0)))) + { + undo_all (); + return 0; + } + /* Count how many auto_inc expressions there were in the original insns; we need to have the same number in the resulting patterns. */