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 71DF43852C50 for ; Fri, 18 Nov 2022 12:19:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 71DF43852C50 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 2AICIMXt008580; Fri, 18 Nov 2022 06:18:22 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 2AICIMCj008579; Fri, 18 Nov 2022 06:18:22 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Fri, 18 Nov 2022 06:18:22 -0600 From: Segher Boessenkool To: HAO CHEN GUI Cc: David Edelsohn , gcc-patches , "Kewen.Lin" , Peter Bergner Subject: Re: [PATCHv2, rs6000] Enable have_cbranchcc4 on rs6000 Message-ID: <20221118121822.GY25951@gate.crashing.org> References: <438c6628-0b9c-e5d0-e198-2fd6edd16a93@linux.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,KAM_NUMSUBJECT,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 Fri, Nov 18, 2022 at 02:35:30PM +0800, HAO CHEN GUI wrote: > 在 2022/11/17 21:24, David Edelsohn 写道: > > Why are you using zero_constant predicate instead of matching (const_int 0) for operand 2? > The "const_int 0" is an operand other than a predicate. We need a predicate here. Said differently, it is passed as an operand to this named pattern or optab, so you need a match_operand here. > > Why does this need the new all_branch_comparison_operator?  Can the ifcvt optimization correctly elide the 2 insn sequence? > Because rs6000 defines "*cbranch_2insn" insn, such insns are generated after expand. > > (jump_insn 50 47 51 11 (set (pc) > (if_then_else (ge (reg:CCFP 156) > (const_int 0 [0])) > (label_ref 53) > (pc))) "/home/guihaoc/gcc/gcc-mainline-base/gmp/mpz/cmpabs_d.c":80:7 884 {*cbranch_2insn} > (expr_list:REG_DEAD (reg:CCFP 156) > (int_list:REG_BR_PROB 633507684 (nil))) > -> 53) But notice the cost of *cbranch_2insn -- ifcvt should never generate cbranchcc4 with such composite conditions! > In prepare_cmp_insn, the comparison is verified by insn_operand_matches. If > extra_insn_branch_comparison_operator is not included in "cbranchcc4" predicate, > it hits ICE here. > > if (GET_MODE_CLASS (mode) == MODE_CC) > { > enum insn_code icode = optab_handler (cbranch_optab, CCmode); > test = gen_rtx_fmt_ee (comparison, VOIDmode, x, y); > gcc_assert (icode != CODE_FOR_nothing > && insn_operand_matches (icode, 0, test)); > *ptest = test; > return; > } > > The real conditional move is generated by emit_conditional_move_1. Commonly > "*cbranch_2insn" can't be optimized out and it returns NULL_RTX. > > if (COMPARISON_P (comparison)) > { > saved_pending_stack_adjust save; > save_pending_stack_adjust (&save); > last = get_last_insn (); > do_pending_stack_adjust (); > machine_mode cmpmode = comp.mode; > prepare_cmp_insn (XEXP (comparison, 0), XEXP (comparison, 1), > GET_CODE (comparison), NULL_RTX, unsignedp, > OPTAB_WIDEN, &comparison, &cmpmode); > if (comparison) > { > rtx res = emit_conditional_move_1 (target, comparison, > op2, op3, mode); > if (res != NULL_RTX) > return res; > } > delete_insns_since (last); > restore_pending_stack_adjust (&save); > > I think that extra_insn_branch_comparison_operator should be included in > "cbranchcc4" predicates as such insns exist. And leave it to > emit_conditional_move which decides whether it can be optimized or not. I don't think we should pretend we have any conditional jumps the machine does not actually have, in cbranchcc4. When would this ever be useful? cror;beq can be quite expensive, compared to the code it would replace anyway. If something generates those here (which then ICEs later), that is wrong, fix *that*? Is it ifcvt doing it? Segher