From patchwork Sat Dec 9 09:35:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 176151 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5962564vqy; Sat, 9 Dec 2023 01:35:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFV9KqHizKXCbFrfYNSqVoLWsccIi4fJVLBBa+uEqbvJBDvHd7SBisisqZl8Nxlfau4D5y5 X-Received: by 2002:a0c:e64a:0:b0:67a:a741:e041 with SMTP id c10-20020a0ce64a000000b0067aa741e041mr2196191qvn.3.1702114534782; Sat, 09 Dec 2023 01:35:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702114534; cv=pass; d=google.com; s=arc-20160816; b=lFAxkQ1xW2vjPQLF4xAVVPMsp0TWvA2bhRitzvXPRHzolT+nt2r2+X4KeZqFKHmKF5 tNLzR2SY4fhRd4VadP9O5rFUFL7EjSWK0R3UyThjg/s2X/RSdQAreVYPAZxtBaJ72+LU gkg0/Kj08m1QOAvHRvlZ2Vh4pZi+aUbLCYSC9BxQpKanNfVBmjEf02qAWxMBcBAb5eag k36AeqJ7hgEs82eJCIg5lBC21zlAR7u444wX3iJQ0KpnvjJFV/26mWxemQqUuJ5hJAyF Wr8/QfKlzDdpsR1mkHB1qLrlsjCZAq6YibZ7/qRxiptG4sHKI1NkBrNZrM0s04XdI8S6 Hl8w== 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=iR8BvRhL6eC1LtmxhGEa4zpl/s0MJGFFMjlQB6YHDvU=; fh=FCjeRajqaQYHMkQtfIia8KT5yBac53mYOLLyJhYG/AY=; b=ggBfGR4giSiXQ3GZNfmuGKh+a0ZJxaFPKpvp+1Yl8eQFSkEtKpRz9ecWpth2P4pEy2 R5txoZKG7a+LJ5N78veUwv1ZZ02s7e75LiMIgwyFQWOOIlKv6ea8oT7JJoZPyxKK+3PB vV/2qfteORmKt3SFoP11WWZch3hFqgGJkOC1D6TUWAm36UN0wuXoYQ30F1xXH8+eyJ2B KiB403tLgLUkF4lxXxw7EPtJD4uXqaSJffik/h/ufxdZgfaF6fG4qtC/f7rT3J3QpHG8 4Zd+11TIVFaIQmXcJqDURK3mhioPo0jjlxTxFkLHAxgSXKKfFyE5mVzdNKsB3U+WEeIj XMlA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GumT/t81"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id da19-20020a05621408d300b0067a8d3c22a7si3721364qvb.479.2023.12.09.01.35.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Dec 2023 01:35:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="GumT/t81"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 8AD663858438 for ; Sat, 9 Dec 2023 09:35:34 +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 0A0063858C53 for ; Sat, 9 Dec 2023 09:35:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A0063858C53 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 0A0063858C53 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=1702114512; cv=none; b=JzdNKbzqT1N34YhjXL2E/36WYsH3Rm520aCxmyhI6VgZXNT24ckuY5sfsgzzBdFEss5ogO/ReJRfx67IleojqUolm+E0whAlH7+75Zvj6belhHcMNMr7nUSxUjsdvIN48o12AbGRmuj+kGtPTOaUsDsj5QcoUNdpPMpNrpXEX0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702114512; c=relaxed/simple; bh=uZuBOMyFFqa7/OE7+FprUioz5ya6vT2KvygNESmV2S4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=n4OCJh0IOenrCoHKGAJ2kAyLrVEti2ulgm90fQP/8NChTr0mjMDwSUNW+wX+MiT69Jqa7N63Fd8uRGOhtkZGh6SAmMRbnpiiXt2viQLV7rB6Y8gTBbLNbd7WPpmzfh0AiM27xeuvs0TVzlagY2R294M6RVC4xhRskx/bRqzwkz8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702114510; 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=iR8BvRhL6eC1LtmxhGEa4zpl/s0MJGFFMjlQB6YHDvU=; b=GumT/t81g7Yw8uwhia0+KfS0Nmnx0nqzhI0eWoU9XPXvfRcmznTg9nvXn3h0Tu9m7edSvN VjBvUudBi95UepkzqD/e8/KD/HZ+ckdIuxcoISmmAJ/hLGCDhwDQzxJwyMa9FnvuHRUbRf LvkLqgUC4n/muJxEHQjZNgT1zSepSks= 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-544-Sf6VJYHbOJ6rUheAZsr6jQ-1; Sat, 09 Dec 2023 04:35:08 -0500 X-MC-Unique: Sf6VJYHbOJ6rUheAZsr6jQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 A5B2F185A780; Sat, 9 Dec 2023 09:35:08 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 69E8C40C6E38; Sat, 9 Dec 2023 09:35:08 +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 3B99Z57T1458713 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 9 Dec 2023 10:35:06 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B99Z53r1458712; Sat, 9 Dec 2023 10:35:05 +0100 Date: Sat, 9 Dec 2023 10:35:04 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] phiopt: Fix ICE with large --param l1-cache-line-size= [PR112887] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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_H3, 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: 1784796450340318465 X-GMAIL-MSGID: 1784796450340318465 Hi! This function is never called when param_l1_cache_line_size is 0, but it uses int and unsigned int variables to hold alignment in bits, so for large param_l1_cache_line_size it is zero and e.g. DECL_ALIGN () % param_align_bits can divide by zero. Looking at the code, the function uses tree_fits_uhwi_p on the trees before converting them using tree_to_uhwi to int variables, which looks just wrong, either it would need to punt if it doesn't fit into those and also check for overflows during the computation, or use unsigned HOST_WIDE_INT for all of this. That also fixes the division by zero, as param_l1_cache_line_size maximum is INT_MAX, that multiplied by 8 will always fit. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-09 Jakub Jelinek PR tree-optimization/112887 * tree-ssa-phiopt.cc (hoist_adjacent_loads): Change type of param_align, param_align_bits, offset1, offset2, size2 and align1 variables from int or unsigned int to unsigned HOST_WIDE_INT. * gcc.dg/pr112887.c: New test. Jakub --- gcc/tree-ssa-phiopt.cc.jj 2023-11-14 10:52:16.195275972 +0100 +++ gcc/tree-ssa-phiopt.cc 2023-12-08 16:25:29.166747347 +0100 @@ -3757,8 +3757,8 @@ static void hoist_adjacent_loads (basic_block bb0, basic_block bb1, basic_block bb2, basic_block bb3) { - int param_align = param_l1_cache_line_size; - unsigned param_align_bits = (unsigned) (param_align * BITS_PER_UNIT); + unsigned HOST_WIDE_INT param_align = param_l1_cache_line_size; + unsigned HOST_WIDE_INT param_align_bits = param_align * BITS_PER_UNIT; gphi_iterator gsi; /* Walk the phis in bb3 looking for an opportunity. We are looking @@ -3770,8 +3770,7 @@ hoist_adjacent_loads (basic_block bb0, b gimple *def1, *def2; tree arg1, arg2, ref1, ref2, field1, field2; tree tree_offset1, tree_offset2, tree_size2, next; - int offset1, offset2, size2; - unsigned align1; + unsigned HOST_WIDE_INT offset1, offset2, size2, align1; gimple_stmt_iterator gsi2; basic_block bb_for_def1, bb_for_def2; --- gcc/testsuite/gcc.dg/pr112887.c.jj 2023-12-08 16:31:30.708697160 +0100 +++ gcc/testsuite/gcc.dg/pr112887.c 2023-12-08 16:27:06.662385487 +0100 @@ -0,0 +1,13 @@ +/* PR tree-optimization/112887 */ +/* { dg-do compile } */ +/* { dg-options "-O2 --param=l1-cache-line-size=0x20000000" } */ + +void bar (long); +long c; +struct S { long a, b; } s; + +void +foo (void) +{ + bar (c ? s.a : s.b); +}