From patchwork Tue Dec 5 07:27:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 173757 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3263486vqy; Mon, 4 Dec 2023 23:28:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IElQMoMBj9NJRB1Kx8ifedpcQ/3BUjmKvjtgNPks6NpL2ZpQ2O0rzL+i095LcTGmykEbFYa X-Received: by 2002:a05:620a:318b:b0:77e:fba3:58c2 with SMTP id bi11-20020a05620a318b00b0077efba358c2mr965684qkb.83.1701761304150; Mon, 04 Dec 2023 23:28:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701761304; cv=pass; d=google.com; s=arc-20160816; b=rJhCWjNM9VpryL6i+nfA8PjE+W9wlp+KZVyKx/iAr5jbxbKa0ngA5ZLxHj1jY7hOoF DSss7zR+V3seaOPR99S4ABIzSZxTuYNquzC1wcooWHfy62rXNb8nTJ+P/G46N8xe3PXH EJsF30lsPpEzS7A6J1vmfzA01DPd1XsI5aXt7Mku9nvosoeqYC/NDDyff8xBeXqkDeFO TuPyIX8RlcWL2hmVjmWkNT7yRgxg8vuWuC+uqL2TAiSY9m4HtgXP1SJ2k9dt23cjHpmp 7HnXLjUpL/PR2wYjMRIoA542vP8lgGFmUOiow7O/BpojlErf18RxzjDWdSmUC4no75Cr 9I4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=WGjHrVe6/Mz/LlJgIDDUMDaeotENdhJk0NywtCItpIc=; fh=h2iPLTLlSKmpj4PWOaJAO8af6hiH/htLInOT1vU8M+E=; b=NcRknwYCicBEyCHEz1nrOH6QmGIVVpcqmLRs1aYn+PJ9nTjLMobt29M1sgiKXBEI0J sWYnj8CGXzmNQKOdqosaJUikiUX4CbP3wq5fWLu8SLu1Akfymtwz9h+ZAnBnOXQHHdJf 5+E9OpeYqQUMFy0sLA8CuIc9gbJx1mUm5Kiw0W2TqWbTuRM3+1HIUPRVnL3cbXd5qf29 IrONf7xZ2WLAz1LwpQFJaEenhRcYzeTeMuZ5QewsxFSZdf+X+WBA1cfeUkoQx+ADunC2 oLyl74PCMYwMN9XpS6zzemcbsAOMI3dE0SXup7Jsv6qm3jP/9oaLpJuEEvvdKYSg+wwU InPg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="UcaJxR/5"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v3-20020a05620a0f0300b0077d7b36c96fsi12154633qkl.135.2023.12.04.23.28.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="UcaJxR/5"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD6F63857348 for ; Tue, 5 Dec 2023 07:28:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D94833858D1E for ; Tue, 5 Dec 2023 07:27:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D94833858D1E 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 D94833858D1E 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=1701761281; cv=none; b=gjd05RbjbXy1sLylIjQIwNGhqf45+wHTsinyvBObpEzYnkNm4R7A8nLpQm6dgMA1DERjBBF/v8ScC7z5Qle4TaOB8Axk+W1r9Soq9geuzGxJVsg1f7YpwB5DEp5TCJXvrDTlrOgM3GPCNlfkJMs+TGDYFOo1diSK5Dmsk1Z2Q7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701761281; c=relaxed/simple; bh=H4hu/ulqy+KbOeVoibg3eW7S0UgxgrhWSZ8t1aIiyO0=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=ZTXi+09PpfedbgfpdesQPnyWxuXQ572vKTgRwLpuLt2sZnmf8Eld5+J3HNCLxKxiUjDmQHN5o7wbrQvvQSY7ThNjwKzB+khSoY1IoXXCuXV3okFsl299mKJ+noQ8MIpKaZZktXkjH38bBFbs2P7zcZub96EmojANv3RM244jlfo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701761279; 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=WGjHrVe6/Mz/LlJgIDDUMDaeotENdhJk0NywtCItpIc=; b=UcaJxR/5XAAOAUAQ568/YrdDUVVOwtA95pWrGMYZ+SW3Hi1jHfsPIq8ynbV8mzxJc8wmPH POwPkNRxz8sFar+6N52nepxOaz24Z9bOocikYzedxXbaB56265RpJ4YIjPP1kjwPE7wlZz FxqDoQfElmTnItHZDm2IAiwbN4E12ns= 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-524-4d1Zhgb_OVuMuJ7U_Vx3UQ-1; Tue, 05 Dec 2023 02:27:58 -0500 X-MC-Unique: 4d1Zhgb_OVuMuJ7U_Vx3UQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 AF3C8835145; Tue, 5 Dec 2023 07:27:57 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72A8FC15A0C; Tue, 5 Dec 2023 07:27:57 +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 3B57RtoI693955 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 08:27:55 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B57RsAA693954; Tue, 5 Dec 2023 08:27:54 +0100 Date: Tue, 5 Dec 2023 08:27:54 +0100 From: Jakub Jelinek To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Fix -fcf-protection -Os ICE due to movabsq peephole2 [PR112845] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784426061390744209 X-GMAIL-MSGID: 1784426061390744209 Hi! The following testcase ICEs in the movabsq $(i32 << shift), r64 peephole2 I've added a while back to use smaller code than movabsq if possible. If i32 is 0xfa1e0ff3 and shift is not divisible by 8, then it creates an invalid insn (as 0xfa1e0ff3 CONST_INT is not allowed as x86_64_immediate_operand nor x86_64_zext_immediate_operand), the peephole2 even triggers on it again and again (this time with shift 0) until it gives up. The following patch fixes that. As ix86_endbr_immediate_operand needs a CONST_INT and it is hopefully rare, I chose to use FAIL rather than handling it in the condition (where I'd probably need to call ctz_hwi again etc.). Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-04 Jakub Jelinek PR target/112845 * config/i386/i386.md (movabsq $(i32 << shift), r64 peephole2): FAIL if the new immediate is ix86_endbr_immediate_operand. Jakub --- gcc/config/i386/i386.md.jj 2023-12-01 08:10:42.287330513 +0100 +++ gcc/config/i386/i386.md 2023-12-04 16:22:23.497986229 +0100 @@ -2699,7 +2699,10 @@ (define_peephole2 (clobber (reg:CC FLAGS_REG))])] { int shift = ctz_hwi (UINTVAL (operands[1])); - operands[1] = gen_int_mode (UINTVAL (operands[1]) >> shift, DImode); + rtx op1 = gen_int_mode (UINTVAL (operands[1]) >> shift, DImode); + if (ix86_endbr_immediate_operand (op1, VOIDmode)) + FAIL; + operands[1] = op1; operands[2] = gen_int_mode (shift, QImode); }) --- gcc/testsuite/gcc.dg/pr112845.c.jj 2023-12-04 16:25:31.228350449 +0100 +++ gcc/testsuite/gcc.dg/pr112845.c 2023-12-04 16:25:26.740413464 +0100 @@ -0,0 +1,9 @@ +/* PR target/112845 */ +/* { dg-do compile { target cet } } */ +/* { dg-options "-Os -fcf-protection" } */ + +unsigned long long +foo (void) +{ + return 0xfa1e0ff3ULL << 3; +}