Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp109912ybj; Wed, 6 May 2020 12:46:22 -0700 (PDT) X-Google-Smtp-Source: APiQypLSzbBb1qLHEyXvVScUmquzITGu8smhSilowC/ankIfGMgVqD15Ach8xA6B4uBy97igumVm X-Received: by 2002:aa7:da8b:: with SMTP id q11mr8931967eds.359.1588794382663; Wed, 06 May 2020 12:46:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588794382; cv=none; d=google.com; s=arc-20160816; b=wVuWeuLMipxK0QWCnpWpnItsRQz/7f7BIvoHIaY44+lg/L9CeIePrgzbI/QxNaQq1Y CF6vDi31DnHLgn5lBjxHwsKZ/QbBrBmAQf8ai0v+3FwWTn3zYiqzmcOg2ZPz/8K0mGt4 3AZCXWBN9CNyVouKckIvmy4HLGsxyuSDqYQqjk/hU4a1b42+fwDiBB12G+U+uoE6PQgu OWsDltwetHwV66sIE0Rcl1zBVPILRTdstz1wvUA8nkU4NyMfaFON4wSvgws+OLAjK0xB NR7ABvminMy9iJJQLxHOmLhwtLEKYD13qTJp6GxdZtwcz2o01+ivDRCvRYVjdqFdp+bi jioA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=07w3M3fjX49pguIvUyZoChyUZSwRCf3IidBIG7ARz+M=; b=UP4cVRIHnwjxPigt4VDTKiQ8NqzFyJYxByOAXAFDVqZwexWvRZcpl3FdGKLxK3R2SD iu242DcSorNUnEt2sOA1g38Xpia1gpDvtDRxpmpn5ULfRZfg8nJunTy5XX5bWXsk390h wj+iKExdZgsL9lnFx6JjssLH1QxPnfK1eFducqORZDMrfp/B+7KQEbrRxP3icHqlqpJP WajUal5FJYY860qyHlI0CGzmyEZr2tJOEaAkD0ZEcq/a7qRXIb16eYrWbAtrs5Aiw9dF OlYZK8cJm+Wu8PAKyIjJSXo9jIxTG/6TeWzNuAmQvXZhiVmI0OkCGOZug6bkRLk/Dw3q VQMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="Bv/hOfS/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gg16si1893866ejb.310.2020.05.06.12.45.59; Wed, 06 May 2020 12:46:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="Bv/hOfS/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729727AbgEFRRJ (ORCPT + 99 others); Wed, 6 May 2020 13:17:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbgEFRRI (ORCPT ); Wed, 6 May 2020 13:17:08 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E001FC061A0F for ; Wed, 6 May 2020 10:17:07 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id u6so3215171ljl.6 for ; Wed, 06 May 2020 10:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=07w3M3fjX49pguIvUyZoChyUZSwRCf3IidBIG7ARz+M=; b=Bv/hOfS/WKD94FxyU/YzCqrVj0cnpXp1XV6cBa438o2cwpkU6Wr+f350ViQfVa6Pks wl5GeBrkIxOCebVW+g8QQLUTBHtaBKpbeQzuqS1y1aUAfuuPYRirIXsPMGsWo+2i2yP+ 2Y7tG8jeDeIFeF0PTzl6ilF5ps4kaSpbd4RHI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=07w3M3fjX49pguIvUyZoChyUZSwRCf3IidBIG7ARz+M=; b=ls3ocgNOSAqfiVb3NMpNvqkcDe52MN+p4I2LhR5y/pm2FsXRPxIhGxxiKQodmFJEvD XrZ+YgYuOgnuOCFhwABG9zX6BnFafxBj/yY68LPS2Zyzozxn4fIA2i9xQv6fDyZtlibU 1Ohm6JpU007zkCzthbxebbGatJwzvnMCG4JmlvjghqzlX97amqmRhb/P4VWo4KEF830D m3FFuu4kBAgrKCOTBIMcIsoH8Ia5Uh09Hu8qelhhP55RRRCjVLCV6a5PV4AuqPtR8g5j 5b3kZPFuKYrU8N6VDlmzvsosQfhhcCuwpsr7dPO4kAM9jOjXwLlH5AdfUYiGlonzGlzn PUWg== X-Gm-Message-State: AGi0PuaTIKOUMEmPRK89svQy581T5wwHAJazzvtL008OOdEjKVRE8Lp7 t1ja0GdwzP4OeISAt6SiFCUiGviAwWM= X-Received: by 2002:a2e:a292:: with SMTP id k18mr5489575lja.263.1588785425673; Wed, 06 May 2020 10:17:05 -0700 (PDT) Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com. [209.85.208.178]) by smtp.gmail.com with ESMTPSA id o22sm1709115ljj.100.2020.05.06.10.17.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 May 2020 10:17:04 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id b2so3228030ljp.4 for ; Wed, 06 May 2020 10:17:04 -0700 (PDT) X-Received: by 2002:a2e:814e:: with SMTP id t14mr5608093ljg.204.1588785423772; Wed, 06 May 2020 10:17:03 -0700 (PDT) MIME-Version: 1.0 References: <20200501202849.647891881@infradead.org> <20200501202944.593400184@infradead.org> <1238787e-d97d-f09b-d76d-2df2dc273f4b@rasmusvillemoes.dk> <20200503125813.GL3762@hirez.programming.kicks-ass.net> <20200504201445.GQ3762@hirez.programming.kicks-ass.net> <20200505093625.GE5298@hirez.programming.kicks-ass.net> <20200506135128.GR3762@hirez.programming.kicks-ass.net> In-Reply-To: <20200506135128.GR3762@hirez.programming.kicks-ass.net> From: Linus Torvalds Date: Wed, 6 May 2020 10:16:47 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 14/18] static_call: Add static_cond_call() To: Peter Zijlstra Cc: Nick Desaulniers , Rasmus Villemoes , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , LKML , Steven Rostedt , Masami Hiramatsu , Daniel Bristot de Oliveira , Jason Baron , Thomas Gleixner , Ingo Molnar , Nadav Amit , "H. Peter Anvin" , Andy Lutomirski , Ard Biesheuvel , Josh Poimboeuf , Paolo Bonzini , Mathieu Desnoyers , "H.J. Lu" , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 6, 2020 at 6:51 AM Peter Zijlstra wrote: > > I was hoping for: > > bar: # @bar > movl %edi, .L_x$local(%rip) > retq > ponies: # @ponies > movq .Lfoo$local(%rip), %rax > testq %rax, %rax > jz 1f > jmpq *%rcx # TAILCALL > 1: > retq If you want to just avoid the 'cmov', the best way to do that is to insert a barrier() on one side of the if-statement. That breaks the ability to turn the conditional jump into a cmov. HOWEVER. It looks like noth clang and gcc will move the indirect jump to the conditional sites, but then neither of them is smart enough to just turn the indirect jump into one direct jump. Strange. So you still get an indirect call for just the "ret" case. The code looks actively stupid with gcc: .L7: movl $__static_call_nop, %eax jmp *%rax clang: .LBB1_1: mov eax, offset __static_call_nop jmp rax # TAILCALL despite the barrier not being between those two points. The only difference is the assembler syntax. Odd. That's such a trivial and obvious optimization. But presumably it's a pattern that just doesn't happen normally. Linus