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: 1843976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mQUVAQ+2; 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 4S1bWH0FMLz1yqD for ; Fri, 6 Oct 2023 02:46:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE1023875463 for ; Thu, 5 Oct 2023 15:45:59 +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-Google-Smtp-Source: AGHT+IFpYv5rrxrQFKJVl0YO3ANlTb7UXJrTHdLf5Itzs11NgBbbdjODw2/1leMDnj/0J44WONIHBtA1LIgi0lyyxNE= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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" } } */