From patchwork Tue Aug 13 11:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Manolis Tsamis X-Patchwork-Id: 1971914 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=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=Y9gKZTQ8; 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 4WjqdC0mN4z1yYl for ; Tue, 13 Aug 2024 21:57:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFE203858C60 for ; Tue, 13 Aug 2024 11:57:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 864B63858D34 for ; Tue, 13 Aug 2024 11:57:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 864B63858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 864B63858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723550228; cv=none; b=ooSHO1SAD6vY3D5jg0oY2gGvJN/i/9Y4g4fbrC1Zw4zGf/i2f2M347he6rwuERTlqG3/4SxEFqOIqXEJ7X6P/Oit74yjzd7Y5QoepRcp0F5T1rkrMGlgjO+Oi8WeBrzE9+DcMiozRAk6a/iI6fgTljV0gdHru3+p4mv7L/WVobE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723550228; c=relaxed/simple; bh=+0xhLszTZHOpyPZa9g5+GBCEzNF9nk/8hHIjuKEcW8s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Agmhn9RQT1Nfm8VCi0T1FGVkwTrUx2dpEtLaF5fQ4Us8NhauYC9olyg/0kPTn6OIOhrukMT2DeaDdNMgsHkWAis94+8/OdNkkUpISaA2q9PgeKjK62rR9MUXJ5KPgQId29lZU45odrnvoDTvcWp19GF1eZ/O7qo6GUPdrufkYY0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-52efbb55d24so9503276e87.1 for ; Tue, 13 Aug 2024 04:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1723550225; x=1724155025; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=q3jU8yx4QCzip/NfgFbHH1fd/vJeY0eid0+v5LokwZo=; b=Y9gKZTQ8CMiIJRJeqED40Y36EC7dstI106zmMHw/1L1wuIMmYqaVDYz0PoVkdXkjSD 6itLPyAtRiJWq1ic0UBIlHzMA0PumbkzjBpg7QCjVjD8b6078q/jRJ98lxti1hot2RDI 0wdQ0Osx26+KhCAOjCv6pfc36ntaspf3+vogmoKDGD0qXIb6U+AIkPOViKkpQipP4nbe DDLOYXUAVxypX0g0mosW9xnxK8QAYO5sT2th6SZ0PTIIyqRwJmJsomfcRP7pvhOc0IZx E1BusEfZkCNUzS56WN4WJ5HCXxxhioefu7LNwpXz6sI9PzbrQ/xvgN/83UbgUO9SsflC 8i2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723550225; x=1724155025; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q3jU8yx4QCzip/NfgFbHH1fd/vJeY0eid0+v5LokwZo=; b=AT5XjhHGCEoy4Kkzpi1PvNWgbx+rIbV9enGU95ZHGOtGr9Ty7JlUInM3eXGh38Tzg5 ztpt1iWJFrTNVWOecJwUY+oBHMzkLNqexoAGtY03Gk+LkVs76XCizneyK0/L8NbO500R nK0IxDdyb7gBiE2O3GJndwrhU6pXSr/B+ml7Bf4mt1Yc0Ki+bxgJLTSwUYeSrNB83pxD sEviylZnGuWtf1dHaGTFBdyIEECOhcIk7ZdITC5PwS7P5vtYwT5GppF8IbRFPDAcGdvJ YZXykGszCQr2/72vr81FN//MJhNnXB/9sBUJZulJX7WNxmJmP5HPUKUTyYU2mHWCfMpt UHjQ== X-Gm-Message-State: AOJu0YyCs/hPkcl9T78rYwLETkE+gVpfIJ3a9JXo0Epa3V9cpKmMngKW tr5N2nckio+FcN+XCWn+1ICNgtblBej4Y5VjicCgEAF+AmFOHxzMZKDzw+ufk9GnI8JqYD/7XjO H X-Google-Smtp-Source: AGHT+IFQ8LBMC1aS3batl2Xxv/czuCFSxthTFmyX6zgvA5z8l12pSQQqn8OWLZDUrPyjK8GoOhnpDw== X-Received: by 2002:a05:6512:308d:b0:52f:d17e:46b with SMTP id 2adb3069b0e04-53213692de9mr2683944e87.54.1723550223910; Tue, 13 Aug 2024 04:57:03 -0700 (PDT) Received: from helsinki-03.engr ([2a01:4f9:6b:2a47::2]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-53200ec3b19sm966239e87.92.2024.08.13.04.57.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 04:57:03 -0700 (PDT) From: Manolis Tsamis To: gcc-patches@gcc.gnu.org Cc: Philipp Tomsich , =?utf-8?q?Christoph_M=C3=BCl?= =?utf-8?q?lner?= , Andrew Pinski , Sam James , Manolis Tsamis Subject: [PATCH] ifcvt: Fix force_operand ICE due to noce_convert_multiple_sets [PR116353] Date: Tue, 13 Aug 2024 13:57:01 +0200 Message-Id: <20240813115701.3169159-1-manolis.tsamis@vrull.eu> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 Now that more operations are allowed for noce_convert_multiple_sets, we need to check noce_can_force_operand on the sequence before calling try_emit_cmove_seq. Otherwise an inappropriate argument may be given to copy_to_mode_reg and result in an ICE. Fix-up for the recent ifcvt commit 72c9b5f438f22cca493b4e2a8a2a31ff61bf1477 PR tree-optimization/116353 gcc/ChangeLog: * ifcvt.cc (bb_ok_for_noce_convert_multiple_sets): Check noce_can_force_operand. gcc/testsuite/ChangeLog: * gcc.target/i386/pr116353.c: New test. Tested-by: Christoph Müllner Signed-off-by: Manolis Tsamis --- gcc/ifcvt.cc | 6 ++- gcc/testsuite/gcc.target/i386/pr116353.c | 55 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr116353.c diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 3e25f30b67e..da59c907891 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -3938,8 +3938,10 @@ bb_ok_for_noce_convert_multiple_sets (basic_block test_bb, unsigned *cost) rtx src = SET_SRC (set); /* Do not handle anything involving memory loads/stores since it might - violate data-race-freedom guarantees. */ - if (!REG_P (dest) || contains_mem_rtx_p (src)) + violate data-race-freedom guarantees. Make sure we can force SRC + to a register as that may be needed in try_emit_cmove_seq. */ + if (!REG_P (dest) || contains_mem_rtx_p (src) + || !noce_can_force_operand (src)) return false; /* Destination and source must be appropriate. */ diff --git a/gcc/testsuite/gcc.target/i386/pr116353.c b/gcc/testsuite/gcc.target/i386/pr116353.c new file mode 100644 index 00000000000..8e254653d5d --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr116353.c @@ -0,0 +1,55 @@ +/* PR tree-optimization/116353 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +enum desmode { C }; +struct { + unsigned char des_ivec[]; +} _des_crypt_desp; +int des_SPtrans_6_0, des_SPtrans_4_0, des_encrypt_encrypt, des_encrypt_i; +long des_encrypt_s_0, _des_crypt_tin1, _des_crypt_tout0, _des_crypt_tout1, + _des_crypt_tin0; +enum desmode _des_crypt_desp_0; +unsigned long _des_crypt_tbuf[2]; +char _des_crypt_out; +void des_encrypt(unsigned long *buf) { + long l, r, t; + l = buf[0]; + r = buf[1]; + t = r; + r ^= l ^= t < 6; + if (des_encrypt_encrypt) + for (;; des_encrypt_i += 4) + des_encrypt_s_0 ^= des_SPtrans_4_0 | des_SPtrans_6_0; + buf[1] = r; +} +void _des_crypt() { + long xor0, xor1; + unsigned char *in; + int cbc_mode = _des_crypt_desp_0; + in = _des_crypt_desp.des_ivec; + xor0 = xor1 = 0; + for (;;) { + _des_crypt_tin0 = *in++; + _des_crypt_tin0 |= *in++ << 8; + _des_crypt_tin0 |= *in++ << 16; + _des_crypt_tin0 |= (long)*in << 24; + _des_crypt_tin1 = *in++; + _des_crypt_tin1 |= *in++ << 8; + _des_crypt_tin1 |= *in++ << 16; + _des_crypt_tin1 |= (long)*in << 24; + _des_crypt_tbuf[0] = _des_crypt_tin0; + _des_crypt_tbuf[1] = _des_crypt_tin1; + des_encrypt(_des_crypt_tbuf); + if (cbc_mode) { + _des_crypt_tout0 = xor0; + _des_crypt_tout1 = _des_crypt_tbuf[1] ^ xor1; + xor0 = _des_crypt_tin0; + xor1 = _des_crypt_tin1; + } else { + _des_crypt_tout0 = _des_crypt_tbuf[0]; + _des_crypt_tout1 = _des_crypt_tbuf[1]; + } + _des_crypt_out = _des_crypt_tout0 * _des_crypt_tout1; + } +}