From patchwork Thu Oct 7 16:45:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 45962 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 D3BF83857C4A for ; Thu, 7 Oct 2021 16:45:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id E05223858C60 for ; Thu, 7 Oct 2021 16:45:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E05223858C60 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-x62c.google.com with SMTP id t11so4261342plq.11 for ; Thu, 07 Oct 2021 09:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=u3daDYpR3hd29cQ+d2ca3PQ6GLmYGpAJLD6wXEZ3HOk=; b=iOArP4TpdIVl9DGgXIXJk728YRLFNs5p7tTGPzQoZb4dbQN2szDpP+lj+Y1jv+M7pd uPgDi2FK5eowMGzDAwRHDgTaNKQwyLXDKyVu9qAkyV11+G8yDlAYeyFCVNvHNw5UdQsy UUH7GmiwlREpNmvmqDORRYQT3zJ6SEtguBfTqCqwR+8t0ZzSlkrVgfxulngpsnq1syH2 ih5A3Go6GfTFJBanmBJCmcRFtvg+FYZ8VwbgCOUh92wEVYuQeRhYcMzvIqwUVVpgFGfq rE6emimko8K6nm9PePj+u5VWRJlfUw/q5gb5Bygw6JKiY8o98TToS8VEiy1vju2P/hAM whjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=u3daDYpR3hd29cQ+d2ca3PQ6GLmYGpAJLD6wXEZ3HOk=; b=YA08i6oH/WVtmvUaWutAeGeLIg0ZledkpQzqYIcwQzgUizxQFzYYdfzY0TIXE9asSy 0+f24e0gow1RbHCgFDygMiGp8pzIweEeVBnttpWzR6Wkcvyici+k10srqg/euVpyVyN2 CngRUggLbYdn20Qqnqbvhd45TxthbTw8tUaYKTqKSmg6SANl/YZRaroTHtbd3SV1rwKA HleBhEah8hcpZ2onk9GQqQ8eyEJ/A4ogmo4z5dK3ertRXlnStHk/lnUhU5MkJEVRd271 ATeBg3RupqH+FLq3MrHa+vlUZLj1n9/4oFrtyrXid8XgPjR+gBQ7+z7QeVk+TPHeVUXd 6Vew== X-Gm-Message-State: AOAM5335My9WhiUYDnNgMQVH+qI2zom+Kx+Jkv6dYsitrZJbAPYPYQB1 tQL0XmwqhE6kfqFoUkVxYFu8o610Pnjgig== X-Google-Smtp-Source: ABdhPJwGEhARsW62TeqW9gg6cuuGfE7sm3RwDG44AfN6hM1rv2BfMC2WU0rO28A/YAiQaj6yzoguwQ== X-Received: by 2002:a17:90a:8c82:: with SMTP id b2mr6639564pjo.173.1633625112424; Thu, 07 Oct 2021 09:45:12 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id u24sm102253pfm.85.2021.10.07.09.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 09:45:10 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com, christophm30@gmail.com, oliva@adacore.com, pinskia@gmail.com Subject: [PATCH v2] [PR/target 100316] Allow constant address for __builtin___clear_cache. Date: Fri, 8 Oct 2021 00:45:03 +0800 Message-Id: <20211007164503.53816-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , Cc: Kito Cheng Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" __builtin___clear_cache was able to accept constant address for the argument, but it seems no longer accept recently, and it even not accept constant address which is hold in variable when optimization is enable: ``` void foo3(){ void *yy = (void*)0x1000; __builtin___clear_cache(yy, yy); } ``` So this patch make BEGIN and END accept VOIDmode, like cselib_lookup_mem did per Jim Wilson's suggestion. ``` static cselib_val * cselib_lookup_mem (rtx x, int create) { ... addr_mode = GET_MODE (XEXP (x, 0)); if (addr_mode == VOIDmode) addr_mode = Pmode; ``` Changes v1 -> v2: - Check is CONST_INT intead of cehck mode, no new testcase, since constant value with other type like CONST_DOUBLE will catched by front-end. e.g. Code: ```c void foo(){ __builtin___clear_cache(1.11, 0); } ``` Error message: ``` clearcache-double.c: In function 'foo': clearcache-double.c:2:27: error: incompatible type for argument 1 of '__builtin___clear_cache' 2 | __builtin___clear_cache(1.11, 0); | ^~~~ | | | double clearcache-double.c:2:27: note: expected 'void *' but argument is of type 'double' ``` gcc/ChangeLog: PR target/100316 * builtins.c (maybe_emit_call_builtin___clear_cache): Allow CONST_INT for BEGIN and END. gcc/testsuite/ChangeLog: PR target/100316 * gcc.c-torture/compile/pr100316.c: New. --- gcc/builtins.c | 6 ++++-- gcc/testsuite/gcc.c-torture/compile/pr100316.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr100316.c diff --git a/gcc/builtins.c b/gcc/builtins.c index 3e57eb03af0..8c3ad302468 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5163,8 +5163,10 @@ default_emit_call_builtin___clear_cache (rtx begin, rtx end) void maybe_emit_call_builtin___clear_cache (rtx begin, rtx end) { - if ((GET_MODE (begin) != ptr_mode && GET_MODE (begin) != Pmode) - || (GET_MODE (end) != ptr_mode && GET_MODE (end) != Pmode)) + if ((GET_MODE (begin) != ptr_mode && GET_MODE (begin) != Pmode + && !CONST_INT_P (begin)) + || (GET_MODE (end) != ptr_mode && GET_MODE (end) != Pmode + && !CONST_INT_P (end))) { error ("both arguments to %<__builtin___clear_cache%> must be pointers"); return; diff --git a/gcc/testsuite/gcc.c-torture/compile/pr100316.c b/gcc/testsuite/gcc.c-torture/compile/pr100316.c new file mode 100644 index 00000000000..38eca86f49f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr100316.c @@ -0,0 +1,18 @@ +void foo(){ + __builtin___clear_cache(0, 0); +} + +void foo1(){ + __builtin___clear_cache((void*)0, (void*)0); +} + +void foo2(){ + void *yy = 0; + __builtin___clear_cache(yy, yy); +} + +void foo3(){ + void *yy = (void*)0x1000; + __builtin___clear_cache(yy, yy); +} +