From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 399E3398743E; Wed, 16 Sep 2020 19:21:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 399E3398743E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600284110; bh=9phgWEaOWsiV74U7dVK7FRUdi77UXhNpots+WG9YsX8=; h=From:To:Subject:Date:From; b=Uc2FzQaR4Edwpod6iW7s0OZARtq6/6zCSjc+/74Em02pJiwiVPE5c26UI94sNEU4m izz60loymCpRuy4xD+ejYBvbQhziSYll+2At00cwygmYXUusuCm/ST06NPkpSrGo9p tHyh8mLAEEppLx363UpSrTGVfzEFvUZ+Nnt5onSs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-8895] combine: Don't replace SET_SRC with REG_EQUAL note content if SET_SRC has side-effects [PR94873] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: b66139a3ba159473432edabb983c62219a28590d X-Git-Newrev: 0f717ba5975ab42e1176db4cd2384f1862872519 Message-Id: <20200916192150.399E3398743E@sourceware.org> Date: Wed, 16 Sep 2020 19:21:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Sep 2020 19:21:50 -0000 https://gcc.gnu.org/g:0f717ba5975ab42e1176db4cd2384f1862872519 commit r9-8895-g0f717ba5975ab42e1176db4cd2384f1862872519 Author: Jakub Jelinek Date: Wed May 6 09:31:19 2020 +0200 combine: Don't replace SET_SRC with REG_EQUAL note content if SET_SRC has side-effects [PR94873] 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. 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. (cherry picked from commit 8982e39b46b1e4a4b09022ddebd758b77ab73bac) Diff: --- gcc/combine.c | 1 + gcc/testsuite/gcc.dg/pr94873.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gcc/combine.c b/gcc/combine.c index 48a60eb0206..ab8463bf27b 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -1488,6 +1488,7 @@ combine_instructions (rtx_insn *f, unsigned int nregs) 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)) diff --git a/gcc/testsuite/gcc.dg/pr94873.c b/gcc/testsuite/gcc.dg/pr94873.c new file mode 100644 index 00000000000..36152176fbf --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr94873.c @@ -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; +}