From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 745D93858C24 for ; Fri, 5 Apr 2024 10:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 745D93858C24 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 745D93858C24 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712311878; cv=none; b=HFs/u2VsWs/kX719FBPWfeSCL4uGgyx8lFLqdINwo1DICuP6QvivRqUafi9i4PTGJ/cOBnPZ1R/q3k17xf403BB01cSpqC/v3MIaLEsO/mwjw8nzkDxrvDhkUEjn+0m8cemxGNDvyzKmkmOtPFxrjLHxxVGIpgkAoU3LCZ/uTVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712311878; c=relaxed/simple; bh=2APBJS1NDHXKB62HyHqax/OWtTMr5hC8Nt92RVRRuGs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=LvZjpcsKY3bQ7e3T4qMxTRfV0s8W2S30pS7mlp5S/F952DY0cWxPN7ixu8/fjshyHXNq7HjCdSNle6OT4gTNRKupHh/H1UAG/IrN/u1QrUp5Hwt68CxgyPS7GGrilq0J6bLA7M/UcAC7WhqR0T1FcgbOQ72edPOjaRXW7sIOyzg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712311875; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=M1MMF9f6eVo6UAsbgPCbwF0i6oLxgYiouXhl7y+e/9w=; b=bbOCHodHU7kf/nRNrPde+nh3tz9T+WiomYtQPSQHBI9ufn9CQqjnrjUL6fJ5v7/+pbm8Gt xdWO+5vQcMS1XnKE7zGm72hXI2PqXH3SGn6BRWkBw2wK+7YulrWijEKDR7hrR9XBk9AHWu B86NavczWMfec0+9D7LXQNug/QDEHBQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-O9Zn5B8vOvKeoMGt10hyeA-1; Fri, 05 Apr 2024 06:11:13 -0400 X-MC-Unique: O9Zn5B8vOvKeoMGt10hyeA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40BA0101A531; Fri, 5 Apr 2024 10:11:13 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E01372166AE6; Fri, 5 Apr 2024 10:11:12 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 435AB76V2450022 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 5 Apr 2024 12:11:07 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 435AB7x62450021; Fri, 5 Apr 2024 12:11:07 +0200 Date: Fri, 5 Apr 2024 12:11:06 +0200 From: Jakub Jelinek To: Richard Biener , Andre Vieira Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] vect: Don't clear base_misaligned in update_epilogue_loop_vinfo [PR114566] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP 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! The following testcase is miscompiled, because in the vectorized epilogue the vectorizer assumes it can use aligned loads/stores (if the base decl gets alignment increased), but it actually doesn't increase that. This is because r10-4203-g97c1460367 added the hunk following patch removes. The explanation feels reasonable, but actually it is not true as the testcase proves. The thing is, we vectorize the main loop with 64-byte vectors and the corresponding data refs have base_alignment 16 (the a array has DECL_ALIGN 128) and offset_alignment 32. Now, because of the offset_alignment 32 rather than 64, we need to use unaligned loads/stores in the main loop (and ditto in the first load/store in vectorized epilogue). But the second load/store in the vectorized epilogue uses only 32-byte vectors and because it is a multiple of offset_alignment, it checks if we could increase alignment of the a VAR_DECL, the function returns true, sets base_misaligned = true and says the access is then aligned. But when update_epilogue_loop_vinfo clears base_misaligned with the assumption that the var had to have the alignment increased already, the update of DECL_ALIGN doesn't happen anymore. Now, I'd think this base_alignment = false was needed before r10-4030-gd2db7f7901 change was committed where it incorrectly overwrote DECL_ALIGN even if it was already larger, rather than just always increasing it. But with that change in, it doesn't make sense to me anymore. Note, the testcase is latent on the trunk, but reproduces on the 13 branch. Bootstrapped/regtested on x86_64-linux and i686-linux on the trunk, plus tested with the testcase on 13 branch with -m32/-m64 without/with the tree-vect-loop.cc patch (where it FAILed before and now PASSes). Ok for trunk? 2024-04-05 Jakub Jelinek PR tree-optimization/114566 * tree-vect-loop.cc (update_epilogue_loop_vinfo): Don't clear base_misaligned. * gcc.target/i386/avx512f-pr114566.c: New test. --- gcc/tree-vect-loop.cc.jj 2024-04-04 00:48:05.932072711 +0200 +++ gcc/tree-vect-loop.cc 2024-04-05 00:59:33.743101468 +0200 @@ -11590,9 +11590,7 @@ find_in_mapping (tree t, void *context) corresponding dr_vec_info need to be reconnected to the EPILOGUE's stmt_vec_infos, their statements need to point to their corresponding copy, if they are gather loads or scatter stores then their reference needs to be - updated to point to its corresponding copy and finally we set - 'base_misaligned' to false as we have already peeled for alignment in the - prologue of the main loop. */ + updated to point to its corresponding copy. */ static void update_epilogue_loop_vinfo (class loop *epilogue, tree advance) @@ -11736,10 +11734,6 @@ update_epilogue_loop_vinfo (class loop * } DR_STMT (dr) = STMT_VINFO_STMT (stmt_vinfo); stmt_vinfo->dr_aux.stmt = stmt_vinfo; - /* The vector size of the epilogue is smaller than that of the main loop - so the alignment is either the same or lower. This means the dr will - thus by definition be aligned. */ - STMT_VINFO_DR_INFO (stmt_vinfo)->base_misaligned = false; } epilogue_vinfo->shared->datarefs_copy.release (); --- gcc/testsuite/gcc.target/i386/avx512f-pr114566.c.jj 2024-04-05 11:21:04.282639386 +0200 +++ gcc/testsuite/gcc.target/i386/avx512f-pr114566.c 2024-04-05 11:21:04.282639386 +0200 @@ -0,0 +1,34 @@ +/* PR tree-optimization/114566 */ +/* { dg-do run } */ +/* { dg-options "-O3 -mavx512f" } */ +/* { dg-additional-options "-fstack-protector-strong" { target fstack_protector } } */ +/* { dg-require-effective-target avx512f } */ + +#define AVX512F +#include "avx512f-helper.h" + +__attribute__((noipa)) int +foo (float x, float y) +{ + float a[8][56]; + __builtin_memset (a, 0, sizeof (a)); + + for (int j = 0; j < 8; j++) + for (int k = 0; k < 56; k++) + { + float b = k * y; + if (b < 0.) + b = 0.; + if (b > 0.) + b = 0.; + a[j][k] += b; + } + + return __builtin_log (x); +} + +void +TEST (void) +{ + foo (86.25f, 0.625f); +} Jakub