From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AB3733858C5E for ; Mon, 4 Dec 2023 08:35:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB3733858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AB3733858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701678945; cv=none; b=Th6t/iUCqcdvsSSf8V9hQn2BnSj4we3VlPe3lKBl+Vua8x2U2V6N7ctuTXspvtaAXileRAscpg1c3Ye6mszR2p/7pUoiiBB8tt6fuF6aUhRiFOxmmNvLgytlcw6xmOpvm5Q2c5TByG2gToE7+JYGdhU8uBefvL7cyy4z40Yeqp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701678945; c=relaxed/simple; bh=xtqSa8uQS3iL3y8AUBgSsrco7+5Kir4WMegPUr3EiD4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=iJFzwO6wNKeJi6Sw7+/M6IFz0zwyBHfld6M7UHZVV33c2m7LvXiazxYdjORR0YhAnakASllkUVNBu34v2wba4tSkT81lyxRreLkhnf6dz0+k82ltftNOBCwAfj690QvROgRm5jOub+UXd7yoHwd6muF0cWrytl+kZxwOUSBYZEY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701678943; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=tBo+9uD6FuzPIzsH+c+y3z+8Y6tuZBaS0F8XAvTOwjM=; b=eKGXoHeL1LdWQ7yHL3c5TYPNqhZJD+j1TpI+nIIm426Q2H1UOceh8YCOXbaoqCo9bgRXi6 oArKXkxgEZwAvSTiLB6+9UUYfcJwdP3r5359DfjK6q5PGqzSahxHEbfuuks+dPqu21ALiZ F29ltPyZKktawMivD1n1EeR0oRPSZzM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-uXMIdqXGNY2r9hXkti2hug-1; Mon, 04 Dec 2023 03:35:41 -0500 X-MC-Unique: uXMIdqXGNY2r9hXkti2hug-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6BF4C811E7B; Mon, 4 Dec 2023 08:35:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 39A28492BFE; Mon, 4 Dec 2023 08:35:40 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3B48ZbcP2150735 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 4 Dec 2023 09:35:37 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B48ZZAE2150734; Mon, 4 Dec 2023 09:35:35 +0100 Date: Mon, 4 Dec 2023 09:35:35 +0100 From: Jakub Jelinek To: "Kewen.Lin" , Segher Boessenkool , David Edelsohn Cc: gcc-patches@gcc.gnu.org Subject: Patch ping: [PATCH] rs6000: Canonicalize copysign (x, -1) back to -abs (x) in the backend [PR112606] Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: Hi! I'd like to ping this patch. Thanks On Sat, Nov 25, 2023 at 11:17:48AM +0100, Jakub Jelinek wrote: > The middle-end has been changed quite recently to canonicalize > -abs (x) to copysign (x, -1) rather than the other way around. > While I agree with that at GIMPLE level, since it matches the GIMPLE > goal of as few operations as possible for a canonical form (-abs (x) > is 2 GIMPLE statements, copysign (x, -1) is just one), I must say > I don't really like that being done on RTL as well (or at least > not canonicalizing (COPYSIGN x, negative) back to (NEG (ABS x))), > because on most targets most of floating point constants need to be loaded > from memory, there are a few exceptions but -1 is often not one of them. > > Anyway, the following patch fixes the rs6000 regression caused by the > change in GIMPLE canonicalization (i.e. the desirable one). As rs6000 > clearly prefers -abs (x) form because it has a single instruction to do > that while it also has copysign instruction, but that requires loading the > -1 from memory, the following patch just ensures the copysign expander > can actually see the floating point constant and in that case emits the > -abs (x) code (or in the hypothetical case of copysign with non-negative > constant abs (x) - but there copysign (x, 1) in GIMPLE is canonicalized > to abs (x)), otherwise forces the operand to be the expected gpc_reg_operand > and does what it did before. > > Bootstrapped/regtested on powerpc64le-linux, ok for trunk? > > 2023-11-25 Jakub Jelinek > > PR target/112606 > * config/rs6000/rs6000.md (copysign3): Change predicate > of the last argument from gpc_reg_operand to any_operand. If > operands[2] is CONST_DOUBLE, emit abs or neg abs depending on > its sign, otherwise if it doesn't satisfy gpc_reg_operand, > force it to REG using copy_to_mode_reg. > > --- gcc/config/rs6000/rs6000.md.jj 2023-10-13 19:34:43.927834877 +0200 > +++ gcc/config/rs6000/rs6000.md 2023-11-24 18:54:13.587876170 +0100 > @@ -5358,7 +5358,7 @@ (define_expand "copysign3" > (set (match_dup 4) > (neg:SFDF (abs:SFDF (match_dup 1)))) > (set (match_operand:SFDF 0 "gpc_reg_operand") > - (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand") > + (if_then_else:SFDF (ge (match_operand:SFDF 2 "any_operand") > (match_dup 5)) > (match_dup 3) > (match_dup 4)))] > @@ -5369,6 +5369,24 @@ (define_expand "copysign3" > || TARGET_CMPB > || VECTOR_UNIT_VSX_P (mode))" > { > + /* Middle-end canonicalizes -fabs (x) to copysign (x, -1), > + but PowerPC prefers -fabs (x). */ > + if (CONST_DOUBLE_AS_FLOAT_P (operands[2])) > + { > + if (real_isneg (CONST_DOUBLE_REAL_VALUE (operands[2]))) > + { > + operands[3] = gen_reg_rtx (mode); > + emit_insn (gen_abs2 (operands[3], operands[1])); > + emit_insn (gen_neg2 (operands[0], operands[3])); > + } > + else > + emit_insn (gen_abs2 (operands[0], operands[1])); > + DONE; > + } > + > + if (!gpc_reg_operand (operands[2], mode)) > + operands[2] = copy_to_mode_reg (mode, operands[2]); > + > if (TARGET_CMPB || VECTOR_UNIT_VSX_P (mode)) > { > emit_insn (gen_copysign3_fcpsgn (operands[0], operands[1], Jakub