From patchwork Tue Jul 4 14:39:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kyrill Tkachov X-Patchwork-Id: 784029 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x268Y2bmmz9t2R for ; Wed, 5 Jul 2017 00:39:24 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IapOj4sG"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=Rws+wC5+Sfh5aI86gK5jwhoH742t0SGigU6S6gQ0ztD VlW6f2+lqsrnrVjd3Xsa7zs6o9lCKWiDAKh4RM19TkesIzZ3Ca+5MFsvcquLkFdW gJ2MU2HTxvO1rRrMlS160JLXqU+tEfPqWKe9gDxC2CMjEOP3rjSdyWkL1Q8de0xA = 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 :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=IdqW6f3+u51aWjDuWV2nk2jDeqw=; b=IapOj4sGnqN7E3ZUJ qys6yf9uT7ezy0B4xjpDifzZhmTxzKuRUC/LDEAhOKEnqogBEJoF8TqtBfH5N+p/ S3KvDejVkRTa+seoxNhE6FE0/ak25EI7GpB6cCZd+o4PW2MTgP0nWfrRJDSKWV6J kJ5n+4q0yTnBdatruoD2pz6my0= Received: (qmail 14136 invoked by alias); 4 Jul 2017 14:39:15 -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 13484 invoked by uid 89); 4 Jul 2017 14:39:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Upon X-HELO: foss.arm.com Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jul 2017 14:39:12 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 222942B; Tue, 4 Jul 2017 07:39:11 -0700 (PDT) Received: from [10.2.207.77] (e100706-lin.cambridge.arm.com [10.2.207.77]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 469343F557; Tue, 4 Jul 2017 07:39:10 -0700 (PDT) Message-ID: <595BA88C.2080905@foss.arm.com> Date: Tue, 04 Jul 2017 15:39:08 +0100 From: Kyrill Tkachov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: GCC Patches CC: Marcus Shawcroft , Richard Earnshaw , James Greenhalgh Subject: [PATCH][AArch64] Fix strict aliasing issue in gcc.target/aarch64/simd/vminmaxnm_1.c Hi all, While doing some unrelated work the gcc.target/aarch64/simd/vminmaxnm_1.c testcase started failing for me. Upon investigation it turns out that it breaks the C strict aliasing rules in the CHECK macro by casting a pointer to an incompatible type and dereferencing it. GCC even warns about it if compiled with -Wstrict-aliasing. This patch fixes the testcase by making it use memcmp to compare the vector elements. This avoids the undefined behaviour. The testcase still passes on trunk. Ok to commit? Thanks, Kyrill 2017-07-04 Kyrylo Tkachov * gcc.target/aarch64/simd/vminmaxnm_1.c: Fix strict aliasing issues. diff --git a/gcc/testsuite/gcc.target/aarch64/simd/vminmaxnm_1.c b/gcc/testsuite/gcc.target/aarch64/simd/vminmaxnm_1.c index 192bad9..8fd4281 100644 --- a/gcc/testsuite/gcc.target/aarch64/simd/vminmaxnm_1.c +++ b/gcc/testsuite/gcc.target/aarch64/simd/vminmaxnm_1.c @@ -7,12 +7,10 @@ extern void abort (); -#define CHECK(T, N, R, E) \ +#define CHECK(R, E) \ {\ - int i = 0;\ - for (; i < N; i++)\ - if (* (T *) &R[i] != * (T *) &E[i])\ - abort ();\ + if (__builtin_memcmp (&R, &E, sizeof (R)) != 0)\ + abort ();\ } int @@ -26,8 +24,8 @@ main (int argc, char **argv) float32x2_t f32x2_ret_minnm = vminnm_f32 (f32x2_input1, f32x2_input2); float32x2_t f32x2_ret_maxnm = vmaxnm_f32 (f32x2_input1, f32x2_input2); - CHECK (uint32_t, 2, f32x2_ret_minnm, f32x2_exp_minnm); - CHECK (uint32_t, 2, f32x2_ret_maxnm, f32x2_exp_maxnm); + CHECK (f32x2_ret_minnm, f32x2_exp_minnm); + CHECK (f32x2_ret_maxnm, f32x2_exp_maxnm); /* v{min|max}nm_f32 NaN. */ f32x2_input1 = vdup_n_f32 (__builtin_nanf ("")); @@ -37,8 +35,8 @@ main (int argc, char **argv) f32x2_ret_minnm = vminnm_f32 (f32x2_input1, f32x2_input2); f32x2_ret_maxnm = vmaxnm_f32 (f32x2_input1, f32x2_input2); - CHECK (uint32_t, 2, f32x2_ret_minnm, f32x2_exp_minnm); - CHECK (uint32_t, 2, f32x2_ret_maxnm, f32x2_exp_maxnm); + CHECK (f32x2_ret_minnm, f32x2_exp_minnm); + CHECK (f32x2_ret_maxnm, f32x2_exp_maxnm); /* v{min|max}nmq_f32 normal. */ float32x4_t f32x4_input1 = vdupq_n_f32 (-1024.0); @@ -48,8 +46,8 @@ main (int argc, char **argv) float32x4_t f32x4_ret_minnm = vminnmq_f32 (f32x4_input1, f32x4_input2); float32x4_t f32x4_ret_maxnm = vmaxnmq_f32 (f32x4_input1, f32x4_input2); - CHECK (uint32_t, 4, f32x4_ret_minnm, f32x4_exp_minnm); - CHECK (uint32_t, 4, f32x4_ret_maxnm, f32x4_exp_maxnm); + CHECK (f32x4_ret_minnm, f32x4_exp_minnm); + CHECK (f32x4_ret_maxnm, f32x4_exp_maxnm); /* v{min|max}nmq_f32 NaN. */ f32x4_input1 = vdupq_n_f32 (-__builtin_nanf ("")); @@ -59,8 +57,8 @@ main (int argc, char **argv) f32x4_ret_minnm = vminnmq_f32 (f32x4_input1, f32x4_input2); f32x4_ret_maxnm = vmaxnmq_f32 (f32x4_input1, f32x4_input2); - CHECK (uint32_t, 4, f32x4_ret_minnm, f32x4_exp_minnm); - CHECK (uint32_t, 4, f32x4_ret_maxnm, f32x4_exp_maxnm); + CHECK (f32x4_ret_minnm, f32x4_exp_minnm); + CHECK (f32x4_ret_maxnm, f32x4_exp_maxnm); /* v{min|max}nm_f64 normal. */ float64x1_t f64x1_input1 = vdup_n_f64 (1.23); @@ -69,16 +67,16 @@ main (int argc, char **argv) float64x1_t f64x1_exp_maxnm = vdup_n_f64 (4.56); float64x1_t f64x1_ret_minnm = vminnm_f64 (f64x1_input1, f64x1_input2); float64x1_t f64x1_ret_maxnm = vmaxnm_f64 (f64x1_input1, f64x1_input2); - CHECK (uint64_t, 1, f64x1_ret_minnm, f64x1_exp_minnm); - CHECK (uint64_t, 1, f64x1_ret_maxnm, f64x1_exp_maxnm); + CHECK (f64x1_ret_minnm, f64x1_exp_minnm); + CHECK (f64x1_ret_maxnm, f64x1_exp_maxnm); /* v{min|max}_f64 normal. */ float64x1_t f64x1_exp_min = vdup_n_f64 (1.23); float64x1_t f64x1_exp_max = vdup_n_f64 (4.56); float64x1_t f64x1_ret_min = vmin_f64 (f64x1_input1, f64x1_input2); float64x1_t f64x1_ret_max = vmax_f64 (f64x1_input1, f64x1_input2); - CHECK (uint64_t, 1, f64x1_ret_min, f64x1_exp_min); - CHECK (uint64_t, 1, f64x1_ret_max, f64x1_exp_max); + CHECK (f64x1_ret_min, f64x1_exp_min); + CHECK (f64x1_ret_max, f64x1_exp_max); /* v{min|max}nmq_f64 normal. */ float64x2_t f64x2_input1 = vdupq_n_f64 (1.23); @@ -87,8 +85,8 @@ main (int argc, char **argv) float64x2_t f64x2_exp_maxnm = vdupq_n_f64 (4.56); float64x2_t f64x2_ret_minnm = vminnmq_f64 (f64x2_input1, f64x2_input2); float64x2_t f64x2_ret_maxnm = vmaxnmq_f64 (f64x2_input1, f64x2_input2); - CHECK (uint64_t, 2, f64x2_ret_minnm, f64x2_exp_minnm); - CHECK (uint64_t, 2, f64x2_ret_maxnm, f64x2_exp_maxnm); + CHECK (f64x2_ret_minnm, f64x2_exp_minnm); + CHECK (f64x2_ret_maxnm, f64x2_exp_maxnm); /* v{min|max}nm_f64 NaN. */ f64x1_input1 = vdup_n_f64 (-__builtin_nanf ("")); @@ -98,8 +96,8 @@ main (int argc, char **argv) f64x1_ret_minnm = vminnm_f64 (f64x1_input1, f64x1_input2); f64x1_ret_maxnm = vmaxnm_f64 (f64x1_input1, f64x1_input2); - CHECK (uint64_t, 1, f64x1_ret_minnm, f64x1_exp_minnm); - CHECK (uint64_t, 1, f64x1_ret_maxnm, f64x1_exp_maxnm); + CHECK (f64x1_ret_minnm, f64x1_exp_minnm); + CHECK (f64x1_ret_maxnm, f64x1_exp_maxnm); /* v{min|max}_f64 NaN. */ f64x1_input1 = vdup_n_f64 (-__builtin_nanf ("")); @@ -109,8 +107,8 @@ main (int argc, char **argv) f64x1_ret_minnm = vmin_f64 (f64x1_input1, f64x1_input2); f64x1_ret_maxnm = vmax_f64 (f64x1_input1, f64x1_input2); - CHECK (uint64_t, 1, f64x1_ret_minnm, f64x1_exp_minnm); - CHECK (uint64_t, 1, f64x1_ret_maxnm, f64x1_exp_maxnm); + CHECK (f64x1_ret_minnm, f64x1_exp_minnm); + CHECK (f64x1_ret_maxnm, f64x1_exp_maxnm); /* v{min|max}nmq_f64 NaN. */ f64x2_input1 = vdupq_n_f64 (-__builtin_nan ("")); @@ -120,8 +118,8 @@ main (int argc, char **argv) f64x2_ret_minnm = vminnmq_f64 (f64x2_input1, f64x2_input2); f64x2_ret_maxnm = vmaxnmq_f64 (f64x2_input1, f64x2_input2); - CHECK (uint64_t, 2, f64x2_ret_minnm, f64x2_exp_minnm); - CHECK (uint64_t, 2, f64x2_ret_maxnm, f64x2_exp_maxnm); + CHECK (f64x2_ret_minnm, f64x2_exp_minnm); + CHECK (f64x2_ret_maxnm, f64x2_exp_maxnm); return 0; }