From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by sourceware.org (Postfix) with ESMTPS id 52F1E3875DD1 for ; Wed, 8 Nov 2023 16:18:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 52F1E3875DD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 52F1E3875DD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699460308; cv=none; b=N60hvSMguDRhc9zht997Z5Duv/AFHJXbacktKpVVVg+tzcpQWrorchDwDzc0zutYDZJZyUUiYPeuh4gJduNDWj+pgdfQfMJYeTNyByyWfFItWk6iAFGbmgT9QsPkl5+WpfA50EtRfLA0GJ0BHyX8uEJ/rRsGGYL93MTwVbdQU6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699460308; c=relaxed/simple; bh=yKlbWhJvFZtITxwcvBNGt4Hwpso3CZ8fI5TMlTSbvxY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=NaI/1hCddj8jqcvwXQ0UYD0jaDzlQclWoclc/0DAbxx843E6VXSiNnfH/9QgUwHOmNDyrEfBXRx6xIlTP3AxlFXJw4S8CwyLnQgjS/bM9fAioHRUeJErtCrL2mKVFqtwF9WZBC3JO642mPfaNkWrc9KMzTUQh9FjvWZDnFjawe4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2c.google.com with SMTP id 006d021491bc7-5849fc56c62so4061233eaf.3 for ; Wed, 08 Nov 2023 08:18:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699460305; x=1700065105; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Ne9/JEYzONwpa5WMtEKTeC2xKQhHkqbI2NCWpNaDXDY=; b=NG6knUErR8tWx1Xva/CFDNvHAQPZR78mXWN+FJVvW5At8nfSapnui31/siOADyoYYD TAaTGN7Hj4rXwIwMoVrdmdS4l9cHG8uJI5tcBCedsSf7rRRBtCEbfNlBTPEsGiSPwEBX ZTQQ4yv26X6OI8/eGHXYxx4k7PMgYa+Twnbrd/91EZynFROwcFrR8X32rn9nYAb+a5Qa yXkHzBJS3Pjb0L3lzJCuvBDyij1OSItE8SA7a3gVOpFsz7YfW11xpy4HzKGGCh3V7O1l +ZFWikGn2fCx2+ZdnMA57ga3YXVRnRJfH8k8BvKfCtVFt0lp2tvTtoGp8uTIJ2T23z16 V5tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699460305; x=1700065105; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ne9/JEYzONwpa5WMtEKTeC2xKQhHkqbI2NCWpNaDXDY=; b=NCbcW1IEDqqktOywDUD+aVDKmPyxnoyd4vI8ZPSom1chFKfwfkiuMGNjTL6AoprbAb bkF0FiGusEklZcJlY0SdlTY4BWHP/HjzCnrrhUAh0ZCc5UL7uXfR4oqQF5HdGq132hjv ALPnfx18llsgmapF4s0tg1DZi31mSErBxgKf3M0ak2Mb3LV7OH2Qj9cVUQw27AIAK/er Cy8n5SjmkJpW1dlq7zbpXm9cMC1m8HoKpCyOkBrWmiGtBc+lTq33bLC0W7OvHObr2wnD GYEydSNO6Pe4dy71t936vlg596WJ28EjDbENVw8WKbxWmhQnlxnxrjRx38KNQPk1SwDf pdwg== X-Gm-Message-State: AOJu0Yxlloc1zcn6HPHL4Riv8E7GrAwH2Gj4NgEHcEX7KimIrD4Qa+95 RTI35wPFDnfT3rRp0boo1d/28fvh5rI= X-Google-Smtp-Source: AGHT+IF1IQgXvwCGRQOo1kj+bCM+MrF+EPMfxqTvM6uT6yCknyQuh985CdP5b9bySYlx9hLGuWzchw== X-Received: by 2002:a4a:e6d0:0:b0:571:28d5:2c71 with SMTP id v16-20020a4ae6d0000000b0057128d52c71mr2346184oot.2.1699460305602; Wed, 08 Nov 2023 08:18:25 -0800 (PST) Received: from [192.168.1.23] (ip-046-223-203-173.um13.pools.vodafone-ip.de. [46.223.203.173]) by smtp.gmail.com with ESMTPSA id u1-20020a4a8c01000000b00584078d1e17sm338494ooj.45.2023.11.08.08.18.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Nov 2023 08:18:25 -0800 (PST) Message-ID: Date: Wed, 8 Nov 2023 17:18:22 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com Content-Language: en-US To: gcc-patches , Tamar Christina From: Robin Dapp Subject: [PATCH] vect: Use statement vectype for conditional mask. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, as Tamar reported in PR112406 we still ICE on aarch64 in SPEC2017 when creating COND_OPs in ifcvt. The problem is that we fail to deduce the mask's type from the statement vectype and then end up with a non-matching mask in expand. This patch checks if the current op is equal to the mask operand and, if so, uses the truth type from the stmt_vectype. Is that a valid approach? Bootstrapped and regtested on aarch64, x86 is running. Besides, the testcase is Tamar's reduced example, originally from SPEC. I hope it's ok to include it as is (as imagick is open source anyway). Regards Robin gcc/ChangeLog: PR middle-end/112406 * tree-vect-stmts.cc (vect_get_vec_defs_for_operand): Handle masks of conditional ops. gcc/testsuite/ChangeLog: * gcc.dg/pr112406.c: New test. --- gcc/testsuite/gcc.dg/pr112406.c | 37 +++++++++++++++++++++++++++++++++ gcc/tree-vect-stmts.cc | 20 +++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr112406.c diff --git a/gcc/testsuite/gcc.dg/pr112406.c b/gcc/testsuite/gcc.dg/pr112406.c new file mode 100644 index 00000000000..46459c68c4a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr112406.c @@ -0,0 +1,37 @@ +/* { dg-do compile { target { aarch64*-*-* } } } */ +/* { dg-options "-march=armv8-a+sve -w -Ofast" } */ + +typedef struct { + int red +} MagickPixelPacket; + +GetImageChannelMoments_image, GetImageChannelMoments_image_0, + GetImageChannelMoments___trans_tmp_1, GetImageChannelMoments_M11_0, + GetImageChannelMoments_pixel_3, GetImageChannelMoments_y, + GetImageChannelMoments_p; + +double GetImageChannelMoments_M00_0, GetImageChannelMoments_M00_1, + GetImageChannelMoments_M01_1; + +MagickPixelPacket GetImageChannelMoments_pixel; + +SetMagickPixelPacket(int color, MagickPixelPacket *pixel) { + pixel->red = color; +} + +GetImageChannelMoments() { + for (; GetImageChannelMoments_y; GetImageChannelMoments_y++) { + SetMagickPixelPacket(GetImageChannelMoments_p, + &GetImageChannelMoments_pixel); + GetImageChannelMoments_M00_1 += GetImageChannelMoments_pixel.red; + if (GetImageChannelMoments_image) + GetImageChannelMoments_M00_1++; + GetImageChannelMoments_M01_1 += + GetImageChannelMoments_y * GetImageChannelMoments_pixel_3; + if (GetImageChannelMoments_image_0) + GetImageChannelMoments_M00_0++; + GetImageChannelMoments_M01_1 += + GetImageChannelMoments_y * GetImageChannelMoments_p++; + } + GetImageChannelMoments___trans_tmp_1 = atan(GetImageChannelMoments_M11_0); +} diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc index 65883e04ad7..6793b01bf44 100644 --- a/gcc/tree-vect-stmts.cc +++ b/gcc/tree-vect-stmts.cc @@ -1238,10 +1238,28 @@ vect_get_vec_defs_for_operand (vec_info *vinfo, stmt_vec_info stmt_vinfo, tree stmt_vectype = STMT_VINFO_VECTYPE (stmt_vinfo); tree vector_type; + /* For a COND_OP the mask operand's type must not be deduced from the + scalar type but from the statement's vectype. */ + bool use_stmt_vectype = false; + gcall *call; + if ((call = dyn_cast (STMT_VINFO_STMT (stmt_vinfo))) + && gimple_call_internal_p (call)) + { + internal_fn ifn = gimple_call_internal_fn (call); + int mask_idx = -1; + if (ifn != IFN_LAST + && (mask_idx = internal_fn_mask_index (ifn)) != -1) + { + tree maskop = gimple_call_arg (call, mask_idx); + if (op == maskop) + use_stmt_vectype = true; + } + } + if (vectype) vector_type = vectype; else if (VECT_SCALAR_BOOLEAN_TYPE_P (TREE_TYPE (op)) - && VECTOR_BOOLEAN_TYPE_P (stmt_vectype)) + && (use_stmt_vectype || VECTOR_BOOLEAN_TYPE_P (stmt_vectype))) vector_type = truth_type_for (stmt_vectype); else vector_type = get_vectype_for_scalar_type (loop_vinfo, TREE_TYPE (op)); -- 2.41.0