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

            Bug ID: 92637
           Summary: runtime issue with -ftree-coalesce-vars
           Product: gcc
           Version: 7.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dongjianqiang2 at huawei dot com
  Target Milestone: ---

Created attachment 47338
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47338&action=edit
testsuite

hi, I compiled the attached with aarch64-linux-gnu-gcc -c -O2  -march=armv8.1-a
testsuite.c -o testsuite.o, it had runtime error, and I found x10 was
overwriten ar row 214.
00000000000001d0 <find_next_zero_area>:
 1d0:   a9bf7bfd        stp     x29, x30, [sp, #-16]!
 1d4:   aa0403eb        mov     x11, x4
 1d8:   aa0003ea        mov     x10, x0
 1dc:   aa0103e9        mov     x9, x1
 1e0:   910003fd        mov     x29, sp
 1e4:   aa2403ed        mvn     x13, x4
 1e8:   2a0303ec        mov     w12, w3
 1ec:   14000005        b       200 <find_next_zero_area+0x30>
 1f0:   94000000        bl      f0 <find_next_bit>
 1f4:   eb00011f        cmp     x8, x0
 1f8:   54000209        b.ls    238 <find_next_zero_area+0x68>  // b.plast
 1fc:   91000402        add     x2, x0, #0x1
 200:   aa0903e1        mov     x1, x9
 204:   aa0a03e0        mov     x0, x10
 208:   94000000        bl      0 <find_next_zero_bit>
 20c:   8b0b0007        add     x7, x0, x11
 210:   8a0d00e7        and     x7, x7, x13
 214:   aa0a03e0        mov     x0, x10              // HERE x10 is overwriten
by glibc
 218:   8b0c00e8        add     x8, x7, x12
 21c:   aa0703e2        mov     x2, x7
 220:   aa0803e1        mov     x1, x8
 224:   eb08013f        cmp     x9, x8
 228:   54fffe42        b.cs    1f0 <find_next_zero_area+0x20>  // b.hs,
b.nlast
 22c:   aa0803e0        mov     x0, x8
 230:   a8c17bfd        ldp     x29, x30, [sp], #16
 234:   d65f03c0        ret
 238:   aa0703e8        mov     x8, x7
 23c:   aa0803e0        mov     x0, x8
 240:   a8c17bfd        ldp     x29, x30, [sp], #16
 244:   d65f03c0        ret

But when I add -fno-tree-coalesce-vars, x10 changed to x9, following assembler
is running correctly.
00000000000001e0 <find_next_zero_area>:
 1e0:   a9bf7bfd        stp     x29, x30, [sp, #-16]!
 1e4:   aa0403ea        mov     x10, x4
 1e8:   aa0003e9        mov     x9, x0
 1ec:   aa0103e8        mov     x8, x1
 1f0:   910003fd        mov     x29, sp
 1f4:   aa2403ec        mvn     x12, x4
 1f8:   2a0303eb        mov     w11, w3
 1fc:   14000005        b       210 <find_next_zero_area+0x30>
 200:   94000000        bl      f8 <find_next_bit>
 204:   eb0000ff        cmp     x7, x0
 208:   54000209        b.ls    248 <find_next_zero_area+0x68>  // b.plast
 20c:   91000402        add     x2, x0, #0x1
 210:   aa0803e1        mov     x1, x8
 214:   aa0903e0        mov     x0, x9         //HERE is correct
 218:   94000000        bl      0 <find_next_zero_bit>
 21c:   8b0a0006        add     x6, x0, x10
 220:   8a0c00c6        and     x6, x6, x12
 224:   aa0903e0        mov     x0, x9
 228:   8b0b00c7        add     x7, x6, x11
 22c:   aa0603e2        mov     x2, x6
 230:   aa0703e1        mov     x1, x7
 234:   eb07011f        cmp     x8, x7
 238:   54fffe42        b.cs    200 <find_next_zero_area+0x20>  // b.hs,
b.nlast
 23c:   aa0703e0        mov     x0, x7
 240:   a8c17bfd        ldp     x29, x30, [sp], #16
 244:   d65f03c0        ret
 248:   aa0603e0        mov     x0, x6
 24c:   a8c17bfd        ldp     x29, x30, [sp], #16
 250:   d65f03c0        ret

I checked x9-x15 are caller-saved register, why compiler doesn't push these
registers onto the stack across calls?

Reply via email to