From patchwork Thu Mar 1 18:30:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 130391 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp3136187edc; Thu, 1 Mar 2018 10:30:55 -0800 (PST) X-Google-Smtp-Source: AG47ELsNxnL9bNCJvomH0//5+0DI1V33lBOrz+9xsYmc8MlPI68bdsBEUpxoiXCjDL2dXJKRrS3a X-Received: by 10.101.97.207 with SMTP id j15mr2254493pgv.266.1519929055603; Thu, 01 Mar 2018 10:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519929055; cv=none; d=google.com; s=arc-20160816; b=f1q7o0aRMknezqgnt7lORWg4zWjGfjTC2Ob3TGrh/21/PzMs/sKBdA9xz0RW/BvBEF HdaRyr18QbupoPc+d21otzgGLciNufMVfAHuMkxbraQGmq7y2pgr5HTH/qvoD5D+OIjk gWQ5bxv9gphNq100cLnWOhHbF0sCI4/24rWmm0qfHvEOTarcZokGKTYEl0xpKTvS5oP2 CxvaxJR2sfjaZ2uIyPvU3SWIEL2W6G6wdmeE821anWVHNApfUiuHAiaULGfFa+ktC7Q5 c6iIN68lcqELPtCKINFHXE5Wo03rsnVbjw4ANh+bPgOb3IzE7OS/tfJbKVxKY4Iepujh G+lg== 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=OVZaEwS7AzQoAWG8XnHtf5+eqqQxnhQB3CKE5s/4ZoQ=; b=vK4Kz9wzI1oVKuVGsZohYa4JYp2YDmWu3UxgjfZSR5nZLQsN6V4gxYQvTkeq0bm82n chb8Y6zOLHXPKLcbQwpbpB/fQ6KW50vqHA/Qaj2fQ8PJMl3QvqZ/raHTrWw77N9enLJU duDd3+MuTqK6S0sxC2tvY+93dgdOjkbRexne/z0uRS5nw5fTrn4ISJIrsZtka3OKoagZ FeNSDcMMY7gFg/zyOb359FZjjeg9MUH0KHxYgx5LSdZf97fpdgr3Oj6EXuZETGK5vALs fNeDgcQRmMULr2MZ1MArMx4+e0DUpLaYW/Hs0+aBiSDSYUODdeDp5baRH601QA2U2D+G OT5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=YF8s8Lsf; spf=pass (google.com: domain of gcc-patches-return-474105-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474105-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 n9-v6si3406014pll.680.2018.03.01.10.30.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 10:30:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-474105-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=YF8s8Lsf; spf=pass (google.com: domain of gcc-patches-return-474105-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-474105-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=lvI6x6rcSpSopN1rheD7Bjo/flu2Qz39GEyIYTEBY26Rffay8GepZ 6DiYDzocKKY7BMZlLhNj/vN909Nz0aQyTGGzkakAwWN+GZ89DL8gEaa1pPkrZ3Qh jVZBePQBlMR2GM+MhMyWVfuK8X6on++IUw5Y4bic7L2kJHm6LXzaL8= 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=8z/oboX9t05qhgjDPrfW25p1dX4=; b=YF8s8Lsf9SeC5ERIVmdU p2rpb1yIoHT13npVFxWnHhYW5OOJ0eRPwYu0lVPTCYnc3NutH58SHrGPG8jTDAgw Kxe6nsvka5elEHWnjFwoSuwRe8op2RA5/GXC3NY4hniiBBJvu7DyWkI1xG0BptBU PgiIrJhmstGbJgtZ7gP0x60= Received: (qmail 89123 invoked by alias); 1 Mar 2018 18:30:43 -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 88878 invoked by uid 89); 1 Mar 2018 18:30:27 -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, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:4922, 69029 X-HELO: mail-wm0-f52.google.com Received: from mail-wm0-f52.google.com (HELO mail-wm0-f52.google.com) (74.125.82.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 01 Mar 2018 18:30:25 +0000 Received: by mail-wm0-f52.google.com with SMTP id t3so13935307wmc.2 for ; Thu, 01 Mar 2018 10:30:16 -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=OVZaEwS7AzQoAWG8XnHtf5+eqqQxnhQB3CKE5s/4ZoQ=; b=esfSgDnnPGt+fbmB+zaBnj3HjNcWhhZe6FovJBZNRgKAJQPfk5x/8JT6lhTjZyDNrs krxxQEfxUGJhXAPtMxfqM2CvXkzIXPAQ8l5ftTYDhebJinrhbqIkhCCThoK2Sf5PrLmU /dkoZ629tQjFMqmiYGsWM/DhUCsXaiNcMZW+f4i1djjVd1WgqfI+pitt5SkxxNU9z6HF D+MXFtl9bcj19KmOG4m4pIdytZc5DL4Yj//oOseR85gUrL2uccSfQCI9uEVpbk6SpYSC VJcDb9kJw3FY2z/zm7scUM+LyR7xFBeh8TWbjLauMZ1jCcxeBpqA+4g2B9/7lzvgzyeD Ut9w== X-Gm-Message-State: APf1xPBOmnyCxEVTuN7mn0LNRFD6WfJUn+CgIEq4dQyxz+ODvqLHAiH3 pFdUldbh/H3VVFR6tvBi9qOAtqpd8To= X-Received: by 10.28.249.21 with SMTP id x21mr2785616wmh.114.1519929014513; Thu, 01 Mar 2018 10:30:14 -0800 (PST) Received: from localhost ([217.140.96.141]) by smtp.gmail.com with ESMTPSA id 186sm2506963wmm.32.2018.03.01.10.30.13 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Mar 2018 10:30:13 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Avoid &LOOP_VINFO_MASKS for bb vectorisation (PR 84634) Date: Thu, 01 Mar 2018 18:30:12 +0000 Message-ID: <87po4n8x8r.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 We were computing &LOOP_VINFO_MASKS even for bb vectorisation, which is UB. Tested on aarch64-linux-gnu. OK to install? Richard 2018-03-01 Richard Sandiford gcc/ PR tree-optimization/84634 * tree-vect-stmts.c (vectorizable_store, vectorizable_load): Replace masks and masked_loop_p with a single loop_masks, making sure it's null for bb vectorization. Index: gcc/tree-vect-stmts.c =================================================================== --- gcc/tree-vect-stmts.c 2018-02-20 09:39:34.536228161 +0000 +++ gcc/tree-vect-stmts.c 2018-03-01 18:29:15.280350088 +0000 @@ -6703,13 +6703,16 @@ vectorizable_store (gimple *stmt, gimple alignment_support_scheme = vect_supportable_dr_alignment (first_dr, false); gcc_assert (alignment_support_scheme); - bool masked_loop_p = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)); + vec_loop_masks *loop_masks + = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo) + ? &LOOP_VINFO_MASKS (loop_vinfo) + : NULL); /* Targets with store-lane instructions must not require explicit realignment. vect_supportable_dr_alignment always returns either dr_aligned or dr_unaligned_supported for masked operations. */ gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES && !mask - && !masked_loop_p) + && !loop_masks) || alignment_support_scheme == dr_aligned || alignment_support_scheme == dr_unaligned_supported); @@ -6783,7 +6786,6 @@ vectorizable_store (gimple *stmt, gimple prev_stmt_info = NULL; tree vec_mask = NULL_TREE; - vec_loop_masks *masks = &LOOP_VINFO_MASKS (loop_vinfo); for (j = 0; j < ncopies; j++) { @@ -6900,8 +6902,9 @@ vectorizable_store (gimple *stmt, gimple } tree final_mask = NULL; - if (masked_loop_p) - final_mask = vect_get_loop_mask (gsi, masks, ncopies, vectype, j); + if (loop_masks) + final_mask = vect_get_loop_mask (gsi, loop_masks, ncopies, + vectype, j); if (vec_mask) final_mask = prepare_load_store_mask (mask_vectype, final_mask, vec_mask, gsi); @@ -6949,8 +6952,9 @@ vectorizable_store (gimple *stmt, gimple unsigned align, misalign; tree final_mask = NULL_TREE; - if (masked_loop_p) - final_mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies, + if (loop_masks) + final_mask = vect_get_loop_mask (gsi, loop_masks, + vec_num * ncopies, vectype, vec_num * j + i); if (vec_mask) final_mask = prepare_load_store_mask (mask_vectype, final_mask, @@ -6960,7 +6964,7 @@ vectorizable_store (gimple *stmt, gimple { tree scale = size_int (gs_info.scale); gcall *call; - if (masked_loop_p) + if (loop_masks) call = gimple_build_call_internal (IFN_MASK_SCATTER_STORE, 5, dataref_ptr, vec_offset, scale, vec_oprnd, final_mask); @@ -7790,13 +7794,16 @@ vectorizable_load (gimple *stmt, gimple_ alignment_support_scheme = vect_supportable_dr_alignment (first_dr, false); gcc_assert (alignment_support_scheme); - bool masked_loop_p = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)); + vec_loop_masks *loop_masks + = (loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo) + ? &LOOP_VINFO_MASKS (loop_vinfo) + : NULL); /* Targets with store-lane instructions must not require explicit realignment. vect_supportable_dr_alignment always returns either dr_aligned or dr_unaligned_supported for masked operations. */ gcc_assert ((memory_access_type != VMAT_LOAD_STORE_LANES && !mask - && !masked_loop_p) + && !loop_masks) || alignment_support_scheme == dr_aligned || alignment_support_scheme == dr_unaligned_supported); @@ -7956,7 +7963,6 @@ vectorizable_load (gimple *stmt, gimple_ tree vec_mask = NULL_TREE; prev_stmt_info = NULL; poly_uint64 group_elt = 0; - vec_loop_masks *masks = &LOOP_VINFO_MASKS (loop_vinfo); for (j = 0; j < ncopies; j++) { /* 1. Create the vector or array pointer update chain. */ @@ -8037,8 +8043,9 @@ vectorizable_load (gimple *stmt, gimple_ vec_array = create_vector_array (vectype, vec_num); tree final_mask = NULL_TREE; - if (masked_loop_p) - final_mask = vect_get_loop_mask (gsi, masks, ncopies, vectype, j); + if (loop_masks) + final_mask = vect_get_loop_mask (gsi, loop_masks, ncopies, + vectype, j); if (vec_mask) final_mask = prepare_load_store_mask (mask_vectype, final_mask, vec_mask, gsi); @@ -8083,9 +8090,10 @@ vectorizable_load (gimple *stmt, gimple_ for (i = 0; i < vec_num; i++) { tree final_mask = NULL_TREE; - if (masked_loop_p + if (loop_masks && memory_access_type != VMAT_INVARIANT) - final_mask = vect_get_loop_mask (gsi, masks, vec_num * ncopies, + final_mask = vect_get_loop_mask (gsi, loop_masks, + vec_num * ncopies, vectype, vec_num * j + i); if (vec_mask) final_mask = prepare_load_store_mask (mask_vectype, final_mask, @@ -8107,7 +8115,7 @@ vectorizable_load (gimple *stmt, gimple_ { tree scale = size_int (gs_info.scale); gcall *call; - if (masked_loop_p) + if (loop_masks) call = gimple_build_call_internal (IFN_MASK_GATHER_LOAD, 4, dataref_ptr, vec_offset, scale, final_mask);