This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c/3464: simple comparision gives wrong result on -maix64 with any optimization



>Number:         3464
>Category:       c
>Synopsis:       simple comparision gives wrong result on -maix64 with any optimization
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 28 10:56:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Peter Boncz
>Release:        gcc 2.95.2
>Organization:
>Environment:
AIX 4.3.3 on powerpc64
>Description:
(long long ANY < long long X=almost min_int) and
   (long long ANY > long long ANY) 

where ANY seems to be almost any signed 64bits integer, and X is some crucial signed long. Bug occurs when X < (32768 - (1<<30))

bug: the expression evaluates to 0 where it should to 1 when compiling with any optimiziation.

without optimization, it works.

I do not understand the generated assembly. it does strange things with 32768 and ORI, where I would expect simple comparions and AND.
>How-To-Repeat:
main(int argc, char** argv) {
	int i = atoi(argv[1]);
	long long l = (long long) i;
	printf("%d\n", (l > -2147450880) && (l < 42));
	printf("%d\n", (l > -2147450881) && (l < 42));
}


/*
Reading specs from /usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.2.0/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.2.0/2.95.2/cpp -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_LONG_LONG -D_IBMR2 -D_POWER -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_LONG_LONG -Asystem(unix) -Asystem(aix) -D__CHAR_UNSIGNED__ -D__OPTIMIZE__ -D__64BIT__ -D_ARCH_PPC b.c b.i
GNU CPP version 2.95.2 19991024 (release)
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.2.0/2.95.2/../../../../powerpc-ibm-aix4.3.2.0/include
 /usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.2.0/2.95.2/include
 /usr/include
End of search list.
The following default directories have been omitted from the search path:
 /usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.2.0/2.95.2/../../../../include/g++-3
End of omitted list.
 /usr/local/lib/gcc-lib/powerpc-ibm-aix4.3.2.0/2.95.2/cc1 b.i -quiet -dumpbase b.c -maix64 -O -version -fcse -o b.s
cc1: Invalid option `-fcse'
GNU C version 2.95.2 19991024 (release) (powerpc-ibm-aix4.3.2.0) compiled by GNU C version 2.95.2 19991024 (release).
*/

/*
	.file	"b.c"
	.machine	"ppc64"
.toc
.csect .text[PR],3
gcc2_compiled.:
__gnu_compiled_c:
.csect _b.rw_c[RO],3
	.align 3
LC..0:
	.byte "%d"
	.byte 10, 0
.toc
LC..1:
	.tc LC..0[TC],LC..0
.csect .text[PR],3
	.align 2
	.globl main
	.globl .main
.csect main[DS],3
main:
	.llong .main, TOC[tc0], 0
.csect .text[PR]
.main:
	mflr 0
	std 29,-24(1)
	std 30,-16(1)
	std 31,-8(1)
	std 0,16(1)
	stdu 1,-144(1)
	mr 29,4
	bl .__main
	cror 31,31,31
	ld 3,8(29)
	bl .atoi
	cror 31,31,31
	mr 29,3
	addis 9,29,0x7fff
	addi 9,9,32767
	lis 0,0x7fff
	ori 0,0,32808
	cmpld 7,9,0
	cror 31,30,28
	mfcr 4
	rlwinm 4,4,0,1
	ld 3,LC..1(2)
	extsw 4,4
	bl .printf
	cror 31,31,31
	addis 29,29,0x8000
	addi 29,29,-32768
	lis 0,0x7fff
	ori 0,0,32809
	cmpld 7,29,0
	cror 31,30,28
	mfcr 4
	rlwinm 4,4,0,1
	ld 3,LC..1(2)
	extsw 4,4
	bl .printf
	cror 31,31,31
	la 1,144(1)
	ld 0,16(1)
	mtlr 0
	ld 29,-24(1)
	ld 30,-16(1)
	ld 31,-8(1)
	blr
LT..main:
	.long 0
	.byte 0,0,32,65,128,3,2,0
	.long 0
	.long LT..main-.main
	.short 4
	.byte "main"
_section_.text:
.csect .data[RW],3
	.long _section_.text
*/
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]