From patchwork Fri Mar 3 00:24:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1751144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=siIk/R0I; dkim-atps=neutral Received: from sourceware.org (unknown [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PSTHq1xp9z2467 for ; Fri, 3 Mar 2023 11:24:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 13F183858C62 for ; Fri, 3 Mar 2023 00:24:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 13F183858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677803077; bh=Ns5A/Z0RB5qhek477gUrFwdnFP6X2Iq9Nxcdl7r8CdQ=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=siIk/R0IckIKKyH0sYhK+aUIfWJaS3E45q2JKwgtsrCJejaU3fbQMazJsJRXGguWl jSQr8qyXMlMln+Bb1Cqt/Fwk2Am4/b4oZvjVhRfWFSCvN1qe461vU41ROBPWxdx+8f ISIWsNeG43xW0WHKcSCL/idJiOxPuhG6vFE/ssQ8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050:0:465::202]) by sourceware.org (Postfix) with ESMTPS id C19A63858D37 for ; Fri, 3 Mar 2023 00:24:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C19A63858D37 Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4PSTHK3FVwz9sW2; Fri, 3 Mar 2023 01:24:13 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [committed] d: vector float comparison doesn't result in 0 or -1 [PR108945] Date: Fri, 3 Mar 2023 01:24:11 +0100 Message-Id: <20230303002411.4153820-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, When comparing two vectors, the type of vector was used as the result of the condition result. This meant that for floating point comparisons, each value would either be `0.0' or `-1.0' reinterpreted as an integer, not the expected integral bitmask values `0' and `-1'. Instead, use the comparison type determined by truth_type_for as the result of the comparison. If a reinterpret is later required by the final conversion for generating CmpExp, it is still only going to reinterpret one integer kind as another. Bootstrapped and regression tested on x86_64-linux-gnu/-m32, and committed to mainline. Regards, Iain. --- PR d/108945 gcc/d/ChangeLog: * d-codegen.cc (build_boolop): Evaluate vector comparison as the truth_type_for vector type. gcc/testsuite/ChangeLog: * gdc.dg/pr108945.d: New test. --- gcc/d/d-codegen.cc | 9 ++++----- gcc/testsuite/gdc.dg/pr108945.d | 12 ++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr108945.d diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index 0e8e07366ee..5a041927ec9 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1453,13 +1453,12 @@ build_boolop (tree_code code, tree arg0, tree arg1) { /* Build a vector comparison. VEC_COND_EXPR ; */ - tree type = TREE_TYPE (arg0); - tree cmptype = truth_type_for (type); + tree cmptype = truth_type_for (TREE_TYPE (arg0)); tree cmp = fold_build2_loc (input_location, code, cmptype, arg0, arg1); - return fold_build3_loc (input_location, VEC_COND_EXPR, type, cmp, - build_minus_one_cst (type), - build_zero_cst (type)); + return fold_build3_loc (input_location, VEC_COND_EXPR, cmptype, cmp, + build_minus_one_cst (cmptype), + build_zero_cst (cmptype)); } if (code == EQ_EXPR || code == NE_EXPR) diff --git a/gcc/testsuite/gdc.dg/pr108945.d b/gcc/testsuite/gdc.dg/pr108945.d new file mode 100644 index 00000000000..03b9de8e758 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr108945.d @@ -0,0 +1,12 @@ +// { dg-options "-fdump-tree-gimple" } +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do compile { target { avx_runtime || vect_sizes_16B_8B } } } + +alias f4 = __vector(float[4]); + +auto pr108945(f4 a, f4 b) +{ + return a < b; +} + +// { dg-final { scan-tree-dump-not "VEC_COND_EXPR" "gimple" } }