From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 031373858D28 for ; Mon, 11 Oct 2021 06:16:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 031373858D28 Received: by mail-ed1-x535.google.com with SMTP id z20so63209255edc.13 for ; Sun, 10 Oct 2021 23:16:07 -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:content-transfer-encoding; bh=/s3PKrXTP7u8KabZFNvkgf50Yy02RxgdYL9rtNJg66Y=; b=qPGFMvEgwwsdUdyvkEhtMFQoVUSVk4w4uJpXY8SUBTQjJNh5P55ZRD1/p3F1JZBx8g 7LAkJlb7sbWYrwIsbdE5eZ/2unkqTpLyBeFIrPOEkPlXvDJ7btTKvx7LCrw/fh85GR3B ayINu8Y0+utF+UrPaG/g/Os1wtYNyvChAUuZTutMOldNBuqd2OEhqgvGNroLSbWA10cl nxIWotQaTOh40U7LixZaC57rOhd6cDy3PB+d17kujZsGxywHJekmVTy0UH0WZRsICihV PgPoGRdBkDamscPx83B8XO48KSoNTOmj9hioY6PQ40l8LtEpzyAbfTHT/hgslOjgvvxg 2SDw== X-Gm-Message-State: AOAM5329nU0gTi5HCfGZBLgP58Iy3qixbHf7Br5OG7CMEdv+6ZWyt91S 5M7L6R2oM8ZwBq5R9IRY2gKHmCF3A5w3SsgUJc4= X-Google-Smtp-Source: ABdhPJwJ3xmbHWfQAajp+P4ZK6/Nvif31E1Uzcz1O4qFwPdl7H1G0GRPr3du/q1I9D17jfckg96qQhHF54mUXVEhme8= X-Received: by 2002:a17:906:6087:: with SMTP id t7mr23511691ejj.206.1633932966788; Sun, 10 Oct 2021 23:16:06 -0700 (PDT) MIME-Version: 1.0 References: <20211008024016.2625-1-kito.cheng@sifive.com> In-Reply-To: From: Kito Cheng Date: Mon, 11 Oct 2021 14:15:55 +0800 Message-ID: Subject: Re: [PATCH v3] [PR/target 100316] Allow constant address for __builtin___clear_cache. To: Kito Cheng Cc: Richard Biener , Alexandre Oliva , GCC Patches , christophm30@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.2 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: Mon, 11 Oct 2021 06:16:09 -0000 Committed to trunk :) On Mon, Oct 11, 2021 at 11:23 AM Kito Cheng wrote: > > Hi Richard: > > Test with x86 and rl78, both are rejected by the front-end if modes > are different from Pmode/ptr_mode, > so I'm gonna commit this change :) > > Testcase for x86 / x86_64: > ``` > void test(void) > { > int __seg_fs *f =3D (int __seg_fs *)16; > int __seg_fs *g =3D (int __seg_fs *)32; > __builtin___clear_cache (f, g); // error: passing argument 1 of > =E2=80=98__builtin___clear_cache=E2=80=99 from pointer to non-enclosed ad= dress space > } > ``` > > Testcase for rl78 (Pmode =3D=3D HImode): > ``` > void test(void) > { > int __near *f =3D (int __near *)16; // mode =3D=3D HImode, same as Pmod= e > int __near *g =3D (int __near *)32; > __builtin___clear_cache (f, g); // OK to compile > } > > void test2(void) > { > int __far *f =3D (int __far *)16; // mode =3D=3D SImode > int __far *g =3D (int __far *)32; > __builtin___clear_cache (f, g); // error: passing argument 1 of > =E2=80=98__builtin___clear_cache=E2=80=99 from pointer to non-enclosed ad= dress space > } > ``` > > On Fri, Oct 8, 2021 at 2:47 PM Richard Biener > wrote: > > > > On Fri, Oct 8, 2021 at 4:40 AM 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 i= s > > > enable: > > > > > > ``` > > > void foo3(){ > > > void *yy =3D (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 =3D GET_MODE (XEXP (x, 0)); > > > if (addr_mode =3D=3D VOIDmode) > > > addr_mode =3D Pmode; > > > ``` > > > > > > Changes v2 -> v3: > > > - Use gcc_assert rather than error, maybe_emit_call_builtin___clear_c= ache is > > > internal use only, and we already checked the type in other place. > > > > > > 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, and use gcc_assert rather than > > > error. > > > > > > gcc/testsuite/ChangeLog: > > > > > > PR target/100316 > > > * gcc.c-torture/compile/pr100316.c: New. > > > --- > > > gcc/builtins.c | 10 ++++------ > > > gcc/testsuite/gcc.c-torture/compile/pr100316.c | 18 ++++++++++++++++= ++ > > > 2 files changed, 22 insertions(+), 6 deletions(-) > > > create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr100316.c > > > > > > diff --git a/gcc/builtins.c b/gcc/builtins.c > > > index 3e57eb03af0..80a1bb191c6 100644 > > > --- a/gcc/builtins.c > > > +++ b/gcc/builtins.c > > > @@ -5163,12 +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) !=3D ptr_mode && GET_MODE (begin) !=3D Pmode= ) > > > - || (GET_MODE (end) !=3D ptr_mode && GET_MODE (end) !=3D Pmode)= ) > > > - { > > > - error ("both arguments to %<__builtin___clear_cache%> must be = pointers"); > > > - return; > > > - } > > > + gcc_assert ((GET_MODE (begin) =3D=3D ptr_mode || GET_MODE (begin) = =3D=3D Pmode > > > + || CONST_INT_P (begin)) > > > + && (GET_MODE (end) =3D=3D ptr_mode || GET_MODE (end) = =3D=3D Pmode > > > + || CONST_INT_P (end))); > > > > OK I guess. > > > > I'm not 100% sure we might not ICE here when using > > __builtin_clear_cache on a pointer > > with some other than the default address-space which might have a mode > > that's not > > ptr_mode or Pmode? > > > > Thanks, > > Richard. > > > > > if (targetm.have_clear_cache ()) > > > { > > > diff --git a/gcc/testsuite/gcc.c-torture/compile/pr100316.c b/gcc/tes= tsuite/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 =3D 0; > > > + __builtin___clear_cache(yy, yy); > > > +} > > > + > > > +void foo3(){ > > > + void *yy =3D (void*)0x1000; > > > + __builtin___clear_cache(yy, yy); > > > +} > > > + > > > -- > > > 2.33.0 > > >