From patchwork Wed Nov 8 16:49:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 118292 Delivered-To: patch@linaro.org Received: by 10.80.245.45 with SMTP id t42csp2019298edm; Wed, 8 Nov 2017 08:49:54 -0800 (PST) X-Google-Smtp-Source: ABhQp+RcQsu1SwXK1JXG7+98X6vkXmXPYc0NWqhj9BsWXj6EEjYJISxz7B3Ja9ZCWwg6QaVY83Cj X-Received: by 10.99.170.66 with SMTP id x2mr1043561pgo.117.1510159793962; Wed, 08 Nov 2017 08:49:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510159793; cv=none; d=google.com; s=arc-20160816; b=n6/BXdbZolZcviu8bQgq8a8wxuVxYOD4jIoCmyUAYn+/u7jjfyhB6JcSzexd2hIkgm ZdHi/Drh1+7V3HBlPjSrZZFvTJlQcfH+FCBKbZ1pb1AamCScCvjxLyL3W3q08vMjJTTe dPMOkxHDCK6jzOYnCIfDAuHFFYU+JL68V9ZforV8QWUHVakFUkSf6rD2P3A+2HSM2IMj RX/mEIZ+adJF3venB8S7CFFR7f2a7IBIxbAQ5nbmT5VbNU2CcCkXSCa+Qw5ng6/HzXYq rKcnXC//yA32l+GocsfR+5tvfGmwUNieRL2XmpoDGG8I1LC/NFXOUMze8D6zNkl6c8XC zAIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=kdvc6uNPucgi4/JtXPwG8Lk1hHLnDUkWxfv0EwKdN2Q=; b=g1aoKf1suB+NeRBvw2Ag09mHv83q/EuncD2wyEYg4GzZ2G40GQs2bPXf5mRp2hk2jM xdS/o7KkkXTsv5jrIHexbOKYW8/btRNJhQ3KtBCqmHmVyR55At0x3XvD18BH/00mMNXG pAI9imMVjZ8OEcXr3673iYl+hit56d7kVCBTiflFoKhZA73eAAkIoskCuVacfe26SbTa rMpO4CrCLZT+QEIrMpII3fLVU1/sB8FMZU7kPihs/h1lP98BJXPeFX1eGhVLY78MgAzZ 1baztlJ+oTC9iUPWej4FGOpo1KcSleuIZvpQFhPbTsWu+jvL6g9X5Neidg7s/l2hnGRW sfWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L82dAHFq; spf=pass (google.com: domain of gcc-patches-return-466277-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-466277-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h9si4314361pgv.572.2017.11.08.08.49.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Nov 2017 08:49:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-466277-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=L82dAHFq; spf=pass (google.com: domain of gcc-patches-return-466277-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-466277-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=CV3EuyIvPicFnu4+w+d9Urp2AQuQtXTV7ANCPEDq477iiwpj29qWm rRNciFButPnE71IWwpT/P6YVa4aOiYUB5VmMttP8sp5LVUht81+TR6kF1LySmpMA qtjzj61qE3N+7KF88ihk7oWneHvOryaeRrSF31LTvQvwPcO7Bl7ry8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=rR51Sx6VUeD39O8RJQwOZErfzEc=; b=L82dAHFq9T6PV8mkkL3C vXRu4DeTVnJTCR1bMEcfHq1K8dDFwJAvkoVWaLpAa6kExMBoQLEV6qRuk/ogEkim AwoFVuAnJphoXwe15jbBuwoP2cSUzqDMn77bLIrr2NbUz8be+9cGa2zbS3gA7JYC EWBm5Jpzvp6N5C4l3DUYi5o= Received: (qmail 59977 invoked by alias); 8 Nov 2017 16:49:36 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 59888 invoked by uid 89); 8 Nov 2017 16:49:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=protect X-HELO: mail-wm0-f47.google.com Received: from mail-wm0-f47.google.com (HELO mail-wm0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Nov 2017 16:49:34 +0000 Received: by mail-wm0-f47.google.com with SMTP id t139so12199909wmt.1 for ; Wed, 08 Nov 2017 08:49:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=kdvc6uNPucgi4/JtXPwG8Lk1hHLnDUkWxfv0EwKdN2Q=; b=nUP5ZuJyqIvvscOeSD0PYEMYUI3y8LmVz3aIw7b+B5EQalSSxUZLJZoYIQ/vqAaOR0 Fq3J5zvSPGj4zBaXDPLlQrRK+FvCdwjbVWj/wdWXRSeel7/9mnhXTMmcEH+M4wMu+mrw tDFS0muhKqYDD5wrGP6hdGZoXqWgniIkhVuy6ZU+19DT3gpI8zVftfRLurK7jjSJKEXX LW72JID5U+l89nikKQfAJbNuu5RWXJgW7uJ4fXMjra2grawH05apnATEXopfDhefcmN5 EALPv7xQ3qPRTrHyhmRhsDhpFa9JSqBJV3ucsyJzNDucpGwonWj6qdOZOlASy03T1vuD IcQw== X-Gm-Message-State: AJaThX68S3MYAXLrWMlom1Q367F7K3YGXTZt+A1b6R27tbkNxtNN0Ny6 eHmUjS6Qfmp8A5IR8ZYMR1XLwyziLiU= X-Received: by 10.28.122.11 with SMTP id v11mr923643wmc.104.1510159772452; Wed, 08 Nov 2017 08:49:32 -0800 (PST) Received: from localhost (94.197.121.218.threembb.co.uk. [94.197.121.218]) by smtp.gmail.com with ESMTPSA id h66sm3415172wmd.11.2017.11.08.08.49.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Nov 2017 08:49:31 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Protect against min_profitable_iters going negative Date: Wed, 08 Nov 2017 16:49:26 +0000 Message-ID: <87a7zwwwa1.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 We had: if (vec_outside_cost <= 0) min_profitable_iters = 0; else { min_profitable_iters = ((vec_outside_cost - scalar_outside_cost) * assumed_vf - vec_inside_cost * peel_iters_prologue - vec_inside_cost * peel_iters_epilogue) / ((scalar_single_iter_cost * assumed_vf) - vec_inside_cost); which can lead to negative min_profitable_iters when the *_outside_costs are the same and peel_iters_epilogue is nonzero (e.g. if we're peeling for gaps). This is tested as part of the patch that adds support for fully-predicated loops. Tested on aarch64-linux-gnu (both with and without SVE), x86_64-linux-gnu and powerpc64le-linux-gnu. OK to install? Thanks, Richard 2017-11-08 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-vect-loop.c (vect_estimate_min_profitable_iters): Make sure min_profitable_iters doesn't go negative. Index: gcc/tree-vect-loop.c =================================================================== --- gcc/tree-vect-loop.c 2017-11-08 16:35:04.770241799 +0000 +++ gcc/tree-vect-loop.c 2017-11-08 16:47:06.386264822 +0000 @@ -3651,23 +3651,24 @@ vect_estimate_min_profitable_iters (loop if ((scalar_single_iter_cost * assumed_vf) > (int) vec_inside_cost) { - if (vec_outside_cost <= 0) + min_profitable_iters = ((vec_outside_cost - scalar_outside_cost) + * assumed_vf + - vec_inside_cost * peel_iters_prologue + - vec_inside_cost * peel_iters_epilogue); + + if (min_profitable_iters <= 0) min_profitable_iters = 0; else - { - min_profitable_iters = ((vec_outside_cost - scalar_outside_cost) - * assumed_vf - - vec_inside_cost * peel_iters_prologue - - vec_inside_cost * peel_iters_epilogue) - / ((scalar_single_iter_cost * assumed_vf) - - vec_inside_cost); + { + min_profitable_iters /= ((scalar_single_iter_cost * assumed_vf) + - vec_inside_cost); if ((scalar_single_iter_cost * assumed_vf * min_profitable_iters) <= (((int) vec_inside_cost * min_profitable_iters) + (((int) vec_outside_cost - scalar_outside_cost) * assumed_vf))) min_profitable_iters++; - } + } } /* vector version will never be profitable. */ else