From patchwork Wed May 30 06:46:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 137234 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp4950019lji; Tue, 29 May 2018 23:46:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLru7nDsqdNOsOmJQCBOHL67k9tqnaIi7nyFcnqIXG22WY93G4kpwjeXwbYyvlBf0FH0/rp X-Received: by 2002:a63:7f4e:: with SMTP id p14-v6mr1218401pgn.27.1527662812501; Tue, 29 May 2018 23:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527662812; cv=none; d=google.com; s=arc-20160816; b=oc1d4KE0Km7/oHndaOVP0Nwq5r3r5swZli+O1Hvf8vxHlDJ78tAGwpwOYSi2VhxlQd lL5JDXGclK7rcRFRU7Qc0q9tBwfap06nBryXqqK1A5JH25HEGfE1KoFfSrG0UEOWdbVc Z4tDwTemcF7TPBklr/awDo7WQUsVQN2ESF/XQaNZ2I+SuokPciltwTECsVzw/PGdWph9 mbocCtvWBjfulRf5rPgQI+wK6AmF+FwHZipd6jgyS2+TrigpWCKC6AgFoQHT4+N83HfQ C1lcC+cV99TMLU/miWH2eC3AWzp5pQb7GAT7Jz4kNEium/GZDc/TGIR5a8ygDsaiNECP uE5g== 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=LT0aRHjDoelYc9UxPMzrvpuaTy3WRPEZ6kDZ8wbjSqA=; b=KOg8EfHyuZ9t+lqKaLdi/8SnP7ve7Y+HemlsM5+o3JDg6Z3Pqu7Zt94wE6pyiqpFVy SrtLSVjra4wChU+ZltvLjvWE5y8VdTPkx8rtsFKxSk7h6I/iFoF8UCjVp+jKtUwC5oZZ 4Aop6MKnYg2o8s9OXWfRzHpx5Ol1Y5t03IhmyHBZgEYKR9yqpWl02+pGSj0Nsrrr4Ruj jpnIZF6XHKAQD7co4spb07lWEWFTspJ6r5j70rqQeoDfAYzFMynYJ8v2Dypfv/TCK+r0 y5LOe+84pK1biBGL/noWSx/gHkfMv+BRUfai7GrY9Noky260blFioVJMZc8ihbReDsJF xxVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LHqu9Unq; spf=pass (google.com: domain of gcc-patches-return-478730-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478730-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 o3-v6si13834990pgs.68.2018.05.29.23.46.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 May 2018 23:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-478730-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=LHqu9Unq; spf=pass (google.com: domain of gcc-patches-return-478730-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-478730-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=yCse1VjzpWxcSB8R12gGkvzjj/QgYRLqIgxgYiBiogrN/o3V3BlvE zxmIqiB8ox8TDX4pqSt61LKSd/VzNq1V1jry3j9dXRPLnC1LVzctTJ4VEmcSOBOV hj/pv+hbRCywaLC8hM7hleCMlW3UlHjA2BIFsFgV7YD8IHgCJt3VfU= 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=3g4UKdoa4eLYuQF6Qzy/wN7yqOM=; b=LHqu9UnqFfHhA8VTzvwX Uxa3X/fkY53xALf9lZN9iA0w9azxAQvuRu5CnWgZoroCTL6qfph8+5USoIzvbykJ V+ZdTDrUosrXdmiq0jkGYkCkM6LWDy05IPpUR6ifxaewzpm1PhFxPsz3nUphct6s 09ahG1/zgVP3LgsZ0kt83Dg= Received: (qmail 10468 invoked by alias); 30 May 2018 06:46:41 -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 10458 invoked by uid 89); 30 May 2018 06:46:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr0-f169.google.com Received: from mail-wr0-f169.google.com (HELO mail-wr0-f169.google.com) (209.85.128.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 30 May 2018 06:46:39 +0000 Received: by mail-wr0-f169.google.com with SMTP id i14-v6so28263230wre.2 for ; Tue, 29 May 2018 23:46:38 -0700 (PDT) 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=LT0aRHjDoelYc9UxPMzrvpuaTy3WRPEZ6kDZ8wbjSqA=; b=oIPwEMuOEgOSf9jkubNTVFcn8BlVaBgPBMxlkDgPA6/mFy9ycA9b6mATT2EDUJziBg rQvgRGV1b1ZX6UycBLAiiUof0gU0+0H3YnCmrDsEgmMi0gQn2Q9O/GgthZTQK1Y93POB /5HgegdQUhmyYZ8j//Wc8V0naqdilCvrVK5MCkf940lrEQssbsU2lNEvid1CejxwFDfT RoiBw4qkO5j4aUGct1/qNqlplFpRgBBLqRJSXAhH8A+NCA5/jNMHLqq/Wsq7cF/VAIew hcjAAt+QP1BzVWsrhr3MzGdRsqQWrhVnx8d6KuOxgckC8tyqOuBDKDNIepR63cHTV4OS jdvQ== X-Gm-Message-State: ALKqPwduwEsfrtSt5olK/tzkQlfItDph2W7cqvJczTNiPperNweaMnej 01ezQyU/Ispc8k3w7GEFbiOolZE+hk0= X-Received: by 2002:adf:a9aa:: with SMTP id b39-v6mr1052511wrd.36.1527662796595; Tue, 29 May 2018 23:46:36 -0700 (PDT) Received: from localhost (144.69.7.51.dyn.plus.net. [51.7.69.144]) by smtp.gmail.com with ESMTPSA id m64-v6sm31813758wmb.12.2018.05.29.23.46.35 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 23:46:35 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Fix expand_expr_real_1 handling of BLKmode bitfield references Date: Wed, 30 May 2018 07:46:35 +0100 Message-ID: <87bmcxabec.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 The handling of bitfield references in expand_expr_real_1 includes: machine_mode ext_mode = mode; if (ext_mode == BLKmode && ! (target != 0 && MEM_P (op0) && MEM_P (target) && multiple_p (bitpos, BITS_PER_UNIT))) ext_mode = int_mode_for_size (bitsize, 1).else_blk (); if (ext_mode == BLKmode) { [...] gcc_assert (MEM_P (op0) Here "mode" is the TYPE_MODE of the result, so when mode == BLKmode, the target must be a MEM if nonnull, since no other rtl objects can have BLKmode. But there's no guarantee that the source value op0 is also BLKmode and thus also a MEM: we can reach the assert for any source if the bitsize being extracted is larger than the largest integer mode (or larger than MAX_FIXED_MODE_SIZE). This triggered for SVE with -msve-vector-bits=512, where we could sometimes try to extract a BLKmode value from a 512-bit vector, and where int_mode_for_size would rightly fail for large bitsizes. The patch reuses the existing: /* Otherwise, if this is a constant or the object is not in memory and need be, put it there. */ else if (CONSTANT_P (op0) || (!MEM_P (op0) && must_force_mem)) { memloc = assign_temp (TREE_TYPE (tem), 1, 1); emit_move_insn (memloc, op0); op0 = memloc; clear_mem_expr = true; } to handle this case. Tested on aarch64-linux-gnu (with and without SVE), aarch64_be-elf and x86_64-linux-gnu. OK to install? Richard 2018-05-30 Richard Sandiford gcc/ * expr.c (expand_expr_real_1): Force the operand into memory if its TYPE_MODE is BLKmode and if there is no integer mode for the number of bits being extracted. gcc/testsuite/ * gcc.target/aarch64/sve/extract_5.c: New test. Index: gcc/expr.c =================================================================== --- gcc/expr.c 2018-05-30 07:33:11.652009370 +0100 +++ gcc/expr.c 2018-05-30 07:44:31.856060230 +0100 @@ -10582,6 +10582,8 @@ expand_expr_real_1 (tree exp, rtx target to a larger size. */ must_force_mem = (offset || mode1 == BLKmode + || (mode == BLKmode + && !int_mode_for_size (bitsize, 1).exists ()) || maybe_gt (bitpos + bitsize, GET_MODE_BITSIZE (mode2))); Index: gcc/testsuite/gcc.target/aarch64/sve/extract_5.c =================================================================== --- /dev/null 2018-04-20 16:19:46.369131350 +0100 +++ gcc/testsuite/gcc.target/aarch64/sve/extract_5.c 2018-05-30 07:44:31.857060190 +0100 @@ -0,0 +1,71 @@ +/* Originally from gcc.dg/vect/vect-alias-check-10.c. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -msve-vector-bits=512" } */ + +#define N 87 +#define M 6 + +typedef signed char sc; +typedef unsigned char uc; +typedef signed short ss; +typedef unsigned short us; +typedef int si; +typedef unsigned int ui; +typedef signed long long sll; +typedef unsigned long long ull; + +#define FOR_EACH_TYPE(M) \ + M (sc) M (uc) \ + M (ss) M (us) \ + M (si) M (ui) \ + M (sll) M (ull) \ + M (float) M (double) + +#define TEST_VALUE(I) ((I) * 5 / 2) + +#define ADD_TEST(TYPE) \ + void __attribute__((noinline, noclone)) \ + test_##TYPE (TYPE *a, int step) \ + { \ + for (int i = 0; i < N; ++i) \ + { \ + a[i * step + 0] = a[i * step + 0] + 1; \ + a[i * step + 1] = a[i * step + 1] + 2; \ + a[i * step + 2] = a[i * step + 2] + 4; \ + a[i * step + 3] = a[i * step + 3] + 8; \ + } \ + } \ + void __attribute__((noinline, noclone)) \ + ref_##TYPE (TYPE *a, int step) \ + { \ + for (int i = 0; i < N; ++i) \ + { \ + a[i * step + 0] = a[i * step + 0] + 1; \ + a[i * step + 1] = a[i * step + 1] + 2; \ + a[i * step + 2] = a[i * step + 2] + 4; \ + a[i * step + 3] = a[i * step + 3] + 8; \ + asm volatile (""); \ + } \ + } + +#define DO_TEST(TYPE) \ + for (int j = -M; j <= M; ++j) \ + { \ + TYPE a[N * M], b[N * M]; \ + for (int i = 0; i < N * M; ++i) \ + a[i] = b[i] = TEST_VALUE (i); \ + int offset = (j < 0 ? N * M - 4 : 0); \ + test_##TYPE (a + offset, j); \ + ref_##TYPE (b + offset, j); \ + if (__builtin_memcmp (a, b, sizeof (a)) != 0) \ + __builtin_abort (); \ + } + +FOR_EACH_TYPE (ADD_TEST) + +int +main (void) +{ + FOR_EACH_TYPE (DO_TEST) + return 0; +}