From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id C8A20385840E for ; Fri, 8 Oct 2021 06:43:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8A20385840E Received: by mail-ed1-x52e.google.com with SMTP id t16so10554833eds.9 for ; Thu, 07 Oct 2021 23:43:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=drJRe5w6loSVKLaWKAyJCtUGOgNRK3kE5t6oj9XW9gc=; b=4SUuJ57HQj9CFMz0KomqwXDvYMeUV1UR7oZ/pxydIoOrqjpWLuQmuUPtI5Kai0iJcl 3RbiL+VoFKNXEQkiGc/fAVB371qSNxY/M5CY1r7/QeVwtlvcKY52cYZun7uKqo7BrPt+ nS1IJf4NuyVH1fjZC/Xn7HrZPR5U97U4rRMhFy35CRYAvFA+FGmm1QeUJcouN5XHucad CKmKHN4dMAuKUAEuEieKU5vnvzm1GTujDErfXBDvgiH91lr3y1YV3soE3IqLH65jmfCJ 9o3paLAQjzXIzFOffsxkbEYIwEzt+k4rTAzpESyqbbr7HmqxumEqukRavHiT5EgIKUuP 1dhA== X-Gm-Message-State: AOAM533BA2VOm9bXsv5oL45sCd5xg+KaY/MXyIUva8mE+7UBw4xLMvre nOY6LJVr8qQoCKBiGD+AXbE8Z3zE+AFV8ON0+/Y= X-Google-Smtp-Source: ABdhPJxACuRDilitoynJtG4R/isq5CGbOQ/jOG45/XLdBCu5kHgc7Os3+k4GBHwqzo1bAmF3rDtc00zM+hpEUFdrjOw= X-Received: by 2002:a17:906:69d6:: with SMTP id g22mr1928998ejs.429.1633675433423; Thu, 07 Oct 2021 23:43:53 -0700 (PDT) MIME-Version: 1.0 References: <20211007164503.53816-1-kito.cheng@sifive.com> In-Reply-To: <20211007164503.53816-1-kito.cheng@sifive.com> From: Richard Biener Date: Fri, 8 Oct 2021 08:43:42 +0200 Message-ID: Subject: Re: [PATCH v2] [PR/target 100316] Allow constant address for __builtin___clear_cache. To: Kito Cheng Cc: GCC Patches , Kito Cheng , Jim Wilson , christophm30@gmail.com, Alexandre Oliva , Andrew Pinski Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: , X-List-Received-Date: Fri, 08 Oct 2021 06:43:56 -0000 On Thu, Oct 7, 2021 at 6:45 PM Kito Cheng wrote: > > __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; I don't think it makes sense to emit user-facing diagnostics about this from here, user code calling this go through expand_builtin___clear_cache which performs the check and diagnostic on the argument types which is more appropriate and the code above is eventually called from special backend code directly but that's nothing the user can do anything about. So how about simply removing this check? Thanks, Richard. > 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); > +} > + > -- > 2.33.0 >