From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id B1C6B385802F; Fri, 10 Mar 2023 21:55:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1C6B385802F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678485316; bh=BYwLA8mo/FTdSNMv0AggAYEd9OcDu0JvMQArYX2PrJY=; h=From:To:Subject:Date:From; b=seO2D5pGPKThQBBrwdXj8PhX+pxiTqAxDjh4xamP2zKM5/TrL9vqRfR/Kjwxf6oZh ZyDUPLpSjXn+f8W92SrC/Ovw6Q51cAXicECzNd0vp48yMO59HYcgtE/qFaXKYuPqvS DmLf0N8vz0GS7TkJ57if40DEh6JgA5xd+NDISwAo= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9239] tree-optimization: [PR108684] ICE in verify_ssa due to simple_dce_from_worklist X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 1784d252cecb0c8f4025ee587af4c29cc0992923 X-Git-Newrev: 657e1e89d34b114ca47fe1f2c5366927c5850af7 Message-Id: <20230310215516.B1C6B385802F@sourceware.org> Date: Fri, 10 Mar 2023 21:55:16 +0000 (GMT) List-Id: https://gcc.gnu.org/g:657e1e89d34b114ca47fe1f2c5366927c5850af7 commit r12-9239-g657e1e89d34b114ca47fe1f2c5366927c5850af7 Author: Andrew Pinski Date: Tue Feb 7 23:09:40 2023 +0000 tree-optimization: [PR108684] ICE in verify_ssa due to simple_dce_from_worklist In simple_dce_from_worklist, we were removing an inline-asm which had a vdef. We should not be removing inline-asm which have a vdef as this code does not check to the store. This fixes that oversight. This was a latent bug exposed recently by both VRP and removal of stores to static starting to use simple_dce_from_worklist. Backported after bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/108684 gcc/ChangeLog: * tree-ssa-dce.cc (simple_dce_from_worklist): Check all ssa names and not just non-vdef ones before accepting the inline-asm. Call unlink_stmt_vdef on the statement before removing it. gcc/testsuite/ChangeLog: * gcc.c-torture/compile/dce-inline-asm-1.c: New test. * gcc.c-torture/compile/dce-inline-asm-2.c: New test. * gcc.dg/tree-ssa/pr108684-1.c: New test. co-authored-by: Andrew Macleod (cherry picked from commit 6a5cb782d1486b378d70857c8efae558da0eb2cc) Diff: --- gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c | 15 +++++++++++++++ gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c | 18 ++++++++++++++++++ gcc/tree-ssa-dce.cc | 5 +++-- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c new file mode 100644 index 00000000000..a9f02e44bd7 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-1.c @@ -0,0 +1,15 @@ +/* PR tree-optimization/108684 */ +/* This used to ICE as when we remove the store to + `t`, we also would remove the inline-asm which + had a VDEF on it but we didn't update the + VUSE that was later on. */ +static int t; + +int f (int *a) +{ + int t1; + asm (" " : "=X" (t1) : : "memory"); + t = t1; + return *a; +} + diff --git a/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c new file mode 100644 index 00000000000..a41b16e4bd0 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/dce-inline-asm-2.c @@ -0,0 +1,16 @@ +/* PR tree-optimization/108684 */ +/* This used to ICE as when we removed the + __builtin_unreachable in VRP, as we + would also remove the branch and the + inline-asm. The inline-asm had a VDEF on it, + which we didn't update further along and + not have the VDEF on the return statement + updated. */ + +int f (int a) +{ + asm (" " : "=X" (a) : : "memory"); + if (a) + return 0; + __builtin_unreachable(); +} diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c new file mode 100644 index 00000000000..3ba206f765e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr108684-1.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + + +static int t; + +int f (int *a) +{ + int t1, t2 = 0; + asm ("shouldshowupstill %1" : "=r" (t1), "=m"(t2) : : ); + t = t1; + return t2; +} + +/* Check to make sure DCE does not remove the inline-asm as it writes to t2. */ +/* We used to DCE this inline-asm when removing the store to t. */ +/* { dg-final { scan-assembler "shouldshowupstill" } } */ +/* { dg-final { scan-tree-dump-times "shouldshowupstill" 1 "optimized" } } */ diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc index 4b7b664867d..4fa830dffd3 100644 --- a/gcc/tree-ssa-dce.cc +++ b/gcc/tree-ssa-dce.cc @@ -2062,9 +2062,9 @@ simple_dce_from_worklist (bitmap worklist) /* The defining statement needs to be defining only this name. ASM is the only statement that can define more than one - (non-virtual) name. */ + name. */ if (is_a(t) - && !single_ssa_def_operand (t, SSA_OP_DEF)) + && !single_ssa_def_operand (t, SSA_OP_ALL_DEFS)) continue; /* Don't remove statements that are needed for non-call @@ -2094,6 +2094,7 @@ simple_dce_from_worklist (bitmap worklist) remove_phi_node (&gsi, true); else { + unlink_stmt_vdef (t); gsi_remove (&gsi, true); release_defs (t); }