[{"id":3628905,"web_url":"http://patchwork.ozlabs.org/comment/3628905/","msgid":"<fca40e51-a19b-4daa-9316-8f1873a3c7d2@gmail.com>","list_archive_url":null,"date":"2025-12-26T22:35:52","subject":"Re: [PATCH] simplify-rtx: Fix up (ne (ior (ne x 0) y) 0)\n simplification [PR123114]","submitter":{"id":81263,"url":"http://patchwork.ozlabs.org/api/people/81263/","name":"Jeffrey Law","email":"jeffreyalaw@gmail.com"},"content":"On 12/15/2025 1:50 AM, Jakub Jelinek wrote:\n> Hi!\n>\n> The following testcase ICEs on x86_64-linux since the PR52345\n> (ne (ior (ne x 0) y) 0) simplification was (slightly) fixed.\n> It wants to optimize\n>      (set (reg/i:DI 10 a0)\n>          (ne:DI (ior:DI (ne:DI (reg:DI 151 [ a ])\n>                      (const_int 0 [0]))\n>                  (reg:DI 152 [ b ]))\n>              (const_int 0 [0])))\n> but doesn't check important property of that, in particular\n> that the mode of the inner NE operand is the same as the\n> mode of the inner NE.\n> The following testcase has\n> (set (reg:CCZ 17 flags)\n>      (compare:CCZ (ior:QI (ne:QI (reg/v:SI 104 [ c ])\n>                  (const_int 0 [0]))\n>              (reg:QI 98 [ _5 ]))\n>          (const_int 0 [0])))\n> where cmp_mode is QImode, but the mode of the inner NE operand\n> is SImode instead, and it attempts to create\n>    (ne:CCZ (ior:QI (reg/v:SI 104 [ c ]) (reg:QI 98 [ _5 ])) (const_int 0))\n> which obviously crashes later on.\n>\n> The following patch fixes it by checking the mode of the inner NE operand\n> and also by using CONST0_RTX (cmp_mode) instead of CONST0_RTX (mode)\n> because that is the mode of the other operand, not mode which is the\n> mode of the outer comparison (though, guess for most modes it will still\n> be const0_rtx).\n>\n> I guess for mode mismatches we could arbitrarily choose some extension (zero\n> or sign) and extend the narrower mode to the wider mode, but I doubt that it\n> would ever match on any target.  But even then we'd need to limit it, we\n> wouldn't want to deal with another mode class (say floating point\n> comparisons), and dunno about vector modes etc.\n>\n> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?\n>\n> 2025-12-13  Jakub Jelinek  <jakub@redhat.com>\n>\n> \tPR rtl-optimization/123114\n> \t* simplify-rtx.cc (simplify_context::simplify_relational_operation):\n> \tVerify XEXP (XEXP (op0, 0), 0) mode and use CONST0_RTX (cmp_mode)\n> \tinstead of CONST0_RTX (mode).\n>\n> \t* gcc.dg/pr123114.c: New test.\n\nOK.  And, no I don't think it would ever match either, so handling \nmismatches seems like it's an effort with zero gain.\n\n\njeff","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 (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20230601 header.b=RqeGJbqd;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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 (2048-bit key,\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20230601 header.b=RqeGJbqd","sourceware.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","sourceware.org; spf=pass smtp.mailfrom=gmail.com","server2.sourceware.org;\n arc=none smtp.remote-ip=209.85.215.171"],"Received":["from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 4ddL7g0n8Pz1y3s\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 27 Dec 2025 09:36:30 +1100 (AEDT)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id A34134BA2E2E\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 26 Dec 2025 22:36:28 +0000 (GMT)","from mail-pg1-f171.google.com (mail-pg1-f171.google.com\n [209.85.215.171])\n by sourceware.org (Postfix) with ESMTPS id CF4F14BA2E29\n for <gcc-patches@gcc.gnu.org>; Fri, 26 Dec 2025 22:35:55 +0000 (GMT)","by mail-pg1-f171.google.com with SMTP id\n 41be03b00d2f7-b4755f37c3eso4945744a12.3\n for <gcc-patches@gcc.gnu.org>; Fri, 26 Dec 2025 14:35:55 -0800 (PST)","from [172.31.1.103] ([172.56.14.46])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2b05ffad66fsm55700104eec.4.2025.12.26.14.35.53\n (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n Fri, 26 Dec 2025 14:35:54 -0800 (PST)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org A34134BA2E2E","OpenDKIM Filter v2.11.0 sourceware.org CF4F14BA2E29"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org CF4F14BA2E29","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org CF4F14BA2E29","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1766788556; cv=none;\n b=ZGr1/oMsozoyRJV+psuws6Cnx92pB0lhYAYp3beM6h8AIWBxg6vXfuwJylsXrpOpouZ6+b0RiVDR1SizkOL3osO3X5dB++z3qDRa3w37sdWZpNjsYbKRHXsbm6V34ZWdImX64R17/Bag1d8NONCILTwMdp85J2ZF0MKpplSM98g=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1766788556; c=relaxed/simple;\n bh=iCq9BbaKsFiDYlpiWUE1KKzfgkFEdIw2FNTM6dKd/rs=;\n h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From;\n b=mUckaet6IJYr0HuK79IT2RBL9bxQ4TZfa+V8/ypxgcbyg1fLQ7jYHEabINzSsERwuzJnUYJEjpZMRMCKrQohFNThgdN9/6fM05Rdi4oVNYz1zZeNZGgSllWRKOEVTA8J16q/lV5pTNTlV43P6H5giC/50g+P2JSP3cU2kaqgH+4=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20230601; t=1766788555; x=1767393355; darn=gcc.gnu.org;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :from:to:cc:subject:date:message-id:reply-to;\n bh=TFQm6XhIbinitVZmG7Y/mUvufvLcOSyAOmjMFGBIkXU=;\n b=RqeGJbqdxPAzUkdXD2WmEvUIxOKr5VqR1Ngv7vYjAlPr9aeHexK4u884OhknRf0r4s\n FvmTMZc0DI6fY9DoXsw1F4d6LDPbAVxFPmJgBBR+po4pdAok0bGIhH+S+jpkv8QHvk9F\n OjQZvxx5HOYQTRKmMtcdEmPnA2Ub827PN7kjs3J94fjyG1cuKwL/1D4Hxl/eStLzj9fm\n 0lm3Fv1Eo1UMIrovkpa1QLgYU7GbtoPX7ALbYC3zPhacGTQAMJAHnW+N2IGWWfeuUV1y\n 2VfZ3ANzAAFydlRj6hXiIK2hPoJxjvuK33MItBf/ijI2SPpNjyLICXOJtYwkuLq4XO+l\n iYFg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20230601; t=1766788555; x=1767393355;\n h=content-transfer-encoding:in-reply-to:from:content-language\n :references:cc:to:subject:user-agent:mime-version:date:message-id\n :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id\n :reply-to;\n bh=TFQm6XhIbinitVZmG7Y/mUvufvLcOSyAOmjMFGBIkXU=;\n b=Dh0O9OCV7DZRo6oHCpJEepP2hFjO3sGBj+X78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"by 2002:a05:693c:60c9:b0:2ae:5092:935 with SMTP id\n 5a478bee46e88-2b05ec48f34mr21431216eec.35.1766788554510;\n Fri, 26 Dec 2025 14:35:54 -0800 (PST)","Message-ID":"<fca40e51-a19b-4daa-9316-8f1873a3c7d2@gmail.com>","Date":"Fri, 26 Dec 2025 15:35:52 -0700","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH] simplify-rtx: Fix up (ne (ior (ne x 0) y) 0)\n simplification [PR123114]","To":"Jakub Jelinek <jakub@redhat.com>","Cc":"gcc-patches@gcc.gnu.org","References":"<aT_L4MhTnd-gdxi9@tucnak>","Content-Language":"en-US","From":"Jeffrey Law <jeffreyalaw@gmail.com>","In-Reply-To":"<aT_L4MhTnd-gdxi9@tucnak>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","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>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]