Gradual underflow and a compiler bug fix for gcc-2.95.2 on Intel x86
hardware
Nelson H. F. Beebe
beebeamath.utah.edu
Fri Dec 10 09:43:19 PST 1999
Vaughan Pratt <prattacs.stanford.edu>'s gradual underflow benchmark
program reported to this list on Sun, 05 Dec 1999 15:40:47 -0800
turned up a bug in the GNU gcc 2.95.2 compiler (and likely, earlier
releases after 2.91.x): the loop
for (x = 1, y = 2, i = 0; x; x /= 2, y /= 2, i++);
printf("%d %g\n", i, y); /* Sanity check: expect 1075 4.94066e-324 */
did not produce the expected result on Intel x86 systems when compiled
with any optimization level greater than 0 (i.e., -O1, -O2, ...), when
-ffloat-store was specified (to reduce 80-bit register precision to
64-bit memory precision).
Several exchanges and `arguments' with the gcc compiler developers led
to the source of the error being uncovered, and this morning, I
received the attached patches. Presumably gcc-2.95.3 will contain
them.
Thanks to Stephen L Moshier <moshieramediaone.net> for the great
debugging job!
>> ...
>>
>> > int main(void)
>> > {
>> > double x, y;
>> > int i;
>> >
>> > for (x = 1, y = 2, i = 0; x; x /= 2, y /= 2, i++);
>> > if (i != 1075)
>> > abort ();
>> > return(0);
>> > }
>>
>> Well, this was a hoisting problem after all.
>> The patch cures the i386 fpu register symptom, above, by preventing
>> floating-point memory references from being moved outside of loops.
>> The first version is against current CVS archive; the second version
>> below is for gcc-2.95.2.
>>
>> I think this makes float-store work a little more like it is supposed
>> to work, and is otherwise harmless.
>> ...
* loop.c (load_mems): Don't hoist floating point mem if -ffloat-store.
*** loop.c 1999/12/03 01:01:33 1.1
--- loop.c 1999/12/10 02:03:25
*************** load_mems (scan_start, end, loop_top, st
*** 9769,9776 ****
rtx mem = loop_mems[i].mem;
rtx mem_list_entry;
! if (MEM_VOLATILE_P (mem)
! || invariant_p (XEXP (mem, 0)) != 1)
/* There's no telling whether or not MEM is modified. */
loop_mems[i].optimize = 0;
--- 9769,9778 ----
rtx mem = loop_mems[i].mem;
rtx mem_list_entry;
! if ((MEM_VOLATILE_P (mem)
! || invariant_p (XEXP (mem, 0)) != 1)
! || (flag_float_store
! && GET_MODE_CLASS (GET_MODE (mem)) == MODE_FLOAT))
/* There's no telling whether or not MEM is modified. */
loop_mems[i].optimize = 0;
------------------
This version of the change is against gcc-2.95.2.
*** loop.c 1999/10/25 06:44:53 1.1
--- loop.c 1999/12/10 01:57:18
*************** load_mems (scan_start, end, loop_top, st
*** 9529,9536 ****
rtx mem = loop_mems[i].mem;
rtx mem_list_entry;
! if (MEM_VOLATILE_P (mem)
! || invariant_p (XEXP (mem, 0)) != 1)
/* There's no telling whether or not MEM is modified. */
loop_mems[i].optimize = 0;
--- 9529,9538 ----
rtx mem = loop_mems[i].mem;
rtx mem_list_entry;
! if ((MEM_VOLATILE_P (mem)
! || invariant_p (XEXP (mem, 0)) != 1)
! || (flag_float_store
! && GET_MODE_CLASS (GET_MODE (mem)) == MODE_FLOAT))
/* There's no telling whether or not MEM is modified. */
loop_mems[i].optimize = 0;
-------------------------------------------------------------------------------
- Nelson H. F. Beebe Tel: +1 801 581 5254 -
- Center for Scientific Computing FAX: +1 801 585 1640, +1 801 581 4148 -
- University of Utah Internet e-mail: beebeamath.utah.edu -
- Department of Mathematics, 322 INSCC beebeaacm.org -
- 155 S 1400 E RM 233 beebeaieee.org -
- Salt Lake City, UT 84112-0090, USA URL: http://www.math.utah.edu/~beebe -
-------------------------------------------------------------------------------
More information about the Numeric-interest
mailing list