From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id B070B3888C57 for ; Fri, 23 Jul 2021 10:54:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B070B3888C57 Received: by mail-ej1-x629.google.com with SMTP id l13so3109969ejo.3 for ; Fri, 23 Jul 2021 03:54:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=beAtVxC+869nC8WElqX32I6ej1I4XT7Wy20Djj4HqO0=; b=SziRh2SlLNNfMk8Gw/jZWua60WdrtAlWHGViHFFR5Z7HKgXySOQPRJ/01DomJSo11y 8nZ4VXCAjx+xyleeuT8sBkBc7rIFzvyrroxjBsDkZjihm9C2NcWoV1JzF+KkKxyhVgdm eZLLUXn21MlXRuxmTPXilm2QSPLDVUR7usTF4xFQXtNjTW4vo3QpNFJz84DmjsgkG+8M i93C8XJZtJJyVXH1UBXo2I7fcMzH3vyfu1qyMW2zzP75MFQsyObC9v4RHNoG8R2W9g/z DKXkdc+WFe826IoN8F8m+JZ72YzXVOktpx4Y8jgY38isk870hypaE0mI2RyzK0hlj1xy 9IbA== X-Gm-Message-State: AOAM532Sq1qWMJYSoaZXCEWcM5XSLcjYYYFMWN5drGcCybXl50LsPiph OcYS16dnNWUV1AVWS52t519+G1RB20pe5KjHa4T9DvhycNI= X-Google-Smtp-Source: ABdhPJxfYvYxaeHQJDB1Yjx9TFq/DJc4zMwLc4uvtaBt73w5tFGeNOkSXePK6CvR9Pp/8FZNRKyUIeFD9Lp05zLaN3g= X-Received: by 2002:a17:907:770f:: with SMTP id kw15mr4013481ejc.23.1627037658407; Fri, 23 Jul 2021 03:54:18 -0700 (PDT) MIME-Version: 1.0 From: Prathamesh Kulkarni Date: Fri, 23 Jul 2021 16:23:42 +0530 Message-ID: Subject: [RFC] Adding a new attribute to function param to mark it as constant To: GCC Development , Richard Earnshaw Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, 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@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2021 10:54:21 -0000 Hi, Continuing from this thread, https://gcc.gnu.org/pipermail/gcc-patches/2021-July/575920.html The proposal is to provide a mechanism to mark a parameter in a function as a literal constant. Motivation: Consider the following intrinsic vshl_n_s32 from arrm/arm_neon.h: __extension__ extern __inline int32x2_t __attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) vshl_n_s32 (int32x2_t __a, const int __b) { return (int32x2_t)__builtin_neon_vshl_nv2si (__a, __b); } and it's caller: int32x2_t f (int32x2_t x) { return vshl_n_s32 (x, 1); } The constraint here is that, vshl_n intrinsics require that the second arg (__b), should be an immediate value. Currently, this check is performed by arm_expand_builtin_args, and if a non-constant value gets passed, it emits the following diagnostic: ../armhf-build/gcc/include/arm_neon.h:4904:10: error: argument 2 must be a constant immediate 4904 | return (int32x2_t)__builtin_neon_vshl_nv2si (__a, __b); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ However, we're trying to replace builtin calls with gcc's C vector extensions where possible (PR66791), because the builtins are opaque to the optimizers. Unfortunately, we lose type checking of immediate value if we replace the builtin with << operator: __extension__ extern __inline int32x2_t __attribute__ ((__always_inline__, __gnu_inline__, __artificial__)) vshl_n_s32 (int32x2_t __a, const int __b) { return __a << __b; } So, I was wondering if we should have an attribute for a parameter to specifically mark it as a constant value with optional range value info ? As Richard suggested, sth like: void foo(int x __attribute__((literal_constant (min_val, max_val))); Thanks, Prathamesh