From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id B95C53857C53 for ; Mon, 12 Jul 2021 09:39:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B95C53857C53 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4551B1FB; Mon, 12 Jul 2021 02:39:08 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D2663F694; Mon, 12 Jul 2021 02:39:07 -0700 (PDT) From: Richard Sandiford To: Tamar Christina Mail-Followup-To: Tamar Christina , Richard Biener , nd , "gcc-patches\@gcc.gnu.org" , richard.sandiford@arm.com Cc: Richard Biener , nd , "gcc-patches\@gcc.gnu.org" Subject: Re: [PATCH 1/4]middle-end Vect: Add support for dot-product where the sign for the multiplicant changes. References: <7q3oonr2-92r0-8o9q-s27q-9r735s4n3s3@fhfr.qr> Date: Mon, 12 Jul 2021 10:39:06 +0100 In-Reply-To: (Tamar Christina's message of "Mon, 12 Jul 2021 09:18:17 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2021 09:39:10 -0000 Tamar Christina writes: > Hi, > >> Richard Sandiford writes: >> >> @@ -992,21 +1029,27 @@ vect_recog_dot_prod_pattern (vec_info >> *vinfo, >> >> /* FORNOW. Can continue analyzing the def-use chain when this stmt in >> a phi >> >> inside the loop (in case we are analyzing an outer-loop). */ >> >> vect_unpromoted_value unprom0[2]; >> >> + enum optab_subtype subtype = optab_vector; >> >> if (!vect_widened_op_tree (vinfo, mult_vinfo, MULT_EXPR, >> WIDEN_MULT_EXPR, >> >> - false, 2, unprom0, &half_type)) >> >> + false, 2, unprom0, &half_type, &subtype)) >> >> + return NULL; >> >> + >> >> + if (subtype == optab_vector_mixed_sign >> >> + && TYPE_UNSIGNED (unprom_mult.type) >> >> + && TYPE_PRECISION (half_type) * 4 > TYPE_PRECISION >> >> + (unprom_mult.type)) >> >> return NULL; >> > >> > Isn't the final condition here instead that TYPE1 is narrower than TYPE2? >> > I.e. we need to reject the case in which we multiply a signed and an >> > unsigned value to get a (logically) signed result, but then >> > zero-extend it (rather than sign-extend it) to the precision of the addition. >> > >> > That would make the test: >> > >> > if (subtype == optab_vector_mixed_sign >> > && TYPE_UNSIGNED (unprom_mult.type) >> > && TYPE_PRECISION (unprom_mult.type) < TYPE_PRECISION (type)) >> > return NULL; >> > >> > instead. >> >> And folding that into the existing test gives: >> >> /* If there are two widening operations, make sure they agree on the sign >> of the extension. The result of an optab_vector_mixed_sign operation >> is signed; otherwise, the result has the same sign as the operands. */ >> if (TYPE_PRECISION (unprom_mult.type) != TYPE_PRECISION (type) >> && (subtype == optab_vector_mixed_sign >> ? TYPE_UNSIGNED (unprom_mult.type) >> : TYPE_SIGN (unprom_mult.type) != TYPE_SIGN (half_type))) >> return NULL; >> > > I went with the first one which doesn't add the extra constraints for the > normal dotproduct as that makes it too restrictive. It's the type of the > multiplication that determines the operation so dotproduct can be used > a bit more than where we currently do. > > This was relaxed in an earlier patch. I didn't mean that we should add extra constraints to the normal case though. The existing test I was referring to above was: /* If there are two widening operations, make sure they agree on the sign of the extension. */ if (TYPE_PRECISION (unprom_mult.type) != TYPE_PRECISION (type) && TYPE_SIGN (unprom_mult.type) != TYPE_SIGN (half_type)) return NULL; Although this existing test makes sense for the normal case, IMO testing TYPE_SIGN (half_type) doesn't make sense for the mixed-sign case. I think we should therefore replace the existing test with: /* If there are two widening operations, make sure they agree on the sign of the extension. The result of an optab_vector_mixed_sign operation is signed; otherwise, the result has the same sign as the operands. */ if (TYPE_PRECISION (unprom_mult.type) != TYPE_PRECISION (type) && (subtype == optab_vector_mixed_sign ? TYPE_UNSIGNED (unprom_mult.type) : TYPE_SIGN (unprom_mult.type) != TYPE_SIGN (half_type))) return NULL; rather than add a separate condition for the mixed-sign case. The behaviour of the normal case is the same both ways. Thanks, Richard