From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C978D3858C2C; Mon, 25 Apr 2022 08:06:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C978D3858C2C From: "zsojka at seznam dot cz" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/105368] [10/11/12 Regression] ICE: SIGSEGV in powi_lookup_cost (tree-ssa-math-opts.cc:1441) with -Ofast and __builtin_powf() Date: Mon, 25 Apr 2022 08:06:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: zsojka at seznam dot cz X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2022 08:06:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105368 --- Comment #2 from Zdenek Sojka --- (gdb) disas Dump of assembler code for function powi_cost(long): 0x0000000001538160 <+0>: push %r14 0x0000000001538162 <+2>: mov $0x20,%ecx 0x0000000001538167 <+7>: push %r13 0x0000000001538169 <+9>: push %r12 0x000000000153816b <+11>: push %rbp 0x000000000153816c <+12>: push %rbx 0x000000000153816d <+13>: mov %rdi,%rbx 0x0000000001538170 <+16>: sub $0x100,%rsp 0x0000000001538177 <+23>: neg %rbx 0x000000000153817a <+26>: cmovs %rdi,%rbx 0x000000000153817e <+30>: mov %rsp,%r13 0x0000000001538181 <+33>: xor %eax,%eax 0x0000000001538183 <+35>: xor %r12d,%r12d 0x0000000001538186 <+38>: mov %r13,%rdi 0x0000000001538189 <+41>: rep stos %rax,%es:(%rdi) 0x000000000153818c <+44>: movb $0x1,0x1(%rsp) =3D> 0x0000000001538191 <+49>: cmp $0xff,%rbx 0x0000000001538198 <+56>: jg 0x15381b0 0x000000000153819a <+58>: jmp 0x1538207 1463=20=20=20=20 1464 /* Ignore the reciprocal when calculating the cost. */ 1465 val =3D (n < 0) ? -n : n; 0x000000000153816d <+13>: mov %rdi,%rbx 1454 powi_cost (HOST_WIDE_INT n) 0x0000000001538170 <+16>: sub $0x100,%rsp 1455 { 1456 bool cache[POWI_TABLE_SIZE]; 1457 unsigned HOST_WIDE_INT digit; 1458 unsigned HOST_WIDE_INT val; 1459 int result; 1460=20=20=20=20 1461 if (n =3D=3D 0) 1462 return 0; --Type for more, q to quit, c to continue without paging-- 1463=20=20=20=20 1464 /* Ignore the reciprocal when calculating the cost. */ 1465 val =3D (n < 0) ? -n : n; 0x0000000001538177 <+23>: neg %rbx 0x000000000153817a <+26>: cmovs %rdi,%rbx ... /repo/gcc-trunk/gcc/tree-ssa-math-opts.cc: 1469 cache[1] =3D true; 0x000000000153818c <+44>: movb $0x1,0x1(%rsp) 1472=20=20=20=20 1473 while (val >=3D POWI_TABLE_SIZE) =3D> 0x0000000001538191 <+49>: cmp $0xff,%rbx 0x0000000001538198 <+56>: jg 0x15381b0 0x000000000153819a <+58>: jmp 0x1538207 (gdb) p/x n $19 =3D 0x8000000000000000 (gdb) p/x val $20 =3D 0x8000000000000000 (gdb) p/x $rbx $22 =3D 0x8000000000000000 The "while (val >=3D POWI_TABLE_SIZE)" check seems to be done in signed arithmetics ("jg" conditional jump), so the value is not reduced and cache[= i] accesses out of bounds. This happens with both boostrapped and non-bootstrapped compiler (using host gcc-11.3.0)=