public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113715] New: RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns
@ 2024-02-02  8:51 mumuxi_ll at outlook dot com
  2024-02-06  3:16 ` [Bug target/113715] " fanghuaqi at vip dot qq.com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: mumuxi_ll at outlook dot com @ 2024-02-02  8:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113715
           Summary: RISC-V: If the Zcmp is enabled, the a0 register
                    operates abnormally when the program returns
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mumuxi_ll at outlook dot com
  Target Milestone: ---

When compiling the following test.c code with the options
-march=rv32ima_zca_zcb_zcmp_zcmt -mabi=ilp32 -Os, a bug appears when gcc
enables zcmp. In the disassembly dump.txt, it can be observed that when
executing the bne instruction in test_err, a0 is not set to 0 as the function
return value.

Source code:

void test_1(int onoff)
{
    for (volatile int i = 0; i < 100; i ++) {

    }
}

int test_err(void *param, int mode, int *saveAddr)
{
    if (mode == 2) {
        test_1(1);
    }

    return 0;
}

int main()
{
    int ret = test_err((void *)0x123456, 3, (int *)0x123456);
    for (volatile int i = ret; i < 100; i ++) {
        ret = i * i;
    }
    return ret;
}


GCC ASM:

test_1:
        addi    sp,sp,-16
        sw      zero,12(sp)
        li      a4,99
.L2:
        lw      a5,12(sp)
        ble     a5,a4,.L3
        addi    sp,sp,16
        jr      ra
.L3:
        lw      a5,12(sp)
        addi    a5,a5,1
        sw      a5,12(sp)
        j       .L2
test_err:
        li      a5,2
        bne     a1,a5,.L8
        li      a0,1
        cm.push {ra}, -16
        call    test_1
        cm.popretz      {ra}, 16
.L8:
        ret
main:
        addi    sp,sp,-16
        sw      zero,12(sp)
        li      a0,0
        li      a3,99
.L12:
        lw      a5,12(sp)
        ble     a5,a3,.L13
        addi    sp,sp,16
        jr      ra
.L13:
        lw      a0,12(sp)
        lw      a4,12(sp)
        mul     a0,a0,a4
        lw      a4,12(sp)
        addi    a4,a4,1
        sw      a4,12(sp)
        j       .L12

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/113715] RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns
  2024-02-02  8:51 [Bug c/113715] New: RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns mumuxi_ll at outlook dot com
@ 2024-02-06  3:16 ` fanghuaqi at vip dot qq.com
  2024-02-06  3:36 ` pinskia at gcc dot gnu.org
  2024-02-08  3:11 ` fanghuaqi at vip dot qq.com
  2 siblings, 0 replies; 4+ messages in thread
From: fanghuaqi at vip dot qq.com @ 2024-02-06  3:16 UTC (permalink / raw)
  To: gcc-bugs

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

Huaqi <fanghuaqi at vip dot qq.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fanghuaqi at vip dot qq.com

--- Comment #1 from Huaqi <fanghuaqi at vip dot qq.com> ---
I tried to revert this commit
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b27d323a368033f0b37e93c57a57a35fd9997864

Then the wrong generated cm.popretz is removed, and it now works as expected,
could somebody check whether there is a better solution to this patch.

Thanks

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/113715] RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns
  2024-02-02  8:51 [Bug c/113715] New: RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns mumuxi_ll at outlook dot com
  2024-02-06  3:16 ` [Bug target/113715] " fanghuaqi at vip dot qq.com
@ 2024-02-06  3:36 ` pinskia at gcc dot gnu.org
  2024-02-08  3:11 ` fanghuaqi at vip dot qq.com
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-06  3:36 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-02-06
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes this is where shrink wrapping incorrects incorrectly with
riscv_zcmp_can_use_popretz optimization. Basically popretz should be disabled
for shrink wrapped function call I think ...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/113715] RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns
  2024-02-02  8:51 [Bug c/113715] New: RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns mumuxi_ll at outlook dot com
  2024-02-06  3:16 ` [Bug target/113715] " fanghuaqi at vip dot qq.com
  2024-02-06  3:36 ` pinskia at gcc dot gnu.org
@ 2024-02-08  3:11 ` fanghuaqi at vip dot qq.com
  2 siblings, 0 replies; 4+ messages in thread
From: fanghuaqi at vip dot qq.com @ 2024-02-08  3:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Huaqi <fanghuaqi at vip dot qq.com> ---
(In reply to Andrew Pinski from comment #2)
> Yes this is where shrink wrapping incorrects incorrectly with
> riscv_zcmp_can_use_popretz optimization. Basically popretz should be
> disabled for shrink wrapped function call I think ...

Maybe just revert this commit is a good approach for now, it won't affect other
functions, and later on someone upload new patch to implement this cm.popretz
generation

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-08  3:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02  8:51 [Bug c/113715] New: RISC-V: If the Zcmp is enabled, the a0 register operates abnormally when the program returns mumuxi_ll at outlook dot com
2024-02-06  3:16 ` [Bug target/113715] " fanghuaqi at vip dot qq.com
2024-02-06  3:36 ` pinskia at gcc dot gnu.org
2024-02-08  3:11 ` fanghuaqi at vip dot qq.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).