From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id ECA6F3858C66 for ; Tue, 9 Jan 2024 19:47:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECA6F3858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ECA6F3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704829629; cv=none; b=G7tW64lVelTHt8psxe+fKsw7JGRokECgVKDxxUvecXO6eNI4cLKxnvtytYNLLQsOp8fEatRw/km6/3k8RUhpG1NqJuppXvQ1mlCHpF8uMlWpoIhY+X0qDNDwnZgXCzeOx/7LH5ep+YFWYj+YzIX8otjsjjiYqCcUmnheG1DnGgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704829629; c=relaxed/simple; bh=QBgh7PKDeLyTvdoFkhO1dPDcMzo9Ng2UPZPyLqYbFA4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=NWpUaK1lJYcQXI3MZV8JfP3gE422qDMDwraN618wnjeN6ghB/R/0eNpyxcOKaohVqXevRzm4mHJzz739X5/bsqL5O3R/mUeC/YQPqT9g8t+9qq9FEcxsOYxkAgUjN2Rhwph3ZTszu4HNwzFAJ5b/e8QePdILxlzosyFARBLhYok= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-3606dc50447so18959905ab.2 for ; Tue, 09 Jan 2024 11:47:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704829625; x=1705434425; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=2/3Dh01VUBBZTtp9bDldRMKKh+FfvHIlcQqO5Ox3H4s=; b=Xgz0Xk2zinX13ht9o2O1vA+72/dotJCy3uu+KWaEWdfNo1PFZ0uOrDPjhquXlqBryz RlJzY5/QVFxzP6L+DH8bfJAi2UTYki+BydyUFM/sM5HITWpaeuDOseOyeW9bIxcViOmX uwGFkkjK6jsL9/Nl89+3EF+ffJR3ioHGYNTNsY8L2lhCmwyJpVky5T03MRPDncInQGRm X6iEfavV8BMW/WtbaxDauyqsaubjokG72nn7l/yW696lBSOknx/yIS+qhXUYKAb1jbc3 ntCCSoXZzdnTlYSXgnz9RQKVij4dxLf5btEg6FaT41gbjFwImf64zRlBN0yutHCrYs9s B38Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704829625; x=1705434425; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2/3Dh01VUBBZTtp9bDldRMKKh+FfvHIlcQqO5Ox3H4s=; b=sgAGOwshSGGdwxtZ7LmdSer3+hL8+sjmuJBwNZ8f12iOmBDq3wPDiXHywbksuZmHMv GG0/YE5RAzvQGQoNeP1lAtD5cKqQdvEBQrJw6QiqDnYxCEbgMdEGnoES/YEZFAFJw4xw LWhyySxyzUy3bhs5ms5/FKivvyd6imNT/RIIcyoRch6vRLJT0QkZOn/nkysJnRVTQd4R 2ino2mos5Wc4QmEbJTHgrtw1Hg6D4jQmucZ0qlvItN92utGOu1sNACRfrP9atr+iwgle B5FP5NomEiqURcDOmcwVIlZz9/sQtgb5XVAqPGMHklweilEOYaiyXRFuKgfjPLtDQLRz foOg== X-Gm-Message-State: AOJu0Yylr9662CwD32DDPU1OVV5dkyxZ0PNIIoqGrNzx5v2jVb5Pu04G tqkxURKn1N9py/2kiacQimo= X-Google-Smtp-Source: AGHT+IEsjVHTljQDNYTRlgDJDeLlF4rbbAR/viVW9FD8kLKi1XklhdwzJYIj55vgnBwwpS7uvz6zzw== X-Received: by 2002:a92:cdae:0:b0:35f:f01e:bb30 with SMTP id g14-20020a92cdae000000b0035ff01ebb30mr9113286ild.49.1704829625098; Tue, 09 Jan 2024 11:47:05 -0800 (PST) Received: from [172.31.0.109] ([136.36.72.243]) by smtp.gmail.com with ESMTPSA id y14-20020a92c74e000000b0036090442bd8sm789591ilp.47.2024.01.09.11.47.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Jan 2024 11:47:04 -0800 (PST) Message-ID: Date: Tue, 9 Jan 2024 12:47:03 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] vect: Fix ICE in vect_analyze_loop_costing [PR113210] Content-Language: en-US To: Jakub Jelinek , Richard Biener Cc: gcc-patches@gcc.gnu.org References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SCC_BODY_URI_ONLY,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no 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 1/6/24 01:59, Jakub Jelinek wrote: > Hi! > > The following testcase ICEs (on ARM/RISCV with certain options), because niters analysis > computes number of latch executions for the loop as > (short unsigned int) (a.0_1 + 255) + 1 > 256 ? ~(short unsigned int) (a.0_1 + 255) : 0 > where a.0_1 is unsigned char. This is correct, but given that a.0_1 + 255 > is done in unsigned char the condition is never true and so it is actually > equivalent to 0, but the folders don't know that. > The vectorizer sets LOOP_VINFO_NITERSM1 to that expression and does on with > computing LOOP_VINFO_NITERS by fold_build2 PLUS_EXPR of that expression > unshared and INTEGER_CST one. In that folding we trigger various > optimizations, first it is correctly simplified into > (short unsigned int) (a.0_1 + 255) + 1 > 256 ? -(short unsigned int) (a.0_1 + 255) : 1 > and next using > /* (X + 1) > Y ? -X : 1 simplifies to X >= Y ? -X : 1 when > X is unsigned, as when X + 1 overflows, X is -1, so -X == 1. */ > into > (short unsigned int) (a.0_1 + 255) >= 256 ? -(short unsigned int) (a.0_1 + 255) : 1 > and for this the first COND_EXPR argument is folded and figured out to be 0 > and so while LOOP_VINFO_NITERSM1 is a complex expression (unknown to be > equivalent to 0), LOOP_VINFO_NITERS is INTEGER_CST 1. > vect_analyze_loop_costing then uses LOOP_VINFO_NITERS_KNOWN_P (which checks > if LOOP_VINFO_NITERS is INTEGER_CST which fits into shwi or something like > that) and from that assumes that LOOP_VINFO_NITERSM1 will be INTEGER_CST. > > The following patch fixes that by adding verification for that too. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2024-01-06 Jakub Jelinek > > PR tree-optimization/113210 > * tree-vect-loop.cc (vect_analyze_loop_costing): If LOOP_VINFO_NITERSM1 > is not INTEGER_CST, don't try to use it. > > * gcc.c-torture/compile/pr113210.c: New test. OK jeff