From patchwork Wed Feb 28 08:09:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 207694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3201365dyb; Wed, 28 Feb 2024 00:10:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXG6eWNMjbB4wEbXxceeXqTXXUAn5l/aDCxJ11BhddOzIlXa8wPiHYlm9BYS2xWLgXmXcPphpFJsMi6hPv4R7/m5KTAXg== X-Google-Smtp-Source: AGHT+IFU0kfhmRYKtoTzegk80ELk7pZ2dEqOYo4pYTEweW3YSXDDpEGjrMUFTk1HM3jgWjJNEJuH X-Received: by 2002:a05:6102:5488:b0:471:be25:1b5a with SMTP id bk8-20020a056102548800b00471be251b5amr12971013vsb.20.1709107847986; Wed, 28 Feb 2024 00:10:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709107847; cv=pass; d=google.com; s=arc-20160816; b=y8wS5akB/LK2TNlBtBi4JnVAce20KjEmt2LslFn/tV9vxYDzuDPxSIfp10kT9lOgwT 13IiWyG56jJ8xh1N49DwLszubZCX9MgKXFuATozS6nLc4e6dGfOmsOHmZrS0J5YbxQBW dCtJhZsatMaC8D+aqJwVc/aUqCh6jXNminHB4UJmtWDFwQBS9gf1kzfL19RwmRrPGdNz mo1DzXmxnyrAdO10TppgHeMBhKMtHhZjsmplAjcbLyv3/JNutg9GAkwVbBmVeAz5jSuw fIpOQKYXLPLThfrK9JPqiOo3dmseo2mR065qCxM86nKSUnBw+bD6GFLMq29zMRT6mXf6 GI5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=ls5C+v7CrN1Jp+qs0Q7Dz6dwp0wEtM8JYw5Z97CxLbw=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=WZcUiO6e27kj4eyeTEVgPqYrN+AVDamtceiMOA4mS3w1HKlXIfILRSv7QpIjfi4v8c lByQkohipefWhAGfeduce0rXoeu7u8VS8I1sDWqf2OYrW5i7OrsaHhAt+KbDZA/5U3v9 M3ZDR23+XLFKNQVXX823z/751p0RDxuuBRVfrF2alnExFMjdPVys36RJhDI1wYjbvlUt EnfXS9pHvO6GxyNpEn3OI6HZW0hgGNFRyhSIHk3uMsBqToDjxFnNHM4tlrsAA/Dzu9IG 1Jzvk/mQq+fPClbV3+vJSDVKg6/cg61YLZolq9kubcahlh53pbFzG/AvtimGg43SEuwc veaQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TspZj3qZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id a22-20020ac87216000000b0042dacda1b93si8980405qtp.492.2024.02.28.00.10.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 00:10:47 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TspZj3qZ; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACF213858C36 for ; Wed, 28 Feb 2024 08:10:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 CA74C3858C5E for ; Wed, 28 Feb 2024 08:09:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA74C3858C5E 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 CA74C3858C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709107801; cv=none; b=msV2MS57i4+SY6ago4u80AklV2s7E5I3+MP6vJEAtbtgxqspcAVhqCsy8jQHNzl4hkCGQoRyPq+v8IyXnzK3pd8OLKnkgDNFaLdq6bLDKpV+PTzuf1XYgkiJFUIOPsmR7Kg+NasesaEi72N8w+ob7VhjD+tBYID4h9nURy2GNXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709107801; c=relaxed/simple; bh=g1vXXgSyhaoEe1JjOKxZliYBWqHMCJ+amVKLqi9O/xg=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=O/8R+opc4s4DfQLlX9dN3oRqic8F3bOFGIYS3i8XL+lGWOojmxfv/poUEkoZSI/9ew6GY5SoMMHuOrQTvxkj/Qk10jPcBHShmIf8AyOJOGboLg6Z4yJOUhvFQB2rov72dwtzJuAtjrxDHX4GZt/SDvbzsV5Ys5ueZL90gScgg5M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709107797; 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; bh=ls5C+v7CrN1Jp+qs0Q7Dz6dwp0wEtM8JYw5Z97CxLbw=; b=TspZj3qZu5PrKP/1/ZngyIWCFAhgaPiMz05rm3utAvyD18M4nn1KghShnxFQQ6IV605o9c u0ej98b9/Gcwk8fMPynZQG1Pgm8tAxQ/P2B/dTC7PW4Ois8dE8n1ABPDSFCKVujQh5TToH CNtUrwkumnRlf7p3uFQ/ltYWHqoCYIc= 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-10-0dtvAPwnOa-Id8fo2euINw-1; Wed, 28 Feb 2024 03:09:55 -0500 X-MC-Unique: 0dtvAPwnOa-Id8fo2euINw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 968E8185A780; Wed, 28 Feb 2024 08:09:55 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5AF1E1C060AF; Wed, 28 Feb 2024 08:09:55 +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 41S89qFh2997311 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 09:09:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 41S89prU2997310; Wed, 28 Feb 2024 09:09:51 +0100 Date: Wed, 28 Feb 2024 09:09:51 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] graphite: Fix non-INTEGER_TYPE integral comparison handling [PR114041] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792129470963603949 X-GMAIL-MSGID: 1792129470963603949 Hi! The following testcases are miscompiled, because graphite ignores boolean, enumerated or _BitInt comparisons, rewrites the code as if the comparisons were always true or always false. The INTEGER_TYPE checks were initially added in r6-2239 but at that point it was both in add_conditions_to_domain and in parameter_index_in_region. Later on the check was also added to stmt_simple_for_scop_p, and finally r8-3931 changed the stmt_simple_for_scop_p check to INTEGRAL_TYPE_P and turned the parameter_index_in_region -> assign_parameter_index_in_region into INTEGRAL_TYPE_P assertion, but the add_conditions_to_domain check for INTEGER_TYPE remained. The following patch uses INTEGRAL_TYPE_P to complete the change. Bootstrapped/regtested on x86_64-linux and i686-linux (--with-isl only on the former though), ok for trunk? 2024-02-28 Jakub Jelinek PR tree-optimization/114041 * graphite-sese-to-poly.cc (add_conditions_to_domain): Check for INTEGRAL_TYPE_P check rather than INTEGER_TYPE. * gcc.dg/graphite/run-id-pr114041-1.c: New test. * gcc.dg/graphite/run-id-pr114041-2.c: New test. Jakub --- gcc/graphite-sese-to-poly.cc.jj 2024-01-03 11:51:29.136764430 +0100 +++ gcc/graphite-sese-to-poly.cc 2024-02-27 19:35:07.668304435 +0100 @@ -391,8 +391,9 @@ add_conditions_to_domain (poly_bb_p pbb) { case GIMPLE_COND: { - /* Don't constrain on anything else than INTEGER_TYPE. */ - if (TREE_CODE (TREE_TYPE (gimple_cond_lhs (stmt))) != INTEGER_TYPE) + /* Don't constrain on anything else than INTEGRAL_TYPE_P. */ + tree cmp_type = TREE_TYPE (gimple_cond_lhs (stmt)); + if (!INTEGRAL_TYPE_P (cmp_type)) break; gcond *cond_stmt = as_a (stmt); --- gcc/testsuite/gcc.dg/graphite/run-id-pr114041-1.c.jj 2024-02-27 18:42:26.864025806 +0100 +++ gcc/testsuite/gcc.dg/graphite/run-id-pr114041-1.c 2024-02-27 18:43:07.310466262 +0100 @@ -0,0 +1,23 @@ +/* PR tree-optimization/114041 */ +/* { dg-require-effective-target bitint } */ +/* { dg-options "-O -fgraphite-identity" } */ + +unsigned a[24], b[24]; + +__attribute__((noipa)) unsigned +foo (unsigned _BitInt(8) x) +{ + for (int i = 0; i < 24; ++i) + a[i] = i; + unsigned e = __builtin_stdc_bit_ceil (x); + for (int i = 0; i < 24; ++i) + b[i] = i; + return e; +} + +int +main () +{ + if (foo (0) != 1) + __builtin_abort (); +} --- gcc/testsuite/gcc.dg/graphite/run-id-pr114041-2.c.jj 2024-02-27 19:36:02.373547881 +0100 +++ gcc/testsuite/gcc.dg/graphite/run-id-pr114041-2.c 2024-02-27 19:36:22.515269333 +0100 @@ -0,0 +1,27 @@ +/* PR tree-optimization/114041 */ +/* { dg-options "-O -fgraphite-identity" } */ + +unsigned a[24], b[24]; +enum E { E0 = 0, E1 = 1, E42 = 42, E56 = 56 }; + +__attribute__((noipa)) unsigned +foo (enum E x) +{ + for (int i = 0; i < 24; ++i) + a[i] = i; + unsigned e; + if (x >= E42) + e = __builtin_clz ((unsigned) x); + else + e = 42; + for (int i = 0; i < 24; ++i) + b[i] = i; + return e; +} + +int +main () +{ + if (foo (E1) != 42 || foo (E56) != __SIZEOF_INT__ * __CHAR_BIT__ - 6) + __builtin_abort (); +}