From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id EFEFF3858D37 for ; Mon, 23 Oct 2023 16:23:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFEFF3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFEFF3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698078219; cv=none; b=x6uS6O73wijVmmOdO3eWSjSmvdax6TdWgvTv1khN7VcmJeQ3lML0OMnyezEIX5mnXpEveC2en0kWA/ZedtpxnVgHBNq6cAozElbZmpbwC+wDOVIrFeZC2co1mg5KXhZcTppExib+QO6gYBhGJh0c5Ub1do5lDAv9iH8TrI2bEKk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698078219; c=relaxed/simple; bh=seyTn3MEXfvPfj05XFePkN61/oYwGN6wqSmEfFdlHEM=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=hs3d7AnhDdLwimJNBd8lr5ZXzuAQdZ6qSmWztxBRGXxHAyAVEYM4G/mlerjdjUU74xJznQnAa/SVYQJJAUXnkVJRdSMer6dwL9vQtMUJgSIaYB47K7sQtBlXWE47eSb5GoOPkcAorYoRe1q2os3n3EynZe2zkSvR7eiidsx4hEA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id A865540755E8; Mon, 23 Oct 2023 16:23:36 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru A865540755E8 Date: Mon, 23 Oct 2023 19:23:36 +0300 (MSK) From: Alexander Monakov To: Xi Ruoyao cc: Georg-Johann Lay , gcc-help@gcc.gnu.org Subject: Re: Why gcc's code is so much slower than clang's? In-Reply-To: Message-ID: <745d05e8-501d-7b0b-36b7-17e426fa4221@ispras.ru> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, 23 Oct 2023, Xi Ruoyao via Gcc-help wrote: > GCC even uses branch instead of cmov for: > > int test(int x) > { > return x & 1 ? 3 * x + 1 : x / 2; > } > > Should we create a ticket in bugzilla or is there some reason not to use > cmov here? There's a long-standing problem that RTL if-conversion passes do not emit important information such as estimated costs and attempted transforms, so it's impossible to say if it's "working as designed" without gdb'ing the compiler. I suspect something is not working as it should on this example. In general: For predictable branches, cmov can stitch computations into one long dependency chain, making the resulting code latency-bound. For unpredictable branches, cmov avoids the costs resulting from mispredictions. The compiler cannot tell if a branch is going to be well-predictable or not. My view is that compilers should offer __builtin_branchless_select so people can express what they need. So far it didn't happen. LLVM offers __builtin_unpredictable, which in my eyes is just an indirect way to request branchless code. Alexander