Bug 16052 - strength reduction produces wrong code
Summary: strength reduction produces wrong code
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 16066 21862 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-06-18 10:28 UTC by YAMAMOTO Takashi
Modified: 2005-06-01 13:18 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3 3.2.3 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2004-06-18 16:12:41


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description YAMAMOTO Takashi 2004-06-18 10:28:20 UTC
siro% /usr/local/gcc3/bin/gcc -v
Reading specs from /usr/local/gcc3/lib/gcc/i386-unknown-netbsdelf2.0F/3.4.0/specs
Configured with: ./configure --prefix=/usr/local/gcc3_4 : (reconfigured) ./configure --prefix=/usr/local/gcc3 --enable-languages=c
Thread model: posix
gcc version 3.4.0


"gcc -O2 -S a.c" produces wrong code.

note that the produced code uses "jle" insn for loop condition.
because what it attempts to check is "p < (original value of p)+N*M",
it should use an unsigned comparison.

== a.c (source code) ==================================================

#include <stdio.h>

typedef int a_t;

inline void
h1(const a_t *p)
{

	printf("%p\n", p);
}

#define	N 800
#define	M 4

void
h(const a_t *p)
{
	int j;

	for (j = 0; j < N; j++) {
		h1(p + j*M);
	}
}

#if 1
#ifdef _LP64
#define	PTRBIT	64
#else
#define	PTRBIT	32
#endif
int
main(int argc, char **argv)
{

	h((void *) ((1ULL << (PTRBIT - 1)) - sizeof(a_t) * N * M));
}
#endif

== a.s (produced code) ==================================================

	.file	"a.c"
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%p\n"
	.text
	.p2align 2,,3
.globl h1
	.type	h1, @function
h1:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$16, %esp
	pushl	8(%ebp)
	pushl	$.LC0
	call	printf
	leave
	ret
	.size	h1, .-h1
	.p2align 2,,3
.globl h
	.type	h, @function
h:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%esi
	pushl	%ebx
	movl	8(%ebp), %ebx
	leal	12784(%ebx), %esi
	.p2align 2,,3
.L7:
	subl	$8, %esp
	pushl	%ebx
	pushl	$.LC0
	addl	$16, %ebx
	call	printf
	addl	$16, %esp
	cmpl	%esi, %ebx
	jle	.L7
	leal	-8(%ebp), %esp
	popl	%ebx
	popl	%esi
	leave
	ret
	.size	h, .-h
	.p2align 2,,3
.globl main
	.type	main, @function
main:
	pushl	%ebp
	movl	%esp, %ebp
	subl	$8, %esp
	andl	$-16, %esp
	subl	$28, %esp
	pushl	$2147470848
	call	h
	leave
	ret
	.size	main, .-main
	.ident	"GCC: (GNU) 3.4.0"
Comment 1 Andrew Pinski 2004-06-18 16:12:40 UTC
Confirmed, -O2 -march=i386 is needed to reproduce it on i686-pc-linux-gnu (well any i?86 really)
Comment 2 Andrew Pinski 2004-06-18 20:26:38 UTC
*** Bug 16066 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2004-06-18 20:28:34 UTC
Hmm, I did not test 3.3.4 at all, so this might be just a regression I do not know, but the debian folks 
think it is.
Comment 4 Mark Mitchell 2004-08-29 19:02:46 UTC
Postponed until GCC 3.4.3.
Comment 5 Mark Mitchell 2004-11-01 00:45:14 UTC
Postponed until GCC 3.4.4.
Comment 6 Steven Bosscher 2004-12-04 13:43:31 UTC
Fails on all ix86
Comment 7 Eric Botcazou 2004-12-05 12:08:29 UTC
> Fails on all ix86

Yeah, this is the classical problem with biv elimination to pointer givs.  See
gcc.c-torture/execute/loop-2e.c, which is XFAILed on x86.  Not a regression.
Comment 8 Andrew Pinski 2005-05-02 00:54:51 UTC
Fixed for 4.0.0.
Comment 9 Andrew Pinski 2005-06-01 13:18:42 UTC
*** Bug 21862 has been marked as a duplicate of this bug. ***