https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89721

            Bug ID: 89721
           Summary: __builtin_mffs sometimes optimized away
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pc at gcc dot gnu.org
  Target Milestone: ---

Created attachment 45969
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45969&action=edit
test case where 3rd call to __builtin_mffs() is optimized away

I have a testcase that reports arguably incorrect results under any
optimization, correct results without optimization.  This is with GCC 7.3, 8.2,
and trunk.

Testcase attached.

Without optimization:
--
$ ./mffs-bug
fpscr = 0x0000000000000002
fpscr = 0x0000000000000003
fpscr = 0x0000000000000001
--

With -O:
--
$ ./mffs-bug-O
fpscr = 0x0000000000000002
fpscr = 0x0000000000000003
fpscr = 0x0000000000000003

If I remove interesting pieces of the code above the last stanza, the problem
disappears.

The generated assembly is missing the final (of 3) "mffs" instructions.  Below,
the instruction is expected roughly between 76c and 770:
--
...
 10000718:      li      r3,2
 1000071c:      bl      10000560 <00000018.plt_call.fesetround@@GLIBC_2.17>
 10000720:      ld      r2,24(r1)
 10000724:      mffs    f0
 10000728:      addis   r31,r2,-2
 1000072c:      addi    r31,r31,-30144
 10000730:      mfvsrd  r4,vs0
 10000734:      mr      r3,r31
 10000738:      bl      10000540 <00000018.plt_call.printf@@GLIBC_2.17>
 1000073c:      ld      r2,24(r1)
 10000740:      li      r3,3
 10000744:      bl      10000560 <00000018.plt_call.fesetround@@GLIBC_2.17>
 10000748:      ld      r2,24(r1)
 1000074c:      mffs    f0
 10000750:      fmr     f31,f0
 10000754:      mfvsrd  r4,vs0
 10000758:      mr      r3,r31
 1000075c:      bl      10000540 <00000018.plt_call.printf@@GLIBC_2.17>
 10000760:      ld      r2,24(r1)
 10000764:      li      r3,1
 10000768:      bl      10000560 <00000018.plt_call.fesetround@@GLIBC_2.17>
 1000076c:      ld      r2,24(r1)
 10000770:      mfvsrd  r4,vs31
 10000774:      mr      r3,r31
 10000778:      bl      10000540 <00000018.plt_call.printf@@GLIBC_2.17>
--

Reply via email to