From patchwork Thu Nov 23 15:23:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1867832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=N1KR3Nz6; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Sbhjc0lrHz1ySN for ; Fri, 24 Nov 2023 02:24:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 554E0386180D for ; Thu, 23 Nov 2023 15:24:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 133243857C70 for ; Thu, 23 Nov 2023 15:24:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 133243857C70 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 133243857C70 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700753046; cv=none; b=p/Q6H3QypsXl9aLxUgOXnWitBJYbDMCPvspdHBXbodENRtZJOJUeVGsub13KbOid2P5n9OvterQOwCKp/tAi5cHYOnGWFDGv/ANeCxVi7wQ/jCzDU/h0vTBn7uLGU/0kkIUnmygJ8chof6hMPe6qy44VZzpQyWNMHCZ12uebC6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700753046; c=relaxed/simple; bh=a7cymj+G+fdOaCkfpgnzWsL3f/P5RhpsBDfE2I1yJFc=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=VFQWaGIyuXhear9a+L0JizcsGmauUwJMnwyXFK9rP9P9z0xIW+ec8Dykm+Xt4BQL1RbeUarJzxM4HZFArnqZe3ePG78EhKl4uYgpp0qCQr59FFKjDkMetXyFTW9cgfjaUsNyRTjuPF+zQ1yDmXIr7J8nvwH/EPsPruS6v2rjuP4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52e.google.com with SMTP id 4fb4d7f45d1cf-548ce28fd23so1362974a12.3 for ; Thu, 23 Nov 2023 07:24:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700753043; x=1701357843; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=CyIQqGSdj9Sky8cUPGuo9HUdRtecOL4V03boK4qyPVg=; b=N1KR3Nz6+Cq6vYkyw6BcQC27iFtqxHsfLsu2lhkx/vL/nolY3cdeVsIZicbWcqyI/5 uGfTDAocuOyA9xJQWLyo8OHp2vwur5KGWl3ZSEq17g5TmxFLzu7uSuoDdggXjUDVv088 Z6lidZ6P/HB2o2qRv+vxMn7bxHunM1FRe6JFHhfHKHbVoSr9TSgFSKgSoiBAXPAqeBD1 SUMXhyYEzSqehUX6S8GHaPjotoz/uG8+HMDkM0EaDeiCAEd5Kdsw0VNDRd5ymKV8/Z2q sTMoBLe6bqo82YRe/O8JyaVp5gJ81PoqxvE0OS570sov6gHNYn3gdgeARaihGyeftkYi dbPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700753043; x=1701357843; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CyIQqGSdj9Sky8cUPGuo9HUdRtecOL4V03boK4qyPVg=; b=ex1fna+Z0X2zrByRg4ptSJMdplOFb9YT3SMwva5evNeB9ikqmDYNgzBr24zUDYYd3U M4IxPAYbK7Acf0U8bBAkbPqWZtUmDAoq1YlKuQcZG+ECs1UsGFxMsM8MlB/Pps1wgfne koRjp8cfEZyhrQ7gtdQJ4yomkEk7sRrmWUb+Ln+gkDcHTPgNYVNrTunHALsRoaLr7ZjE ftV3S75HHt8iZOyADqyTn5rfSwFW/becqO5cPYjj97n5YzrvNZFY7lmtBpyRA++mC4BO WXUR8ktLTQ1bnYnAqJKVSs55SUpKxznUFAiF7sM1dn+hRp5dDMm8+myHIu3Rt6LpqlIK XqmA== X-Gm-Message-State: AOJu0YxyxdG/dudycnGMcq5AFiYQroODdA0DecwYUFWWvjX2Lt1ERvHP V+qJtMbO0jGZqdgzOJAMUzRQy7bCnP44bEDLVgjAgGBrrsVyUQ== X-Google-Smtp-Source: AGHT+IHNY1Do4LaMiEy+KN4S0OvtDsDIdrBjdfBTxDtWRwKLOhRyUqBc3qT9hsYgBlKIbyjI2hg1qgUPuWKx4fINrC4= X-Received: by 2002:a50:ee9a:0:b0:544:a153:cd19 with SMTP id f26-20020a50ee9a000000b00544a153cd19mr4133397edr.41.1700753043409; Thu, 23 Nov 2023 07:24:03 -0800 (PST) MIME-Version: 1.0 From: Uros Bizjak Date: Thu, 23 Nov 2023 16:23:52 +0100 Message-ID: Subject: [committed] i386: Wrong code with __builtin_parityl [PR112672] To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, 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 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+incoming=patchwork.ozlabs.org@gcc.gnu.org gen_parityhi2_cmp instruction clobbers its input operand, so use a temporary register in the call to gen_parityhi2_cmp. PR target/112672 gcc/ChangeLog: * config/i386/i386.md (parityhi2): Use temporary register in the call to gen_parityhi2_cmp. gcc/testsuite/ChangeLog: * gcc.target/i386/pr112672.c: New test. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros. diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 99bb909b244..41de9537a40 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -20031,8 +20031,10 @@ (define_expand "parityhi2" "! TARGET_POPCNT" { rtx scratch = gen_reg_rtx (QImode); + rtx tmp = gen_reg_rtx (HImode); - emit_insn (gen_parityhi2_cmp (operands[1])); + emit_move_insn (tmp, operands[1]); + emit_insn (gen_parityhi2_cmp (tmp)); ix86_expand_setcc (scratch, ORDERED, gen_rtx_REG (CCmode, FLAGS_REG), const0_rtx); diff --git a/gcc/testsuite/gcc.target/i386/pr112672.c b/gcc/testsuite/gcc.target/i386/pr112672.c new file mode 100644 index 00000000000..583e9fdfb8b --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr112672.c @@ -0,0 +1,23 @@ +/* PR target/112672 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +typedef unsigned short u16; + +u16 g = 254; + +static inline u16 +foo (u16 u) +{ + u *= g; + return u + __builtin_parityl (u); +} + +int +main (void) +{ + u16 x = foo (4); + if (x != 4 * 254 + 1) + __builtin_abort (); + return 0; +}