From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id 9BAF43852777 for ; Wed, 13 Jul 2022 07:42:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9BAF43852777 Received: by mail-qv1-xf2c.google.com with SMTP id m10so3028955qvu.4 for ; Wed, 13 Jul 2022 00:42:04 -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=y39S1LNwKidxptEq+s2N92+JKvtKIX+oW/zDhg9sP5E=; b=cSmlFsCvAjQQwqhV2FtK7snVuizVH9kYKST2OqfU4OSPl2BUf40gOtE6veeB39ZICp V7di5DrxGP39d26PDLzeBTu/3fR2K9SR5zoveqrOu64DANfI3uY5KCRmej6s2Y7bsnUH 2Jo9ssn5GaQSOP3LKv8qMG7Qiqwxjv/qUiCxunheKnodDHZvlYdpV5vT0gv8SucVtztW PRSp5YVJfR/4SmRe93ow5HmXc/J4AXVbqbYj/k3joy+OVfA4H2b1CjatB/BLTW3uQbjX U5KX//Zo4UZZFExbw3jNtbJFknh5HrzNDJsGXy8XoF6cPPmUOtChCFz2KAYLGkK7UIcL CGcA== X-Gm-Message-State: AJIora/RJ4zTy7LfWHHgvU6Gb8UjaBYHqcw0Yx9fQxAdl4TICyvQPGO2 coYn78eeKoBf/3iKeKiTYPT4uYjEL998cHA+pyjDORh7 X-Google-Smtp-Source: AGRyM1uC6OEPKgvVLEq7nR5LNwf64qxNM8wEnMEFO9jNk8JWN66/jypOzw+F757gAUYpSTtXMqzShQQEz4FV/+Rdj+o= X-Received: by 2002:a05:6214:260b:b0:473:6ef4:491b with SMTP id gu11-20020a056214260b00b004736ef4491bmr1715553qvb.34.1657698123993; Wed, 13 Jul 2022 00:42:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Wed, 13 Jul 2022 09:41:52 +0200 Message-ID: Subject: Re: [PATCH v2 1/2] aarch64: Don't return invalid GIMPLE assign statements To: Andrew Carlotti Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.2 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, T_SCC_BODY_TEXT_LINE 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jul 2022 07:42:07 -0000 On Tue, Jul 12, 2022 at 4:38 PM Andrew Carlotti wrote: > > aarch64_general_gimple_fold_builtin doesn't check whether the LHS of a > function call is null before converting it to an assign statement. To avoid > returning an invalid GIMPLE statement in this case, we instead assign the > expression result to a new (unused) variable. > > This change only affects code that: > 1) Calls an intrinsic function that has no side effects; > 2) Does not use or store the value returned by the intrinsic; > 3) Uses parameters that prevent the front-end eliminating the call prior to > gimplification. > > The ICE is unlikely to have occurred in the wild, as it relies on the presence > of a redundant intrinsic call. Other targets usually simply refrain from folding intrinsic calls with no LHS. Another option is to just drop it on the floor if it does not have any side-effects which for the gimple_fold_builtin hook means folding it to a GIMPLE_NOP (gimple_build_nop ()). > gcc/ChangeLog: > > * config/aarch64/aarch64-builtins.cc > (aarch64_general_gimple_fold_builtin): Add fixup for invalid GIMPLE. > > gcc/testsuite/ChangeLog: > > * gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c: New test. > > --- > > diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc > index e0a741ac663188713e21f457affa57217d074783..5753988a9964967c27a03aca5fddb9025fd8ed6e 100644 > --- a/gcc/config/aarch64/aarch64-builtins.cc > +++ b/gcc/config/aarch64/aarch64-builtins.cc > @@ -3022,6 +3022,16 @@ aarch64_general_gimple_fold_builtin (unsigned int fcode, gcall *stmt, > default: > break; > } > + > + /* GIMPLE assign statements (unlike calls) require a non-null lhs. If we > + created an assign statement with a null lhs, then fix this by assigning > + to a new (and subsequently unused) variable. */ > + if (new_stmt && is_gimple_assign (new_stmt) && !gimple_assign_lhs (new_stmt)) > + { > + tree new_lhs = make_ssa_name (gimple_call_return_type (stmt)); > + gimple_assign_set_lhs (new_stmt, new_lhs); > + } > + > return new_stmt; > } > > diff --git a/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c > new file mode 100644 > index 0000000000000000000000000000000000000000..345307456b175307f5cb22de5e59cfc6254f2737 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/aarch64/advsimd-intrinsics/ignored_return_1.c > @@ -0,0 +1,9 @@ > +/* { dg-do compile { target { aarch64*-*-* } } } */ > + > +#include > + > +int8_t *bar(); > + > +void foo() { > + __builtin_aarch64_ld1v16qi(bar()); > +}