From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id B0F743858284 for ; Wed, 29 Nov 2023 12:01:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0F743858284 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B0F743858284 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701259305; cv=none; b=iiBX6S66NWVDGIB2y2rL3B5DDBT7pV5bO0dk28OyAQSelSLoLADESK3kCm7yOw1iFmIG12VDC9UowBAomtMRP4AsOPl1tD2FBiorEH/XS+g2igvIjb+W89EJCcDYm0xdJAtM9kf/kh5JippfAAP1SCtDEogOEbAy8a+o4co3DCQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701259305; c=relaxed/simple; bh=IIa2rwHt5X6GUTNocMIWUt8eXXm4MlFdaaW54pSujxU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=m9LEtujO2PJYN6ZUdaN30NnhYnPH0VidkQKGj7Xs4Y7/3f25pWBZyFUQqkHAmnOA1zo8lW0thqD41iU8GquVIu5ZQ2k82s49U3wWqo0TlddUIuVOJK89f5ngo1JPy/xRIf57+23LLf30s/Rd44zNxht9P4N9+oWKH62LgBYiETo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40b538d5c4eso3681015e9.1 for ; Wed, 29 Nov 2023 04:01:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1701259302; x=1701864102; darn=gcc.gnu.org; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=tBeUYj1AnoO/gOOIAvTns1y/UQEybJY6bP2pGOxvqvY=; b=JhD8SoxelKRF67mBuETbaHRqJMelY2aup0pKnNE2zSALA+vMmX5s5azohXRH3rd5va Eaj2TpHrSM0O/nyVseMghMlgm8IWsKSnbLAuSHAZKDOUXn5p5dTox8vrKPYcF6rBig0e 1S4bIgfbsAvBxsMbOEw+6mGNzi8sSoUjIrK1Sv7eBVOvIDLHTypf8YPt3Ip6dOpSuvvg AAfahT2YzD7hDUE4Bp60r0ijchK9HcQ7RKm0IQg+YPmEpoztjxhdyzJmvQtoB6y9AuuP M9wC0lLUSuH3VERNNNOo4ufNwsWVgQjaV6GpVJg9+BGV0wWb8SisSW37lPB/SgF8thN/ 27jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701259302; x=1701864102; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tBeUYj1AnoO/gOOIAvTns1y/UQEybJY6bP2pGOxvqvY=; b=eUynFcIi8f67O6TltJZ7Yghqz4TuUDvZDnR0gEVX0GozMNJlOOW5ZOGoIWZjUiRzAP AW+IssoX7p0srAO+9O+xXhPylm0kSQ3Op+56QU47UO9iCoCBS6wmgzufk+H99qYuza2w 7Skw0eIRWpLJqKoHGBLi4frO8Zl9Tqk+HeG35HLqjNfUMVbAAF8O4hvRTY4OlYeN5Yoz hbnbMJ/X+GYjq9Mk+1KKvTnbUu+atYOa1Nueyj/rSTxkj/w9KFdsuEVS7jcmErOjjyMn Na9i86q70HXUXumtIfccdAp51WzOk5bYYrw0r79mzoHrhNs9RV13nTrf3WRhUR+et+6w 4PEQ== X-Gm-Message-State: AOJu0YyvU9kSkMj/dt1MN+8fvPvOg6KUYjwpYFxYFhn2Fqz9aIWrnrPb JdczW6BcBap4uU8xQyHlkEGC0Q== X-Google-Smtp-Source: AGHT+IHpvf0oWiA2RzNm9CoPlDEOqFK8LbHJ1mghGx6RQaj6FqUKj43GC/4VhQEzvVaXMWaKh/dz7Q== X-Received: by 2002:a05:600c:3c9d:b0:40b:3645:4678 with SMTP id bg29-20020a05600c3c9d00b0040b36454678mr13239248wmb.19.1701259302181; Wed, 29 Nov 2023 04:01:42 -0800 (PST) Received: from tpp.orcam.me.uk (tpp.orcam.me.uk. [2001:8b0:154:0:ea6a:64ff:fe24:f2fc]) by smtp.gmail.com with ESMTPSA id h15-20020a05600c314f00b004083a105f27sm1963993wmo.26.2023.11.29.04.01.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Nov 2023 04:01:41 -0800 (PST) Date: Wed, 29 Nov 2023 12:01:39 +0000 (GMT) From: "Maciej W. Rozycki" To: Jeff Law cc: gcc-patches@gcc.gnu.org, Andrew Waterman , Jim Wilson , Kito Cheng , Palmer Dabbelt Subject: Re: [PATCH 09/44] RISC-V: Rework branch costing model for if-conversion In-Reply-To: <86917a66-8442-49d5-a2f2-fb8b991ccaf3@gmail.com> Message-ID: References: <7ec2ebde-9242-4907-85d9-d76e84bea5ec@gmail.com> <86917a66-8442-49d5-a2f2-fb8b991ccaf3@gmail.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On Tue, 28 Nov 2023, Jeff Law wrote: > FWIW, I was looking at a regression with our internal tests after your > changes. It was quite nice to see how well twiddling -mbranch-cost > correlated to how many instructions we would allow in a conditional move > sequence. I'm a bit concerned though that our interpretation of `-mbranch-cost=0' is different from the middle end's, such as in `emit_store_flag': /* If we reached here, we can't do this with a scc insn, however there are some comparisons that can be done in other ways. Don't do any of these cases if branches are very cheap. */ if (BRANCH_COST (optimize_insn_for_speed_p (), false) == 0) return 0; > The downside is it highlighted the gimple vs RTL use issue. I'm confident > that we would like to see a higher branch cost in the RTL phases for our > uarch, but I'm much less comfortable with how that's going to change the > decisions made in trees/gimple. We'll have to investigate that at some depth. Ack. > > I've looked at it already and it's the middle end that ends up with the > > zero-extension, specifically `convert_move' invoked from `emit_cstore' > > down the call to `noce_try_store_flag_mask', to widen the output from > > `cstoredi4', so I don't think we can do anything in the backend to prevent > > it from happening. And neither I think we can do anything useful about > > `cstoredi4' having a SImode output, as it's a pattern matched by name > > rather than RTX, so we can't provide variants having a SImode and a DImode > > output each both at a time, as that would cause a name clash. > We're actually tracking some of these extraneous extensions. Do you happen to > know if the zero-extended object happens to be (subreg:SI (reg:DI)) kind of > construct? That's the kind of thing we're chasing down right now from various > points. Vineet has already fixed one class of them. Jivan and I are looking > at others. Under GDB it's a plain move from (reg:SI 140) to (reg:DI 139), as in the FROM and TO arguments to `convert_move' respectively. This makes it call `convert_mode_scalar', which then chooses between `zext_optab' and `sext_optab' as appropriate, under: /* If the target has a converter from FROM_MODE to TO_MODE, use it. */ to produce: (set (reg:DI 139) (zero_extend:DI (reg:SI 140))) ending up with this complete sequence: (insn 27 0 28 (set (reg:SI 140) (eq:SI (reg/v:DI 137 [ c ]) (const_int 0 [0]))) -1 (nil)) (insn 28 27 29 (set (reg:DI 139) (zero_extend:DI (reg:SI 140))) -1 (nil)) (insn 29 28 30 (set (reg:DI 141) (neg:DI (reg:DI 139))) -1 (nil)) (insn 30 29 0 (set (reg/v:DI 134 [ ]) (and:DI (reg/v:DI 135 [ a ]) (reg:DI 141))) -1 (nil)) passed to `targetm.noce_conversion_profitable_p' right away. Maybe you can teach `emit_cstore' or `convert_move' to use a subreg when it is known for the particular target that the value produced by the conditional-set machine instruction emitted by `cstoreMODE4' is valid unchanged in both modes. You can fiddle with it by trying: $ gcc -march=rv64gc -mbranch-cost=3 -O2 -S gcc/testsuite/gcc.target/riscv/pr105314.c Set a breakpoint at `noce_try_store_flag_mask' and then single-step to see how things proceed. Maciej