From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 688703858C55; Thu, 14 Jul 2022 13:50:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 688703858C55 Received: by mail-ej1-x634.google.com with SMTP id mf4so3558566ejc.3; Thu, 14 Jul 2022 06:50:57 -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=/3Nh1olrIDreiYUn5gqZmZmcJQEr634Af7PmzpqDWac=; b=W7pN+mpgzGRdNejIkJngbu+TbsLjPRoQx7+8Zp0wkFDvJ8ZTgJ2DNMP0T95F8Pf3Zf YSr0z23+hyxfGk7Bp5HNTJZTqo7XuJLjv3kCtaHT6JWE0FSkXqlzBBtJepGgafEleGRi i5N8GQx+LnSdFntk5fLtJOiIEJFoL+ZnQ+45OfTT1L05+Cb4DldavB7KwYrKgc2Glmn/ /sevyDpZtsLzG4vr5SRGG1oYR2rzHgdRNfM2mTwrasW9341EHkXerVRuP5FMPezPnPq1 +wkwpo/B+ZFYUHTT6WhBnu6aWZkjD2T8BwOEI9SS5KzFgrfE+EHqRBgBicmWO1d3JoiC RCNw== X-Gm-Message-State: AJIora+2pr76hri+TKUrXk5S0AqOC5+SScIOHLXTFvEzcMKKYPI65UAJ wgY2eaD0KY785LsmHe0kYb4cn6qDxUYCGexNApDGpSLX X-Google-Smtp-Source: AGRyM1sfxC6Ms9/Mlv7VEExSmw5T/1iu0f5gPnlcunwEyFC2SzlQm32IK0mqPH9ZUNhDz3Io1rGIrJXbtywGrpQ7u0k= X-Received: by 2002:a17:906:c5:b0:722:e65d:770d with SMTP id 5-20020a17090600c500b00722e65d770dmr9004904eji.330.1657806655311; Thu, 14 Jul 2022 06:50:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Thu, 14 Jul 2022 15:50:43 +0200 Message-ID: Subject: Re: Creating a wrapper around a function at compile time To: Erick Ochoa Cc: GCC Development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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@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: Thu, 14 Jul 2022 13:50:59 -0000 On Thu, Jul 14, 2022 at 3:42 PM Erick Ochoa wrote: > > Hi Richard, > > >> > >> > So instead of wrapping the function why not transform the original fun= ction >> > to have a prologue doing a runtime check for the compile-time speciali= zed >> > versions and perform tail-calls to them? >> > >> > What I'm missing is who would call mul_test_param in your case? > > > The idea is that all callsites to mul may call instead mul_test_param or = only those for which there is no known compile time constant. If we had som= e more information about the distribution of the parameter values at runtim= e, then we could even choose not to use the wrapper. > >> >> Following your variant more closely would be doing value profiling >> of function parameters and then "speculative IPA-CP". > > > Yes, the idea of doing value profiling on function parameters certainly f= its this very well. I refrained from calling it "speculative IPA-CP" and in= stead called it specialization with a parameter test but the idea I think i= s the same. However, the main difference between "speculative IPA-CP" and t= his idea is that (if I understand correctly how speculative IPA-CP works) i= s that instead of changing the callsite C to the following version: > > C: mul_test_param (c, d); > > speculative IPA-CP will have the transformation > > C: if (a =3D=3D 2) mul.constprop1 (a) > else if (a =3D=3D 4) mul.constprop2 (a) > else mul (a, b) > > Which depending on how many non compile-time constant callsites there are= , will increase the size of the binary. That's why I prefer the wrapper aro= und the function. But this would be essentially inlining the wrapper. With a value-profile it would be per call site and IPA-CP can use that to direct the cloning. I'm not sure how many values a value histogram can track reliably here. > > As of now, the only "speculative IPA-CP" that I've seen is the speculatio= n on the target of the indirect edge. I could look into exactly how this me= chanism works to try to instead speculate on an arbitrary argument. Do you = think that would be a good first step instead of creating a wrapper and rep= lacing the edges to the wrapper?