From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id 292B43858CDB for ; Fri, 28 Oct 2022 21:33:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 292B43858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 29SLWpVq005733; Fri, 28 Oct 2022 16:32:51 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 29SLWo9Q005732; Fri, 28 Oct 2022 16:32:50 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 28 Oct 2022 16:32:49 -0500 From: Segher Boessenkool To: "H.J. Lu" Cc: gcc-patches@gcc.gnu.org, Uros Bizjak Subject: Re: [PATCH] x86: Replace ne:CCC/ne:CCO with UNSPEC_CC_NE in neg patterns Message-ID: <20221028213249.GG25951@gate.crashing.org> References: <20221026185857.234023-1-hjl.tools@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221026185857.234023-1-hjl.tools@gmail.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=no 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 Wed, Oct 26, 2022 at 11:58:57AM -0700, H.J. Lu via Gcc-patches wrote: > In i386.md, neg patterns which set MODE_CC register like > > (set (reg:CCC FLAGS_REG) > (ne:CCC (match_operand:SWI48 1 "general_reg_operand") (const_int 0))) > > can lead to errors when operand 1 is a constant value. If FLAGS_REG in But it cannot be. general_reg_operand will not allow that: === (define_predicate "general_reg_operand" (and (match_code "reg") (match_test "GENERAL_REGNO_P (REGNO (op))"))) === > (set (reg:CCC FLAGS_REG) > (ne:CCC (const_int 2) (const_int 0))) > > is set to 1, RTX simplifiers may simplify "is set to 1"? Do you mean you do something like (set (regs FLAGS_REG) (const_int 1)) ? That is invalid RTL, as I've said tens of time in the last few weeks. > which leads to incorrect results since LTU on MODE_CC register isn't the > same as "unsigned less than" in x86 backend. The special notation (ltu (reg:CC) (const_int 0)) is not about comparing anything to 0, but simply means "did the comparison-like thing that set that reg say ltu was true". > To prevent RTL optimizers > from setting MODE_CC register to a constant, use UNSPEC_CC_NE to replace > ne:CCC/ne:CCO when setting FLAGS_REG in neg patterns. This is an indirect workaround, nothing more. The unspec will naturally not be folded to anything else (unless you arrange for that yourself), there is nothing the generic code knows about the semantics of any unspec after all. AFIACS there is no way to express overflow in a CC, but an unspec can help, sure. You need to fix the setter side as well though. Segher