From patchwork Sat Dec 9 02:24:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 176111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5840976vqy; Fri, 8 Dec 2023 18:25:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOXun6VmmIGid5a0BLdnKf/HkvYctWRVYD6YN0TOI+fI+FLOZgLQ4bKvY/bkxJG4a5DBe/ X-Received: by 2002:a05:620a:389d:b0:77f:3cb9:8b5c with SMTP id qp29-20020a05620a389d00b0077f3cb98b5cmr1087113qkn.18.1702088710469; Fri, 08 Dec 2023 18:25:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702088710; cv=pass; d=google.com; s=arc-20160816; b=aJGvSL7OW+nJ0t158I5smz7nL2xRt+5/Sgr7hJLK85PnmKcaeLm6aI11MBijyQzpGg Odq/NSa+rNK9Ufkz/UOnFnDClxfsFyBw56tgDDX1f52CtL9j/k5Yu+rbBEc0pY53X94G Wboyl4PN+S7i9YkFi+fyduex126kJwIOJabjP8QHHztbbjswexH1z/6mPqkGAatWVmds ydE4rTVqKgHlWSI60fJg6lOHjG1YP/QIvS4ldgwz18N2HERfm+Y71yLVU20n/FbQyvi1 QC0I2yTuvDxQt+3bSbCGGNL5qfgfV3PQ4mCC9Fp7Xzxp/D/bAaddAjz8PpOiLpY10/S5 K6VA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:date:organization:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=gIv7XZ+q4FO3ZXr5O7V+b2am7XSHSyHM9+uPSIEH8Pw=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=VH/How6Ir3RE5FR1hGmmNhIAxstZAuYuHX/uG6bZsqGWqyoeycoD+Bj4w9WKk1vS7R SgF7UsAcAhZ4Az7h/WLww8PNgDtSfyTQEJhURhQNXDuUUhFhWMNXo4BBbCtxV6k3Kpm2 6jJZA77443ure1GWM2ROIIR7MlkV9w9PpOs1Kh4u2tVDL0GPkniXPGPUi9VvM2bUaLCv maeoeDIWGcISU+nyCyG9ovX/uZucRlu7QWdcCvMnsYiYXUq75X1MME/HrUpADCcmbinG Hq9ip1PCyHNTuDiDKPeTz4KZ5Q1w3K5tPKUUN+I1Sk6gwiwAO61E3/xPg2+xaKqS+4V4 LF7A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=Oj1ayrLE; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i16-20020a05620a145000b0077f2f5ccde6si3161192qkl.199.2023.12.08.18.25.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 18:25:10 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=Oj1ayrLE; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E4393858419 for ; Sat, 9 Dec 2023 02:25:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id D48BC3858C2D for ; Sat, 9 Dec 2023 02:24:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D48BC3858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D48BC3858C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::22c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702088687; cv=none; b=XLQd9+JU1iDhxiEk7WyAbWH0ugffp2G3Wq9HvAAgIxWvdJPt0rUBzeD5faK+/NKT9/KyLuLOKUCiZG+X1DLQ7H2poIpf1NmljWDDpdG8y5ip0+beNIdMvO9n5Ug0LxhXC1q+1jlWdtQY4GATQGDjq7PbtHFrsEJkI8bGJPggozg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702088687; c=relaxed/simple; bh=hK8NUUXbhaWx0ziQ/Ss/LVnKh0fEl4jDOGnGuwlPzcg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NYD9CBs5hMS22ecyDXgKyXbAnMBf4eMyayJk7YCQZmE6s8ske3WZlW9KT0u/Y2O6/3AYTxBjQH0NVy8M1BqYNm0rWzvZE56dAl4sLB567UPNRmeteSZ6gI3lcDzALxNR6oNPUwRbaBSa9hMYwPb0oZmz1D+2GDaVa+gsS3mIjV4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3b8b8372e30so1821288b6e.3 for ; Fri, 08 Dec 2023 18:24:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1702088685; x=1702693485; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=gIv7XZ+q4FO3ZXr5O7V+b2am7XSHSyHM9+uPSIEH8Pw=; b=Oj1ayrLE1m0wxOvqGfEUR6iQyDH/lCwpS9HmR/Qx0/GTp5R05DGG4WhKpaJBszm4KR BDTPRUMv6K0tDqUgMamYCtXL7kZiz6AfXUFlKxYWT7yuvUUiTDA0LUseN+lKTkb9o5Zn 2BOTjbhz6U1tpI+A4JskIoHL/y3vrTdDmz7k4KUAqgphVi6Rq0ERVUeKDa3UsQpBKynV OGJuj5S4f/JfT9zp/3CK8ugSzEIxKqf6sRI7v4XJrMIDzR8PnBwdTHXyAn4p5EUPrbcG Rnx6Z3npt0ZIIE4u/vpQEcekoFxxWjFeeNnvlqudHYDvf6tHQqXXor3BapQKAbgX42BB 5JUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702088685; x=1702693485; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gIv7XZ+q4FO3ZXr5O7V+b2am7XSHSyHM9+uPSIEH8Pw=; b=Fhnh+E5HI+QdhgXHPedl1u9SZ7yc4MZCKWaDXyw2qji2zHt4OZvKu/80E6Y9stIAuq IS4o+GjaYyQPyufO7Z01piyjPaRkD7vWhVgtT76Fg/YH/9USs9F7iUaOgq1qoILQwZOY BOZQH94TgDdiktO706bo8Yx+c4778tjg09XU/hqYY2+AeCQwbFw7589SLNOMGaQTMgSQ qMiH0c4+Og3OUt8KvbgmIPw2Ug4JRy9XtqRzPC8jcQmQp36IKDbxJKARtQgCqadf/efL MgKpQpQphAPkGJeM76M4x1QVIl+keh4V55tC17Dzh2OZBPS7QsBNV463W4wOUYygtPMh rCWQ== X-Gm-Message-State: AOJu0YwP4mPKtLhRTixxs0JIYOhFVVmdYQWA5tF9s6QjRhdynLpvDfM0 tPhOg60cWn3oePM5zfUqlRpvDUf05vdGgwnC4NrYHg== X-Received: by 2002:a05:6808:38c5:b0:3b9:dd4e:d87b with SMTP id el5-20020a05680838c500b003b9dd4ed87bmr1318458oib.65.1702088685128; Fri, 08 Dec 2023 18:24:45 -0800 (PST) Received: from free.home ([2804:7f1:2080:b40a:22de:62ca:39d7:fbd4]) by smtp.gmail.com with ESMTPSA id 16-20020a056a00071000b006ce921da705sm2231694pfl.136.2023.12.08.18.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 18:24:44 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3B92OaIb317630 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 8 Dec 2023 23:24:36 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH] -finline-stringops: avoid too-wide smallest_int_mode_for_size [PR112784] Organization: Free thinker, does not speak for AdaCore Date: Fri, 08 Dec 2023 23:24:36 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784769371665623726 X-GMAIL-MSGID: 1784769371665623726 smallest_int_mode_for_size may abort when the requested mode is not available. Call int_mode_for_size instead, that signals the unsatisfiable request in a more graceful way. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog PR middle-end/112784 * expr.cc (emit_block_move_via_loop): Call int_mode_for_size for maybe-too-wide sizes. (emit_block_cmp_via_loop): Likewise. for gcc/testsuite/ChangeLog PR middle-end/112784 * gcc.target/i386/avx512cd-inline-stringops-pr112784.c: New. --- gcc/expr.cc | 22 ++++++++++++-------- .../i386/avx512cd-inline-stringops-pr112784.c | 12 +++++++++++ 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c diff --git a/gcc/expr.cc b/gcc/expr.cc index 6da51f2aca296..178b3ec6d5adb 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -2449,15 +2449,17 @@ emit_block_move_via_loop (rtx x, rtx y, rtx size, } emit_move_insn (iter, iter_init); - scalar_int_mode int_move_mode - = smallest_int_mode_for_size (incr * BITS_PER_UNIT); - if (GET_MODE_BITSIZE (int_move_mode) != incr * BITS_PER_UNIT) + opt_scalar_int_mode int_move_mode + = int_mode_for_size (incr * BITS_PER_UNIT, 1); + if (!int_move_mode.exists () + || (GET_MODE_BITSIZE (as_a (int_move_mode)) + != incr * BITS_PER_UNIT)) { move_mode = BLKmode; gcc_checking_assert (can_move_by_pieces (incr, align)); } else - move_mode = int_move_mode; + move_mode = as_a (int_move_mode); x_addr = force_operand (XEXP (x, 0), NULL_RTX); y_addr = force_operand (XEXP (y, 0), NULL_RTX); @@ -2701,16 +2703,18 @@ emit_block_cmp_via_loop (rtx x, rtx y, rtx len, tree len_type, rtx target, iter = gen_reg_rtx (iter_mode); emit_move_insn (iter, iter_init); - scalar_int_mode int_cmp_mode - = smallest_int_mode_for_size (incr * BITS_PER_UNIT); - if (GET_MODE_BITSIZE (int_cmp_mode) != incr * BITS_PER_UNIT - || !can_compare_p (NE, int_cmp_mode, ccp_jump)) + opt_scalar_int_mode int_cmp_mode + = int_mode_for_size (incr * BITS_PER_UNIT, 1); + if (!int_cmp_mode.exists () + || (GET_MODE_BITSIZE (as_a (int_cmp_mode)) + != incr * BITS_PER_UNIT) + || !can_compare_p (NE, as_a (int_cmp_mode), ccp_jump)) { cmp_mode = BLKmode; gcc_checking_assert (incr != 1); } else - cmp_mode = int_cmp_mode; + cmp_mode = as_a (int_cmp_mode); /* Save the base addresses. */ x_addr = force_operand (XEXP (x, 0), NULL_RTX); diff --git a/gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c b/gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c new file mode 100644 index 0000000000000..c81f99c693c24 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/avx512cd-inline-stringops-pr112784.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-mavx512cd -finline-stringops" } */ + +struct S { + int e; +} __attribute__((aligned(128))); + +int main() { + struct S s1; + struct S s2; + int v = __builtin_memcmp(&s1, &s2, sizeof(s1)); +}