From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1005) id 53B32385AC09; Thu, 12 Oct 2023 21:54:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 53B32385AC09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1697147658; bh=eHt2p3zLkjwJMOebNG+fwR6i4WZmk00Uq4woQYz2Oqk=; h=From:To:Subject:Date:From; b=wdYFtj43WCfdT4z/xrJJ0RrotpHXVxNDcLmjcEu6DFvG8SgRjBZWOiwpGDzAcCsqN 590yjiktghXag+2KEG/ZvSg4pBlT6xLFZ3Crcv5sCflaNdIPFfkC9OGDOeI7F+t9co YzPlI/drDODXojerTeoBlKVPgUEqwqUWyMwFU3Gc= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Michael Meissner To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/meissner/heads/work139)] PowerPC: Do not depend on an undefined shift X-Act-Checkin: gcc X-Git-Author: Michael Meissner X-Git-Refname: refs/users/meissner/heads/work139 X-Git-Oldrev: 8f3b5e556cf7cc9b0dee82c4f9edd0a1f890f49a X-Git-Newrev: 5ba61cf9168a7f408a9af24d618a55ac44b3cb96 Message-Id: <20231012215418.53B32385AC09@sourceware.org> Date: Thu, 12 Oct 2023 21:54:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5ba61cf9168a7f408a9af24d618a55ac44b3cb96 commit 5ba61cf9168a7f408a9af24d618a55ac44b3cb96 Author: Michael Meissner Date: Thu Oct 12 00:49:35 2023 -0400 PowerPC: Do not depend on an undefined shift I was building a cross compiler to PowerPC on my x86_86 workstation with the latest version of GCC on October 11th. I could not build the compiler on the x86_64 system as it died in building libgcc. I looked into it, and I discovered the compiler was recursing until it ran out of stack space. If I build a native compiler with the same sources on a PowerPC system, it builds fine. I traced this down to a change made around October 10th: | commit 8f1a70a4fbcc6441c70da60d4ef6db1e5635e18a (HEAD) | Author: Jiufu Guo | Date: Tue Jan 10 20:52:33 2023 +0800 | | rs6000: build constant via li/lis;rldicl/rldicr | | If a constant is possible left/right cleaned on a rotated value from | a negative value of "li/lis". Then, using "li/lis ; rldicl/rldicr" | to build the constant. The code was doing a -1 << 64 which is undefined behavior because different machines produce different results. On the x86_64 system, (-1 << 64) produces -1 while on a PowerPC 64-bit system, (-1 << 64) produces 0. The x86_64 then recurses until the stack runs out of space. If I apply this patch, the compiler builds fine on both x86_64 as a PowerPC crosss compiler and on a native PowerPC system. 2023-10-12 Michael Meissner gcc/ PR target/111778 * config/rs6000/rs6000.cc (can_be_built_by_li_lis_and_rldicl): Protect code from shifts that are undefined. (can_be_built_by_li_lis_and_rldicr): Likewise. (can_be_built_by_li_and_rldic): Likewise. Diff: --- gcc/config/rs6000/rs6000.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 2d1d379e128..be6ae5c88bb 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -10371,6 +10371,7 @@ can_be_built_by_li_lis_and_rldicl (HOST_WIDE_INT c, int *shift, to ones and then recheck it. */ int lz = clz_hwi (c); <<<<<<< HEAD +<<<<<<< HEAD <<<<<<< HEAD /* If lz == 0, the left shift is undefined. */ @@ -10388,6 +10389,13 @@ can_be_built_by_li_lis_and_rldicl (HOST_WIDE_INT c, int *shift, ======= >>>>>>> ab63444d033 (Revert patches) +======= + + /* If lz == 0, the left shift is undefined. */ + if (!lz) + return false; + +>>>>>>> 49fb3f85c90 (PowerPC: Do not depend on an undefined shift) HOST_WIDE_INT unmask_c = c | (HOST_WIDE_INT_M1U << (HOST_BITS_PER_WIDE_INT - lz)); int n;