This is the mail archive of the gcc@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]
Other format: [Raw text]

Wrong RTL instruction deleted


Hello!

The testcase below produces different results when compiled with different optimization levels:

--cut here--
#include <stdio.h>

float foo ()
{
 unsigned int MASK = 0x80000000;
 return (float &) MASK;
}

int main() {
 printf ("%f\n", foo());
 return 0;
}
--cut here--

g++ -O1 yyy.cpp produces correct value:
./a.out
-0.000000
g++ -O1 yyy.cpp
./a.out
0.000000
g++ -O3 yyy.cpp
./a.out
36.658997

The asm code of foo() function is correct at -O1:
_Z3foov:
.LFB13:
       pushl   %ebp    #
.LCFI0:
       movl    %esp, %ebp      #,
.LCFI1:
       subl    $16, %esp       #,
.LCFI2:
       movl    $-2147483648, -4(%ebp)  #, MASK
       flds    -4(%ebp)        #
       leave
       ret

But for -O2, the move of constant to stack is missing:
_Z3foov:
.LFB13:
       pushl   %ebp    #
.LCFI0:
       movl    %esp, %ebp      #,
.LCFI1:
       subl    $16, %esp       #,
.LCFI2:
       flds    -4(%ebp)        #
       leave
       ret

Following is the RTL dump of .15.cse2, when foo() is compiled with -O2:
(note 6 2 9 NOTE_INSN_FUNCTION_BEG)

;; Start of basic block 0, registers live: (nil)
(note 9 6 11 0 [bb 0] NOTE_INSN_BASIC_BLOCK)

(insn 11 9 14 0 (set (mem/i:SI (plus:SI (reg/f:SI 20 frame)
               (const_int -4 [0xfffffffc])) [2 MASK+0 S4 A32])
       (const_int -2147483648 [0x80000000])) 35 {*movsi_1} (nil)
   (nil))

(insn 14 11 18 0 (set (reg:SF 61)
(mem:SF (plus:SI (reg/f:SI 20 frame)
(const_int -4 [0xfffffffc])) [3 S4 A32])) 60 {*movsf_1} (nil)
(nil))


(note 18 14 21 0 NOTE_INSN_FUNCTION_END)


And in .16.life, (insn 11) is simply missing (there is no NOTE_INSN_DELETED):
(note 6 2 9 NOTE_INSN_FUNCTION_BEG)


;; Start of basic block 0, registers live: 6 [bp] 7 [sp] 16 [argp] 20 [frame]
(note 9 6 14 0 [bb 0] NOTE_INSN_BASIC_BLOCK)


(insn 14 9 18 0 (set (reg:SF 61)
(mem:SF (plus:SI (reg/f:SI 20 frame)
(const_int -4 [0xfffffffc])) [3 S4 A32])) 60 {*movsf_1} (nil)
(nil))


(note 18 14 21 0 NOTE_INSN_FUNCTION_END)

In -O2, -O3, there is no initialization of temporary value on stack, so the result is undefined.
This behaviour was found when PR16111 was analyzed, but can be also related to PR13366.


Uros.


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