From patchwork Thu Oct 5 15:45:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 148813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2016:b0:403:3b70:6f57 with SMTP id fe22csp388870vqb; Thu, 5 Oct 2023 08:46:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIQsEd1NG9jNLtfTSIsUsqdCPXbalWkr1+SIFAT1G0EZTY7woJ1iPoFB1HN5mn1YKd1h7R X-Received: by 2002:a05:6402:344a:b0:523:4025:49f0 with SMTP id l10-20020a056402344a00b00523402549f0mr4829212edc.26.1696520779922; Thu, 05 Oct 2023 08:46:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696520779; cv=none; d=google.com; s=arc-20160816; b=CCmH7+9dEYNefxipeoC2JMPi64cGhBK3EbqGCEVb0gWMAa6Q49fQDJmDwLlSWDETqu AU6kTp4GXKV8jBtQnmceQHcEOCM9d3HU3/qGVrzykry8q5C3OOD8eL0rtVDc09OjsUkx JVH8gjbblZYTz/mFpGU+d3OicE7Ba4FC8mBFIl7kmtJDtRWekOHZG4vRPSpcM8A/ZYNZ DZlTj3o0QJXFA+ANOa7JtUySzyNS/S0pN2mWsSHeDwc51W3XAqFQtdKtiePlTuZ7a7FP MtsYLoib88t5BqZ9pqlj/Eyb/VyJVUTAJRJVrpwmwKxNNNUhPUOx0LomE+H05Yepo4as ZotQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:message-id:date:from :mime-version:dkim-signature:dmarc-filter:delivered-to; bh=c9tp+9MliOf1PqEktXv3jnkNwdU2EkFNevK8bHIBkug=; fh=XNn3asQvIblazGK92GBt13dVv+YmGV3pBS0JC29ZQco=; b=ClftqklxqrLV1+/YfKWU6O4bG+Wecjdh2DtFEKUusfC9d3lfJO7Ds5wHKs+Oio+604 792SqOoP2lUBnW/eozAFr8k3cT6osbps/FadZXFsiLO1i3iPHvNV3w8MHw0msQMzOQ2R 7Wf3OQT/Kniq2PFYmbk/ggVqu5gccbVudTvVeNXshANHQmQ7bKTDIoQaOQsSgPdtbuzs 12XcfLUvd/B4/Qc9J4nCVdNO4ijqmBs/KGXaUS/8+MuExTlvWMh3bmyIhWTr/ar6I/pF 9ondQCLUfeN/jIThAg8gkR2VzOJ3+c2yBy/OE5FI2wFAjSXT4Du3hvPhhhLOZd+RJuuF PMqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mQUVAQ+2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a6-20020aa7d746000000b00534772db360si836252eds.518.2023.10.05.08.46.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 08:46:19 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mQUVAQ+2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B90623861894 for ; Thu, 5 Oct 2023 15:46:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 9181E385771B for ; Thu, 5 Oct 2023 15:45:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9181E385771B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-52bd9ddb741so2015277a12.0 for ; Thu, 05 Oct 2023 08:45:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696520746; x=1697125546; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=c9tp+9MliOf1PqEktXv3jnkNwdU2EkFNevK8bHIBkug=; b=mQUVAQ+2fhdiDkG/OqMn77RKcFtEmMqY5egC/qQslSXn0KRo7K2iP+gFaTfClMgt5t 3MmFXOnTLql+1sw8+9xMwH5umNj4jzQ2D/e2qNiJ/mLMhcxrnBCsbwd34PNlYyaA5Z7w 1ZxAfjGmCo3PfnHZRukOs+UyNi4MJKgZ+mfpIBG8V0RTZg8qW6HSMIwFaT3wZzto1sw6 gIb/GLof8JAyz+Jy6t/mNSBSFvrl0w9wri2/yN8Cx+qR25EKpQLRLEmHYWO2r6e4MBY+ JbGz9uFcugnYmyyEGZ6wrgaPY6apU6fv9qNV2l+FRr7gllIFw68mqY2ujMb55gIgdJw4 usFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696520746; x=1697125546; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=c9tp+9MliOf1PqEktXv3jnkNwdU2EkFNevK8bHIBkug=; b=ThamUf4QhaiyHBNTfQaNMPTMIWxDTPt9GGIQ92HAy7nmywCs/v4CTCqfvE3bWA1Apd tbh/1xeWXxS5GCDjvGPG2R8I7ZTqu0bChiHc8zx/mYRjMMa+p5XBT3LmnJRr6Su8FqcF 8RyN918zx+OYafa0xydvG1Ckliy7HqaktO1whQF/PLNvOHLHw/oOLo4PJihdPOwcuMsZ rvNczYz0CHYaKI6+Y5tTVtrpDaxe3KNsfG2AKy08kU1R+MBDMrrCT+Oi0YXBwTH0+EDM ih/bGMRWwEw1lpItMQVGYqOHKT2NRll4vokoI1+HBGO+GkuVc9PO4HNY2fnReVJxXwBE Qy0A== X-Gm-Message-State: AOJu0YychSmVRsub8dqS3nIu9qGIDfSHcFaQEvMn3mvt0gt6jOcunbI3 G0AmERxDe/0/+H8tKkqOA2BiXZlBzGNmeqC4FlDptR9tbBF54Q== X-Received: by 2002:aa7:cfd6:0:b0:530:9bea:ed5e with SMTP id r22-20020aa7cfd6000000b005309beaed5emr4847358edy.14.1696520745736; Thu, 05 Oct 2023 08:45:45 -0700 (PDT) MIME-Version: 1.0 From: Uros Bizjak Date: Thu, 5 Oct 2023 17:45:34 +0200 Message-ID: Subject: [COMMITTED] i386: Improve memory copy from named address space [PR111657] To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778930973617147218 X-GMAIL-MSGID: 1778930973617147218 The stringop strategy selection algorithm falls back to a libcall strategy when it exhausts its pool of available strategies. The memory area copy function (memcpy) is not available from the system library for non-default address spaces, so the compiler emits the most trivial byte-at-a-time copy loop instead. The compiler should instead emit an optimized copy loop as a fallback for non-default address spaces. PR target/111657 gcc/ChangeLog: * config/i386/i386-expand.cc (alg_usable_p): Reject libcall strategy for non-default address spaces. (decide_alg): Use loop strategy as a fallback strategy for non-default address spaces. gcc/testsuite/ChangeLog: * gcc.target/i386/pr111657.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index e42ff27c6ef..9a988347200 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -8320,6 +8320,11 @@ alg_usable_p (enum stringop_alg alg, bool memset, bool have_as) { if (alg == no_stringop) return false; + /* It is not possible to use a library call if we have non-default + address space. We can do better than the generic byte-at-a-time + loop, used as a fallback. */ + if (alg == libcall && have_as) + return false; if (alg == vector_loop) return TARGET_SSE || TARGET_AVX; /* Algorithms using the rep prefix want at least edi and ecx; @@ -8494,8 +8499,12 @@ decide_alg (HOST_WIDE_INT count, HOST_WIDE_INT expected_size, gcc_assert (alg != libcall); return alg; } + + /* Try to use some reasonable fallback algorithm. Note that for + non-default address spaces we default to a loop instead of + a libcall. */ return (alg_usable_p (algs->unknown_size, memset, have_as) - ? algs->unknown_size : libcall); + ? algs->unknown_size : have_as ? loop : libcall); } /* Decide on alignment. We know that the operand is already aligned to ALIGN diff --git a/gcc/testsuite/gcc.target/i386/pr111657.c b/gcc/testsuite/gcc.target/i386/pr111657.c new file mode 100644 index 00000000000..fe54fcae8cc --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr111657.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-rtl-expand -mno-sse" } */ + +struct a { long arr[30]; }; + +__seg_gs struct a m; +void bar (struct a *dst) { *dst = m; } + +/* { dg-final { scan-rtl-dump-not "libcall" "expand" } } */