From patchwork Wed Jan 8 07:58:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1219426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516834-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="RLb9xPWI"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="JsW1wpIU"; dkim-atps=neutral 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 47t1q20DvGz9sR0 for ; Wed, 8 Jan 2020 18:59:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=hmA vnVuCdCwmTMO4jeAzcpQc2Z6SbbHnD5M8iTMrpm+73gJ4dPaft2CFiVx46Rq+HN4 4b+f0V7MV4Ct8EWTJiTT23jGNFlCQQRt146N9ZUwyqbYqcf+UkUZ0Mnp3j32y9ut 5+WTqvNE1dGHyKx4pjv9y+a1mxMwGY5bvStsIOuw= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type:content-transfer-encoding; s=default; bh=2EE40R5fA vS4X4kj7U4ucPc7ewI=; b=RLb9xPWITSgtkYfFKWQp/DkoIMlCQGpvAHLghvB7d oI5AQia+TzPHWurz2ptSDF70EhbBlgiLSe1j/3umX1m0YhdOOhzXXYPqBHHlFFHy NzBy6y+vtetAOEzTOW3x6Jx+c8h68nIA0BxCXXdwX0C8QCflfCqicK21CuIN2GFF mQ= Received: (qmail 47815 invoked by alias); 8 Jan 2020 07:59:00 -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 47786 invoked by uid 89); 8 Jan 2020 07:59:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Jan 2020 07:58:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578470337; 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: content-transfer-encoding:content-transfer-encoding; bh=jIuzkitaztQtJFnEYbcYWIyHjYAA2GJXgAOnozNXars=; b=JsW1wpIUBuYO1YoZQlYlMSH5j8/t2ZUHGgdXiEz5rc2O6bmppOaZ9UWHIEjvic4tra/JN5 9U8U8gy0zsLEcOCMRPAmopral5SeVosMPR9hvm7Kx5fY7A/Fivbi6fcvQfJfwAQfiAmqWq Cu7PjSSRCVQVPBeyMc5Umb0JPVHbCdA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-3zWhdj0jOF6fYd_Wq4SQyw-1; Wed, 08 Jan 2020 02:58:56 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C5A1800EBF; Wed, 8 Jan 2020 07:58:55 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-112.ams2.redhat.com [10.36.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0218D10013A7; Wed, 8 Jan 2020 07:58:54 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 0087wqab024153; Wed, 8 Jan 2020 08:58:53 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 0087wpnO024152; Wed, 8 Jan 2020 08:58:51 +0100 Date: Wed, 8 Jan 2020 08:58:51 +0100 From: Jakub Jelinek To: Uros Bizjak Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix x86 ICE when peepholing2 @stack_protect_set_1_ with *lea (PR target/93187) Message-ID: <20200108075851.GH10088@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! On the following testcase, the peephole2s merge @stack_protect_set_1_ with not the expected *mov{si,di}_internal, but *lea instead - which looks like a mov, but uses address_no_seg_operand predicate/Ts constraint. The peephole2s check that operand with several smaller predicates, as we do not want to match anything not matched by the constraints used in the *stack_protect_set_{2_,3} patterns, and I thought those predicates together are subset of general_operand, which is used as the predicate in those patterns, but apparently that is not the case. So this patch also verifies the operand is general_operand. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-01-07 Jakub Jelinek PR target/93187 * config/i386/i386.md (*stack_protect_set_2_ peephole2, *stack_protect_set_3 peephole2): Also check that the second insns source is general_operand. * g++.dg/opt/pr93187.C: New test. Jakub --- gcc/config/i386/i386.md.jj 2020-01-07 18:12:48.043555173 +0100 +++ gcc/config/i386/i386.md 2020-01-07 20:18:27.666952849 +0100 @@ -20084,6 +20084,7 @@ (define_peephole2 (set (match_operand:SI 3 "general_reg_operand") (match_operand:SI 4))] "REGNO (operands[2]) == REGNO (operands[3]) + && general_operand (operands[4], SImode) && (general_reg_operand (operands[4], SImode) || memory_operand (operands[4], SImode) || immediate_operand (operands[4], SImode)) @@ -20128,6 +20129,7 @@ (define_peephole2 (clobber (reg:CC FLAGS_REG))]) (set (match_dup 2) (match_operand:DI 3))] "TARGET_64BIT + && general_operand (operands[3], DImode) && (general_reg_operand (operands[3], DImode) || memory_operand (operands[3], DImode) || x86_64_zext_immediate_operand (operands[3], DImode) --- gcc/testsuite/g++.dg/opt/pr93187.C.jj 2020-01-07 20:20:29.467117172 +0100 +++ gcc/testsuite/g++.dg/opt/pr93187.C 2020-01-07 20:21:40.459047146 +0100 @@ -0,0 +1,77 @@ +// PR target/93187 +// { dg-do compile { target c++11 } } +// { dg-options "-O2" } +// { dg-additional-options "-fstack-protector-strong" { target fstack_protector } } +// { dg-additional-options "-fpie" { target pie } } + +struct A; +struct B; +struct C { int operator () (B, const B &); }; +struct D { typedef int *d; }; +struct E { C g; }; +struct F { F (D::d); friend bool operator==(F &, const int &); }; +template struct H { + typedef D *I; + E l; + I foo (); + T t; + F bar (I, const T &); + F baz (const T &); +}; +template +F +H::bar (I n, const T &o) +{ + while (n) + if (l.g (t, o)) + n = 0; + return 0; +} +template +F +H::baz (const T &n) +{ + D *r = foo (); + F p = bar (r, n); + return p == 0 ? 0 : p; +} +template struct J { + H h; + B &q; + void baz () { h.baz (q); } +}; +enum K { L }; +template struct M; +template struct G { + using N = J; + N *operator->(); +}; +template struct M : public G { + using N = J; + N *foo () { return n; } + N *n; + int o; +}; +template +inline typename G::N * +G::operator-> () +{ + N *n = static_cast> *>(this)->foo (); + return n; +} +struct B { bool qux (); }; +struct O { + struct P { M p; }; + static thread_local P o; + int baz () const; +}; +thread_local O::P O::o; +B be; +int +O::baz () const +{ + do + o.p->baz (); + while (be.qux ()); + __builtin_unreachable (); +}