{"id":2223761,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223761/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/aeCOPGYEvn2rBmoW@tucnak/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<aeCOPGYEvn2rBmoW@tucnak>","date":"2026-04-16T07:22:36","name":"tree-ssa-propagate: Call update_stmt before folding [PR124891]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"653bdfb1e0fca8514445874dc10a9168ccc6cb83","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/1.1/people/671/?format=json","name":"Jakub Jelinek","email":"jakub@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/aeCOPGYEvn2rBmoW@tucnak/mbox/","series":[{"id":500088,"url":"http://patchwork.ozlabs.org/api/1.1/series/500088/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500088","date":"2026-04-16T07:22:36","name":"tree-ssa-propagate: Call update_stmt before folding [PR124891]","version":1,"mbox":"http://patchwork.ozlabs.org/series/500088/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223761/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223761/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=elqRDQ2I;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=elqRDQ2I","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fx8ck16vMz1yG9\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 17:23:16 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id C23074BA543C\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 07:23:14 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 601124BA2E05\n for <gcc-patches@gcc.gnu.org>; Thu, 16 Apr 2026 07:22:45 +0000 (GMT)","from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-6aca80xlO8y-O1DOAavoCg-1; Thu,\n 16 Apr 2026 03:22:41 -0400","from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 65BEA18004A9; Thu, 16 Apr 2026 07:22:40 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.33.129])\n by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id E04E319560B6; Thu, 16 Apr 2026 07:22:39 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 63G7Mb2W887492\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Thu, 16 Apr 2026 09:22:37 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63G7MaRj887491;\n Thu, 16 Apr 2026 09:22:36 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org C23074BA543C","OpenDKIM Filter v2.11.0 sourceware.org 601124BA2E05"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 601124BA2E05","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 601124BA2E05","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776324165; cv=none;\n b=M0YnLR3emYkQHKSy4WjeCtc0wjyqhvFlAbPZF6CSiD4822F7RNfCm9q7VNMqhVcLBVwsacNfoJ/pOWPZlRghq2cjS3do5Oytjbgmv312GdSlFcAfJ99KMICWq2yWdAVrzCusoZNAa3k5Y0GSjzfAPlrYgv6qSRq3T5Did2+J/Qs=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776324165; c=relaxed/simple;\n bh=iaZ/t0S83bKQzE5BkJf6Blhc2czLqlQHm8/NOa4vMB0=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=Sb+tsHMs9WG77cnWBboMMNzJdU655DuZ3VPWonCmT5C2GiSn2AqRkHdryw2tDwW3R0diX/smLSX9oeE3GtXHgq/IHzsvZsEssmLhJpE8K9XuUl4r3wc8uLQj2bUzHczQcoRGpGIbWBBwA6RmCJatx3Vr6PUG+3rFohaGXnOTG80=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776324165;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type; bh=f226OyfL2eEzmpWtbCUeSWLwJtaBazm43kI1Z9XdDY0=;\n b=elqRDQ2IGuQRv/97OEObuD3QeqlEEhG+EJq5q34U5cbqrHOlw8TdjKqi72a8S1054VvUPj\n XTw8zdGLj/hQyd4P/gBFtjq7elckaLeqhpE4UoSkVCmXcErx8HiCxfgS2OKTCFZiD+U2Bb\n Nj/5fjyLOGdT0elEcyK96m7eJ6RusiI=","X-MC-Unique":"6aca80xlO8y-O1DOAavoCg-1","X-Mimecast-MFC-AGG-ID":"6aca80xlO8y-O1DOAavoCg_1776324160","Date":"Thu, 16 Apr 2026 09:22:36 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Richard Biener <rguenther@suse.de>","Cc":"gcc-patches@gcc.gnu.org","Subject":"[PATCH] tree-ssa-propagate: Call update_stmt before folding\n [PR124891]","Message-ID":"<aeCOPGYEvn2rBmoW@tucnak>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.12","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"APz0patPQqMY4UAJH_XTYA87_wr24s8xs-Jbm_RSVdY_1776324160","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi!\n\nThe following testcase ICEs, because we\n      did_replace |= substitute_and_fold_engine->replace_uses_in (stmt);\nand replace some SSA_NAME with INTEGER_CST and without update_stmt\ncall fold_stmt.  Now fold_stmt ends up asking ranger about something end\nICEs because it attempts to walk SSA_USE_OPs on that stmt and because\nwe haven't updated the stmt, walks even the INTEGER_CST among ssa uses\nand checking ICEs because it attempts to test SSA_NAME flags on the\nINTEGER_CST.\n\nThe following patch fixes it by calling update_stmt before folding in that\ncase, it is called again after folding just in case it is folded.\n\nBootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?\n\n2026-04-16  Jakub Jelinek  <jakub@redhat.com>\n\n\tPR tree-optimization/124891\n\t* tree-ssa-propagate.cc\n\t(substitute_and_fold_dom_walker::before_dom_children): Call update_stmt\n\tin the did_replace case before calling fold_stmt.\n\n\t* gcc.dg/torture/pr124891.c: New test.\n\n\n\tJakub","diff":"--- gcc/tree-ssa-propagate.cc.jj\t2026-03-27 10:17:21.499210556 +0100\n+++ gcc/tree-ssa-propagate.cc\t2026-04-15 17:03:42.791155358 +0200\n@@ -860,6 +860,7 @@ substitute_and_fold_dom_walker::before_d\n       /* If we made a replacement, fold the statement.  */\n       if (did_replace)\n \t{\n+\t  update_stmt (stmt);\n \t  fold_stmt (&i, follow_single_use_edges);\n \t  stmt = gsi_stmt (i);\n \t  gimple_set_modified (stmt, true);\n--- gcc/testsuite/gcc.dg/torture/pr124891.c.jj\t2026-04-15 17:05:24.273462229 +0200\n+++ gcc/testsuite/gcc.dg/torture/pr124891.c\t2026-04-15 17:05:14.427626500 +0200\n@@ -0,0 +1,10 @@\n+/* PR tree-optimization/124891 */\n+/* { dg-do compile } */\n+\n+void\n+foo (int x, int y, int z, int *buf)\n+{\n+  for (int i = 0; i < x; ++i)\n+    for (int j = z; j < x-z; ++z)\n+      buf[j + (y - z +i) * x] = buf[x];\n+}\n","prefixes":[]}