From patchwork Mon Aug 21 09:47:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 136358 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2890233vqi; Mon, 21 Aug 2023 02:48:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IENsADVNClYcLnH+jGG8yzQ8pOO0M4SZnbjHcMVXNbZLaZW3FZy4RiOo65VKMCy8408jtC7 X-Received: by 2002:a05:6512:6ca:b0:4ff:9eed:b68d with SMTP id u10-20020a05651206ca00b004ff9eedb68dmr5132005lff.58.1692611323898; Mon, 21 Aug 2023 02:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692611323; cv=none; d=google.com; s=arc-20160816; b=emLX6/fPPzWfX0EwqEvtYdLJhyPzF0moF+ySURYcwvMsmRSuOigPxkFuAWdaQVklDk nHigrCefew4QLEjR7VPF2o71LYYDH+Khb31hOKnRezNlg77Ymq4tc5fQeNpk/GuxNAzn XYgKcRlLBR2I5s/wI+sLY0vhrrB3VSH2ynCTZmH8KmU5B8s4J+Oloha0zIaEiIZdqqNq HU6lHmFWOSh6IoUl8LgQv2YLT2AunrGgqJtFXtxN8GkWcl4Y1kDuSWgafyoHAj6jP3kf JhSYUQBnuaHyqSRXx6TdE8Kvm9Nuyh/9id9TyTBz0T8hsRxkisds6nBGB3qsb1EsPDz4 TTVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=o2kpoTZFf6hV/Xs9Jg+rLPf7er5x7ozbS8r+FaXvZWw=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=ZGvLIofWcIxlxUh8+SV6DPbq5d8ZqVyJwbgdCtDMD/kgQdcbZvVErGrdGccMnE4zVY GxOiv3DBsn7lq+Njp8EyDrarg6NLMfvISSILguMct4V8MEMFHeZeeKT4G1fSUqnm7bIb /ao6rn00UE/5eKC/akcU5gGieJRqTPNZW6PO7xE6eyQaEe94kgVxe+WqfhxFQghBxzJL Y36O6pC0WMIpiEb4pSyGDVhLdAd3XJlDYiW41X6PNbUuhup0UY52oCZl6jMP2f54N3zt GBHznl57a81RWwHSsNAbgjYq8fEDV7f0v0gXpe95wDRgUlj8Zq4vwhN7e5Cu8wK12M5o N7eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=OE7dB5XJ; 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=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d21-20020a170906c21500b00992a9b22b7fsi5499675ejz.668.2023.08.21.02.48.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 02:48:43 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=OE7dB5XJ; 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=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 34B663836E92 for ; Mon, 21 Aug 2023 09:48:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 34B663836E92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692611314; bh=o2kpoTZFf6hV/Xs9Jg+rLPf7er5x7ozbS8r+FaXvZWw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OE7dB5XJ9EMJ2h8ASYkq3BAWtk2o7qWhUH5iUTg+TUfcbnwcbLsxOkJOsEj8UK3hu mtNbpnYK36HRiONQbPDV/40imH4iFa9RZNzUuVc5JYK1at/BEvkCQLz5J+zK+nCZdH c1ZPniQVNDG8X4wUIbF4kEFoHrcAl3tHmxZ7hN+g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 478C63856261 for ; Mon, 21 Aug 2023 09:47:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 478C63856261 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 4C2F3223D9 for ; Mon, 21 Aug 2023 09:47:49 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 4733E2C143 for ; Mon, 21 Aug 2023 09:47:49 +0000 (UTC) Date: Mon, 21 Aug 2023 09:47:49 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/111082 - bogus promoted min User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, 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 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-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230821094834.34B663836E92@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774831611175415432 X-GMAIL-MSGID: 1774831611175415432 vectorize_slp_instance_root_stmt promotes operations with undefined overflow to unsigned arithmetic but fails to consider operations that do not overflow like MIN which it turned into MIN with wrong signedness and in the case of the PR an unsupported operation. The following rectifies this. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/111082 * tree-vect-slp.cc (vectorize_slp_instance_root_stmt): Only pun operations that can overflow. * gcc.dg/pr111082.c: New testcase. --- gcc/testsuite/gcc.dg/pr111082.c | 10 ++++++++++ gcc/tree-vect-slp.cc | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr111082.c diff --git a/gcc/testsuite/gcc.dg/pr111082.c b/gcc/testsuite/gcc.dg/pr111082.c new file mode 100644 index 00000000000..46e36e320d1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr111082.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fno-vect-cost-model" } */ +/* { dg-additional-options "-mavx512f" { target { x86_64-*-* i?86-*-* } } } */ + +long minarray2(const long *input) +{ + if (input[0] < input[1]) + return input[0] ; + return input[1]; +} diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 51f3466805c..e8484401bc9 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -9180,7 +9180,8 @@ vectorize_slp_instance_root_stmt (slp_tree node, slp_instance instance) tree vectype = TREE_TYPE (vec_def); tree compute_vectype = vectype; bool pun_for_overflow_p = (ANY_INTEGRAL_TYPE_P (vectype) - && TYPE_OVERFLOW_UNDEFINED (vectype)); + && TYPE_OVERFLOW_UNDEFINED (vectype) + && operation_can_overflow (reduc_code)); if (pun_for_overflow_p) { compute_vectype = unsigned_type_for (vectype);