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.133.124]) by sourceware.org (Postfix) with ESMTPS id AEBA53858436 for ; Thu, 6 Oct 2022 23:22:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AEBA53858436 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665098573; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RO72cJFp2NCBuZcDNB26MJzFQd9kEFwStQ/sfdoCs0s=; b=UEPSO4GcFNghHlaj/Aywty+ydRDG3pzrmZnoe84zpYbWfiofMnLEbkwPK9LIBN/6ByP6Uy YjeqtLvsWQYCzdDQZiaWAGeUOT+lfySxxSnI+IhCjsMZ1kEOfetl0bMmSk/4cqHKfKRWyR UwGIgMZupK+gFkfXNyosfjP0TiviZlg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-66-zozVoOgANqCYTXEBxLNM8Q-1; Thu, 06 Oct 2022 19:22:50 -0400 X-MC-Unique: zozVoOgANqCYTXEBxLNM8Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DADD7101A528; Thu, 6 Oct 2022 23:22:49 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 982B8404705D; Thu, 6 Oct 2022 23:22:49 +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 296NMk4u3644307 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 7 Oct 2022 01:22:47 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 296NMkjH3644306; Fri, 7 Oct 2022 01:22:46 +0200 Date: Fri, 7 Oct 2022 01:22:45 +0200 From: Jakub Jelinek To: Michael Collison Cc: gcc@gcc.gnu.org Subject: Re: Need help with match.pd crash Message-ID: Reply-To: Jakub Jelinek References: MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=WINDOWS-1252 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP 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 Thu, Oct 06, 2022 at 06:57:40PM -0400, Michael Collison wrote: > I am trying to improve code generation for coremark to match a recent > improvement that was made in LLVM. > > I added the following transformation to match.pd which attempts to replace a > branch with straight line code: > > /* (cond (and (x , 0x1) == 0), y, (z ^ y) ) -> (-(and (x , 0x1)) & z ) ^ y > */ > (simplify >     (cond (eq (bit_and @0 integer_onep@1) >                  integer_zerop) >          @2 >          (bit_xor:c @3 @2)) >         (bit_xor (bit_and (negate (bit_and @0 @1)) @3) @2)) > > I get a internal error, but in stepping through the debugger I can see the > pattern matches, but fails when when it tries to further simplify and match > another pattern in match.pd: > > /* x & C -> x if we know that x & ~C == 0.  */ > #if GIMPLE > (simplify >  (bit_and SSA_NAME@0 INTEGER_CST@1) >  (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) >       && wi::bit_and_not (get_nonzero_bits (@0), wi::to_wide (@1)) == 0) >   @0)) > #endif > > The crash occurs in wi::bit_and_not. Before digging further I want to ask if > there is a problem with the way I wrote the transformation? Yes. The way you wrote it, @0 and @1 (and the zero) will have the same type (or compatible) and @2 and @3 too, but the replacement expression relies on all of @0, @1, @2 and @3 to have compatible types. If you have int x; long long y, z; .. (x & 1) == 0 ? y : z ^ y then (-(x & 1) & z) ^ y is invalid in GIMPLE. It can be even more incompatible, e.g. y and z could be integral vectors while x could be scalar integer, etc. If both TREE_TYPE (@0) and type (aka TREE_TYPE (@2)/TREE_TYPE (@3)) are scalar, then perhaps you could just add (convert? ...) around bit_and, otherwise I think you'd better require TREE_TYPE (@0) and type to be compatible types. On the other side, you probably should handle also (x & 1) != 0 ? z ^ y : y Jakub