[COMMITTED] RISC-V: Add another test for FRM elimination bug [PR118646]

Message ID 20250127220651.917824-1-vineetg@rivosinc.com
State Committed
Commit 019fe9c4d4c7cc9e325b5460d277ebaec108a838
Headers
Series [COMMITTED] RISC-V: Add another test for FRM elimination bug [PR118646] |

Checks

Context Check Description
rivoscibot/toolchain-ci-rivos-lint success Lint passed
rivoscibot/toolchain-ci-rivos-apply-patch success Patch applied
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
rivoscibot/toolchain-ci-rivos-build--newlib-rv64gcv-lp64d-multilib success Build passed
rivoscibot/toolchain-ci-rivos-build--linux-rv64gc_zba_zbb_zbc_zbs-lp64d-multilib success Build passed
rivoscibot/toolchain-ci-rivos-build--linux-rv64gcv-lp64d-multilib success Build passed
rivoscibot/toolchain-ci-rivos-test success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed

Commit Message

Vineet Gupta Jan. 27, 2025, 10:06 p.m. UTC
  The issue is same as PR118103 and fixed by commit 55d288d4ff53
("RISC-V: Make FRM as global register [PR118103]").

Essentially FRM save/restore were getting eliminated because FRM reg
semantics were not being modelled correctly.

In this case it showed up as SPEC2017 527.cam4 runtime aborts in
glibc:round_away() due to non-canonical rounding mode showing up,
"leaking" earlier in the call chain because such rounding mode
save/restore was getting eliminated.

	PR target/118646

gcc/testsuite/ChangeLog:
	* gfortran.target/riscv/rvv/pr118646.f90 (New Test).

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
 .../gfortran.target/riscv/rvv/pr118646.f90    | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.target/riscv/rvv/pr118646.f90
  

Patch

diff --git a/gcc/testsuite/gfortran.target/riscv/rvv/pr118646.f90 b/gcc/testsuite/gfortran.target/riscv/rvv/pr118646.f90
new file mode 100644
index 000000000000..e2a034316123
--- /dev/null
+++ b/gcc/testsuite/gfortran.target/riscv/rvv/pr118646.f90
@@ -0,0 +1,48 @@ 
+! Reduced from SPEC2017 527.cam4 zm_conv.F90
+
+! { dg-do compile }
+! { dg-options "-Ofast -std=legacy -march=rv64gcv_zvl256b_zba_zbb_zbs_zicond -ftree-vectorize -mabi=lp64d" }
+
+module a
+  contains
+subroutine b(f)
+
+   real d(4)
+   integer e(4)
+   integer f(4)
+   real hmax(4)
+   real g(4)
+
+   integer h(4)
+   integer l(4,5)
+   do i = 1,c
+      h(i) = 0
+   end do
+   do k = j  ,1
+      do i = 1,c
+         q = g(i) + hmax(i)
+         if (k >= nint(d(i)) .and. k <= e(i) .and. q > 1.e4) then
+            f(i) = k
+         end if
+      if (k < o ) then
+            if (buoy<= 0.) then
+               l(i,h) = k
+            end if
+         end if
+      end do
+   end do
+   do n = 1,5
+      do k = 1,m
+         do i = 1,c
+            if (k > l(i,n)) then
+               p = r()
+            end if
+         end do
+      end do
+   end do
+end
+end
+
+! { dg-final { scan-assembler-times {frrm\s+[axs][0-9]+} 1 } }
+! { dg-final { scan-assembler-times {fsrmi\s+[01234]} 1 } }
+! { dg-final { scan-assembler-times {fsrm\s+[axs][0-9]+} 1 } }