Skip to content

Commit

Permalink
rs6000: Guard fctid on PowerPC64 and PowerPC476
Browse files Browse the repository at this point in the history
fctid is only supported on 64-bit Power processors and powerpc 476. It
should be guarded by this condition. The patch fixes the issue.

gcc/
	PR target/112707
	* config/rs6000/rs6000.h (TARGET_FCTID): Define.
	* config/rs6000/rs6000.md (lrint<mode>di2): Add guard TARGET_FCTID.
	* (lround<mode>di2): Replace TARGET_FPRND with TARGET_FCTID.

gcc/testsuite/
	PR target/112707
	* gcc.target/powerpc/pr112707.h: New.
	* gcc.target/powerpc/pr112707-2.c: New.
	* gcc.target/powerpc/pr112707-3.c: New.
	* gcc.target/powerpc/pr88558-p7.c: Check fctid on ilp32 and
	has_arch_ppc64 as it's now guarded by powerpc64.
	* gcc.target/powerpc/pr88558-p8.c: Likewise.
	* gfortran.dg/nint_p7.f90: Add powerpc64 target requirement as
	lround<mode>di2 is now guarded by powerpc64.
  • Loading branch information
Haochen Gui committed Dec 11, 2023
1 parent 46e342b commit ae226cb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gcc/config/rs6000/rs6000.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ extern int rs6000_vector_align[];
#define TARGET_FCFIDUS TARGET_POPCNTD
#define TARGET_FCTIDUZ TARGET_POPCNTD
#define TARGET_FCTIWUZ TARGET_POPCNTD
/* Only powerpc64 and powerpc476 support fctid. */
#define TARGET_FCTID (TARGET_POWERPC64 || rs6000_cpu == PROCESSOR_PPC476)
#define TARGET_CTZ TARGET_MODULO
#define TARGET_EXTSWSLI (TARGET_MODULO && TARGET_POWERPC64)
#define TARGET_MADDLD TARGET_MODULO
Expand Down
4 changes: 2 additions & 2 deletions gcc/config/rs6000/rs6000.md
Original file line number Diff line number Diff line change
Expand Up @@ -6736,7 +6736,7 @@
[(set (match_operand:DI 0 "gpc_reg_operand" "=d")
(unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
UNSPEC_FCTID))]
"TARGET_HARD_FLOAT"
"TARGET_HARD_FLOAT && TARGET_FCTID"
"fctid %0,%1"
[(set_attr "type" "fp")])

Expand Down Expand Up @@ -6830,7 +6830,7 @@
(set (match_operand:DI 0 "gpc_reg_operand")
(unspec:DI [(match_dup 2)]
UNSPEC_FCTID))]
"TARGET_HARD_FLOAT && TARGET_VSX && TARGET_FPRND"
"TARGET_HARD_FLOAT && TARGET_VSX && TARGET_FCTID"
{
operands[2] = gen_reg_rtx (<MODE>mode);
})
Expand Down
9 changes: 9 additions & 0 deletions gcc/testsuite/gcc.target/powerpc/pr112707-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* { dg-options "-O2 -mdejagnu-cpu=7450 -fno-math-errno" } */
/* { dg-require-effective-target ilp32 } */
/* { dg-skip-if "" { has_arch_ppc64 } } */
/* { dg-final { scan-assembler-not {\mfctid\M} } } */

/* powerpc 7450 doesn't support ppc64 (-m32 -mpowerpc64), so skips it. */

#include "pr112707.h"
9 changes: 9 additions & 0 deletions gcc/testsuite/gcc.target/powerpc/pr112707-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* { dg-do compile } */
/* { dg-options "-O2 -fno-math-errno -mdejagnu-cpu=476fp" } */
/* { dg-require-effective-target ilp32 } */

/* powerpc 476fp has hard float enabled which is required by fctid */

#include "pr112707.h"

/* { dg-final { scan-assembler-times {\mfctid\M} 2 } } */
10 changes: 10 additions & 0 deletions gcc/testsuite/gcc.target/powerpc/pr112707.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
long long test1 (double a)
{
return __builtin_llrint (a);
}

long long test2 (float a)
{
return __builtin_llrint (a);
}

2 changes: 1 addition & 1 deletion gcc/testsuite/gcc.target/powerpc/pr88558-p7.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "pr88558.h"

/* { dg-final { scan-assembler-times {\mfctid\M} 4 { target lp64 } } } */
/* { dg-final { scan-assembler-times {\mfctid\M} 2 { target ilp32 } } } */
/* { dg-final { scan-assembler-times {\mfctid\M} 2 { target { ilp32 && has_arch_ppc64 } } } } */
/* { dg-final { scan-assembler-times {\mfctiw\M} 2 { target lp64 } } } */
/* { dg-final { scan-assembler-times {\mfctiw\M} 4 { target ilp32 } } } */
/* { dg-final { scan-assembler-times {\mstfiwx\M} 2 { target lp64 } } } */
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/gcc.target/powerpc/pr88558-p8.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "pr88558.h"

/* { dg-final { scan-assembler-times {\mfctid\M} 4 { target lp64 } } } */
/* { dg-final { scan-assembler-times {\mfctid\M} 2 { target ilp32 } } } */
/* { dg-final { scan-assembler-times {\mfctid\M} 2 { target { ilp32 && has_arch_ppc64 } } } } */
/* { dg-final { scan-assembler-times {\mfctiw\M} 2 { target lp64 } } } */
/* { dg-final { scan-assembler-times {\mfctiw\M} 4 { target ilp32 } } } */
/* { dg-final { scan-assembler-times {\mmfvsrwz\M} 2 { target lp64 } } } */
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/gfortran.dg/nint_p7.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
! { dg-do compile { target { powerpc*-*-* } } }
! { dg-require-effective-target powerpc_vsx_ok }
! { dg-options "-O2 -mdejagnu-cpu=power7 -ffast-math" }
! { dg-require-effective-target has_arch_ppc64 }
! { dg-final { scan-assembler-times "xsrdpi" 2 } }

subroutine test_nint(x4,x8)
Expand Down

0 comments on commit ae226cb

Please sign in to comment.