From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 972F33858D33; Fri, 2 Dec 2022 10:09:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 972F33858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669975786; bh=beoftRps9zqahuWl/hkvMivHiQYgCvqg0pJ5lhPuZVo=; h=From:To:Subject:Date:From; b=AkHLi21Xs9TIovLw3LjZCwKvyIcIjcBkhBU7S3hcEQrglQuzAGImKBhYdLMkNNAAQ VaNehGIuQgvLOLQQRBBDeCcMjeBUDSEwauGgUkVp/ssw3uwSmAO58GhQSbpJ1ua6pL BKAQgd/bua2Oxb9GKkBfjpQHvCmUOoD+aWpB0Mr0= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4462] i386: Save/restore recog_data in ix86_vector_duplicate_value [PR106577] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: f13305518558f20ef2d460a74eb29dad5fce1350 X-Git-Newrev: b3237a2c6847993f92218b65f96ece9831a8bfb0 Message-Id: <20221202100946.972F33858D33@sourceware.org> Date: Fri, 2 Dec 2022 10:09:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b3237a2c6847993f92218b65f96ece9831a8bfb0 commit r13-4462-gb3237a2c6847993f92218b65f96ece9831a8bfb0 Author: Jakub Jelinek Date: Fri Dec 2 11:08:45 2022 +0100 i386: Save/restore recog_data in ix86_vector_duplicate_value [PR106577] On Tue, Aug 16, 2022 at 09:14:06AM +0100, Richard Sandiford via Gcc-patches wrote: > IMO the correct low-effort fix is to save and restore recog_data > in ix86_vector_duplicate_value. It's a relatively big copy, > but the current code is pretty wasteful anyway (allocating at > least a new SET and INSN for every query). Compared to the > overhead of doing that, a copy to and from the stack shouldn't > be too bad. The following patch does that. It isn't the first spot in the compiler that does that, not even the first spot in the i386 backend. In i386-expand.cc beyond these 2 recog_memoized calls there is one in expand_vselect, but I think it is unlikely we'd run into these issues trying to expand new permutations from splitters. 2022-12-02 Jakub Jelinek PR target/106577 * config/i386/i386-expand.cc (ix86_vector_duplicate_value): Save/restore recog_data around recog_memoized calls. * gcc.target/i386/pr106577.c: New test. Diff: --- gcc/config/i386/i386-expand.cc | 5 +++++ gcc/testsuite/gcc.target/i386/pr106577.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index f20bf81f393..04aadda6b07 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -15187,6 +15187,10 @@ ix86_vector_duplicate_value (machine_mode mode, rtx target, rtx val) bool ok; rtx_insn *insn; rtx dup; + /* Save/restore recog_data in case this is called from splitters + or other routines where recog_data needs to stay valid across + force_reg. See PR106577. */ + recog_data_d recog_data_save = recog_data; /* First attempt to recognize VAL as-is. */ dup = gen_vec_duplicate (mode, val); @@ -15212,6 +15216,7 @@ ix86_vector_duplicate_value (machine_mode mode, rtx target, rtx val) ok = recog_memoized (insn) >= 0; gcc_assert (ok); } + recog_data = recog_data_save; return true; } diff --git a/gcc/testsuite/gcc.target/i386/pr106577.c b/gcc/testsuite/gcc.target/i386/pr106577.c new file mode 100644 index 00000000000..1182d4f12df --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr106577.c @@ -0,0 +1,10 @@ +/* PR target/106577 */ +/* { dg-do compile { target int128 } } */ +/* { dg-options "-O2 -mavx" } */ + +int i; +void +foo (void) +{ + i ^= !(((unsigned __int128)0xf0f0f0f0f0f0f0f0 << 64 | 0xf0f0f0f0f0f0f0f0) & i); +}