From patchwork Sat Nov 2 11:14:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 287972 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BFCEE2C00E2 for ; Sat, 2 Nov 2013 22:14:38 +1100 (EST) 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:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=gMgDezGcZwpFXZCEimcIu3GiEJePvlNV3w9DLoGLEjZ3hGzhIt E/HKig22FbBmXsCPreljfvVddTkPLcDNRF51IGTiTezogapjSA0YXpNDv0s2gnO2 PEezr+7sifUYvY4euT8UPdM2EbI/2etOcGELGyu0fF3f3qi/zPLq9fbNI= 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:cc:subject:date:message-id:mime-version:content-type; s= default; bh=9qsEdqa8ZPcqi14fmFZaQs08DvI=; b=hUavep++3fccrtDQvgo4 YIsaiW1I30OZSsYCE1kGuEYabkDXZ063ajKIR5trdC6H30s6cEclEXlvQWq8KUyM SNBzpWH8DZ68QhE5GFB9Stfh66dP42no1AuhHRgftMfDlLW6J22ubOj0cr03iugx BnxLJCngRmIwU3JIqFLiscg= Received: (qmail 29696 invoked by alias); 2 Nov 2013 11:14:31 -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 29683 invoked by uid 89); 2 Nov 2013 11:14:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f181.google.com Received: from mail-wi0-f181.google.com (HELO mail-wi0-f181.google.com) (209.85.212.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 02 Nov 2013 11:14:29 +0000 Received: by mail-wi0-f181.google.com with SMTP id ex4so2054599wid.8 for ; Sat, 02 Nov 2013 04:14:26 -0700 (PDT) X-Received: by 10.180.39.34 with SMTP id m2mr5665183wik.26.1383390866755; Sat, 02 Nov 2013 04:14:26 -0700 (PDT) Received: from localhost ([2.28.235.51]) by mx.google.com with ESMTPSA id ey4sm16330214wic.11.2013.11.02.04.14.26 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Sat, 02 Nov 2013 04:14:26 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, zadeck@naturalbridge.com, mikestump@comcast.net, rdsandiford@googlemail.com Cc: zadeck@naturalbridge.com, mikestump@comcast.net Subject: [wide-int] Fix fold_ternary VEC_PERM_EXPR handling Date: Sat, 02 Nov 2013 11:14:25 +0000 Message-ID: <87txfvjbse.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 The wide-int conversion for the fold_ternary VEC_PERM_EXPR case converted a mask of valid element numbers to an element count, which is one greater. The old code set need_mask_canon if an index was greater than the mask, but the new code sets it if an index is greater than the element count, giving an off-by-one error. This patch restores the mainline mask handling and uses that in the gtu_p call instead. Tested on powerpc64-linux-gnu and x86_64-linux-gnu. It fixes some unwanted testsuite differences for one of the ARM targets. OK to install? Thanks, Richard Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2013-11-02 11:07:33.097149207 +0000 +++ gcc/fold-const.c 2013-11-02 11:07:38.107188425 +0000 @@ -14360,7 +14360,7 @@ fold_ternary_loc (location_t loc, enum t case VEC_PERM_EXPR: if (TREE_CODE (arg2) == VECTOR_CST) { - unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i; + unsigned int nelts = TYPE_VECTOR_SUBPARTS (type), i, mask; unsigned char *sel = XALLOCAVEC (unsigned char, nelts); bool need_mask_canon = false; bool all_in_vec0 = true; @@ -14368,23 +14368,22 @@ fold_ternary_loc (location_t loc, enum t bool maybe_identity = true; bool single_arg = (op0 == op1); bool changed = false; - int nelts_cnt = single_arg ? nelts : nelts * 2; + mask = single_arg ? (nelts - 1) : (2 * nelts - 1); gcc_assert (nelts == VECTOR_CST_NELTS (arg2)); for (i = 0; i < nelts; i++) { tree val = VECTOR_CST_ELT (arg2, i); - if (TREE_CODE (val) != INTEGER_CST) return NULL_TREE; /* Make sure that the perm value is in an acceptable range. */ wide_int t = val; - if (wi::gtu_p (t, nelts_cnt)) + if (wi::gtu_p (t, mask)) { need_mask_canon = true; - sel[i] = t.to_uhwi () & (nelts_cnt - 1); + sel[i] = t.to_uhwi () & mask; } else sel[i] = t.to_uhwi ();