From patchwork Wed May 6 07:36:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1284153 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: 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=M3DpfKyS; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49H7hm5B5vz9sRf for ; Wed, 6 May 2020 17:37:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB78F3894E7A; Wed, 6 May 2020 07:37:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB78F3894E7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1588750627; bh=tCGRd8WJHABflzEIUr8gEd1crGENlACnWk/MCJXuyAo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=M3DpfKySGtav7S1/spN6x3TXfDyQ4L8y4LqQBVNMAkSOIPvh+6BQKj48jDCImi7Ly bNOcVUBnuJocc6z7pfJdwiV7YBNdkzKfQ1ChXh9E0Gcb0Ii0oYPzgtjgsLvAz59k1I DguKNHg7BvtvIpZng4O6u7wb4/izv6/XhNMRX5jM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id E56283894E60 for ; Wed, 6 May 2020 07:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E56283894E60 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-2-GoIw9QFyPCeC9poRSGY8Fg-1; Wed, 06 May 2020 03:37:02 -0400 X-MC-Unique: GoIw9QFyPCeC9poRSGY8Fg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 291B3461; Wed, 6 May 2020 07:37:01 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-83.ams2.redhat.com [10.36.112.83]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B1E1760BF4; Wed, 6 May 2020 07:37:00 +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 0467avfD018435; Wed, 6 May 2020 09:36:57 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 0467at2r018434; Wed, 6 May 2020 09:36:55 +0200 Date: Wed, 6 May 2020 09:36:55 +0200 To: Segher Boessenkool Subject: [committed] combine: Don't replace SET_SRC with REG_EQUAL note content if SET_SRC has side-effects [PR94873] Message-ID: <20200506073655.GV8462@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-11.3 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_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! There were some discussions about whether REG_EQUAL notes are valid on insns with a single set which contains auto-inc-dec side-effects in the SET_SRC and the majority thinks that it should be valid. So, this patch fixes the combiner to punt in that case, because otherwise the auto-inc-dec side-effects from the SET_SRC are lost. Bootstrapped/regtested on {x86_64,i686,aarch64,powerpc64{,le}}-linux, preapproved in the PR by Segher, committed to trunk so far. 2020-05-06 Jakub Jelinek PR rtl-optimization/94873 * combine.c (combine_instructions): Don't optimize using REG_EQUAL note if SET_SRC (set) has side-effects. * gcc.dg/pr94873.c: New test. Jakub --- gcc/combine.c.jj 2020-04-24 14:40:21.087840193 +0200 +++ gcc/combine.c 2020-05-05 12:15:36.793466471 +0200 @@ -1485,6 +1485,7 @@ combine_instructions (rtx_insn *f, unsig if ((set = single_set (temp)) != 0 && (note = find_reg_equal_equiv_note (temp)) != 0 && (note = XEXP (note, 0), GET_CODE (note)) != EXPR_LIST + && ! side_effects_p (SET_SRC (set)) /* Avoid using a register that may already been marked dead by an earlier instruction. */ && ! unmentioned_reg_p (note, SET_SRC (set)) --- gcc/testsuite/gcc.dg/pr94873.c.jj 2020-05-05 12:18:35.056778567 +0200 +++ gcc/testsuite/gcc.dg/pr94873.c 2020-05-05 12:14:27.437512245 +0200 @@ -0,0 +1,27 @@ +/* PR rtl-optimization/94873 */ +/* { dg-do run { target int128 } } */ +/* { dg-options "-O -fno-merge-constants -fno-split-wide-types -fno-tree-fre" } */ + +__attribute__((noipa)) void +foo (const char *p, int q) +{ + if (p[0] != '%' || p[1] != '0' || p[2] != '2' || p[3] != 'x' || p[4] != '\0') + __builtin_abort (); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + if ((unsigned char) q != 0x95) + __builtin_abort (); +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + if ((unsigned char) q != 0) + __builtin_abort (); +#endif +} + +int +main () +{ + union U { __int128 a; char b[sizeof (__int128)]; }; + char x = ((union U){ .a = 0xF4409395252B9560ULL}).b[1]; + for (unsigned i = 0; i < sizeof (x); i++) + foo ("%02x", i[(volatile unsigned char *) &x]); + return 0; +}