From patchwork Thu Apr 27 11:17:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 88202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp191112vqo; Thu, 27 Apr 2023 04:18:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ42iMJQO4R3ad96Wx6lK+bLI3jxj+do6lUWPWzM/9Oa5hGUcr6fdGB2e2E7fXX/U0ppwF93 X-Received: by 2002:aa7:c0d8:0:b0:508:47af:c191 with SMTP id j24-20020aa7c0d8000000b0050847afc191mr1094816edp.30.1682594312901; Thu, 27 Apr 2023 04:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682594312; cv=none; d=google.com; s=arc-20160816; b=RXFhw9VbW29HQAFckqJdpTELyxppPrC3lxnyKgKXyUc6lj3FZCUSgF22tAJhFYvoMQ E9fzXhJ0W9kCPfw4Ju4mztGI0XJ6RiFqAZ6bb5TG8/OZmEaS3Ww4NCRH4SLubvaatf9p wf9VWqtFXHT2cQ9eX8sKn+CXJmZu6dvnkKpi/ypKbPKqlGhif4NlKizvlVCUdMcc1EXv hF1Xs3JBCfIiq5b0K7jWqbe8KtLproSZyf2x6i8ZE4vBggR84a8GRv8BjCv4/5QNYxnc Q4j/3ut9GoMGq87xeiBnowUgWrf8toSluZvj203t5vwfv9yKLhMFTb/ujc3g10LsHwke bYpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=K5qIf8BxrEcSgvA0N0LSMeB27oCqURjOAYfDqpy6nOg=; b=wmaZVlMuCCmzigV5CAyDVe52wKY7xrxSC6A6F8FE/wlbNjgQUCORmoFAHYEaPdRkhA LoxOAN7yjnv+hZ184zEvNIDKGIMhlSkVePv5Iz9uiLlbFu1zFP52uU50MrfeUpiSO5nI 554/WXmAk2Y4aqkzuv68t/jyhgNAlSk5tjW7ofpWTXuHea80BPGxaT1cwB6ma4A1B2EY zR1eO/aau8PonSrFBbrtTbhBXGRVY9nyP1/XPp4J/Hnby1op1N7cthBBxwF04ztqPYLD TggXfaW1pZFnj+vcbKYMmEWnz5l7wF1t1XZ+fczGa9qaF5m436x9DWQUcwynk3Rk3/KF l03g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Eg3MW0jp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z11-20020aa7cf8b000000b0050a09e40a3csi2425471edx.44.2023.04.27.04.18.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 04:18:32 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Eg3MW0jp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C411F3858425 for ; Thu, 27 Apr 2023 11:18:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C411F3858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682594307; bh=K5qIf8BxrEcSgvA0N0LSMeB27oCqURjOAYfDqpy6nOg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Eg3MW0jpyrDLeY8+WOylqiLAyVF3slVX1qk43KS+Ra4yjlJLm5RI1orpWdPU+fwEB PEa32BEueVGt11pvSmQP8yeH0z0NpyvV3ZKDipd7b6kUU05iY1vVi5x48zEfEoNSmt wUUAkq8tEZq05sCYcGKkL44cWO7pgVqnMjYBoM1I= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id C0A503858D37 for ; Thu, 27 Apr 2023 11:17:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C0A503858D37 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id E05771FDEE for ; Thu, 27 Apr 2023 11:17:42 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id D88752C141 for ; Thu, 27 Apr 2023 11:17:42 +0000 (UTC) Date: Thu, 27 Apr 2023 11:17:42 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Properly gimplify handled component chains on registers User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230427111827.C411F3858425@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764328014499188133?= X-GMAIL-MSGID: =?utf-8?q?1764328014499188133?= When for example complex lowering wants to extract the imaginary part of a complex variable for lowering a complex move we can end up with it generating __imag > which is valid GENERIC. It then feeds that to the gimplifier via force_gimple_operand but that fails to split up this chain of handled components, generating invalid GIMPLE catched by verification when PR109644 is fixed. The following rectifies this by noting in gimplify_compound_lval when the base object which we gimplify first ends up being a register. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * gimplify.cc (gimplify_compound_lval): When the base gimplified to a register make sure to split up chains of operations. --- gcc/gimplify.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index b0bdd1b46cd..9755f79fb2d 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3281,15 +3281,21 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, if (need_non_reg && (fallback & fb_rvalue)) prepare_gimple_addressable (p, pre_p); + /* Step 3: gimplify size expressions and the indices and operands of - ARRAY_REF. During this loop we also remove any useless conversions. */ + ARRAY_REF. During this loop we also remove any useless conversions. + If we operate on a register also make sure to properly gimplify + to individual operations. */ + bool reg_operations = is_gimple_reg (*p); for (; expr_stack.length () > 0; ) { tree t = expr_stack.pop (); if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF) { + gcc_assert (!reg_operations); + /* Gimplify the low bound and element type size. */ tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, is_gimple_reg, fb_rvalue); @@ -3306,10 +3312,18 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } else if (TREE_CODE (t) == COMPONENT_REF) { + gcc_assert (!reg_operations); + tret = gimplify_expr (&TREE_OPERAND (t, 2), pre_p, post_p, is_gimple_reg, fb_rvalue); ret = MIN (ret, tret); } + else if (reg_operations) + { + tret = gimplify_expr (&TREE_OPERAND (t, 0), pre_p, post_p, + is_gimple_val, fb_rvalue); + ret = MIN (ret, tret); + } STRIP_USELESS_TYPE_CONVERSION (TREE_OPERAND (t, 0));