[gcc r15-15] decay vect tests from run to link for pr95401
https://gcc.gnu.org/g:05d83334d5bbeae01d71080f1da524810d6740d9 commit r15-15-g05d83334d5bbeae01d71080f1da524810d6740d9 Author: Alexandre Oliva Date: Sun Apr 28 04:29:54 2024 -0300 decay vect tests from run to link for pr95401 When vect.exp finds our configuration disables altivec by default, it disables the execution of vectorization tests, assuming the test hardware doesn't support it. Tests become just compile tests, but compile tests won't work correctly when additional sources are named, e.g. pr95401.cc, because GCC refuses to compile multiple files into the same asm output. With this patch, the default for when execution is not possible becomes link. for gcc/testsuite/ChangeLog * lib/target-supports.exp (check_vect_support_and_set_flags): Decay to link rather than compile. Diff: --- gcc/testsuite/lib/target-supports.exp | 18 +- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 3a55b2a4159..182d80129de 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -11625,7 +11625,7 @@ proc check_vect_support_and_set_flags { } { if [check_750cl_hw_available] { set dg-do-what-default run } else { -set dg-do-what-default compile +set dg-do-what-default link } } elseif [istarget powerpc*-*-*] { # Skip targets not supporting -maltivec. @@ -11655,14 +11655,14 @@ proc check_vect_support_and_set_flags { } { # some other cpu type specified above. set DEFAULT_VECTCFLAGS [linsert $DEFAULT_VECTCFLAGS 0 "-mcpu=970"] } -set dg-do-what-default compile +set dg-do-what-default link } } elseif { [istarget i?86-*-*] || [istarget x86_64-*-*] } { lappend DEFAULT_VECTCFLAGS "-msse2" if { [check_effective_target_sse2_runtime] } { set dg-do-what-default run } else { -set dg-do-what-default compile +set dg-do-what-default link } } elseif { [istarget mips*-*-*] && [check_effective_target_nomips16] } { @@ -11681,7 +11681,7 @@ proc check_vect_support_and_set_flags { } { if [check_effective_target_ultrasparc_hw] { set dg-do-what-default run } else { -set dg-do-what-default compile +set dg-do-what-default link } } elseif [istarget alpha*-*-*] { # Alpha's vectorization capabilities are extremely limited. @@ -11694,7 +11694,7 @@ proc check_vect_support_and_set_flags { } { if [check_alpha_max_hw_available] { set dg-do-what-default run } else { -set dg-do-what-default compile +set dg-do-what-default link } } elseif [istarget ia64-*-*] { set dg-do-what-default run @@ -11707,7 +11707,7 @@ proc check_vect_support_and_set_flags { } { if [is-effective-target arm_neon_hw] { set dg-do-what-default run } else { -set dg-do-what-default compile +set dg-do-what-default link } } elseif [istarget aarch64*-*-*] { set dg-do-what-default run @@ -11731,7 +11731,7 @@ proc check_vect_support_and_set_flags { } { set dg-do-what-default run } else { lappend DEFAULT_VECTCFLAGS "-march=z14" "-mzarch" -set dg-do-what-default compile +set dg-do-what-default link } } elseif [istarget amdgcn-*-*] { set dg-do-what-default run @@ -11742,7 +11742,7 @@ proc check_vect_support_and_set_flags { } { foreach item [add_options_for_riscv_v ""] { lappend DEFAULT_VECTCFLAGS $item } - set dg-do-what-default compile + set dg-do-what-default link } } elseif [istarget loongarch*-*-*] { # Set the default vectorization option to "-mlsx" due to the problem @@ -11751,7 +11751,7 @@ proc check_vect_support_and_set_flags { } { if [check_effective_target_loongarch_sx_hw] { set dg-do-what-default run } else { - set dg-do-what-default compile + set dg-do-what-default link } } else { return 0
[gcc r15-16] [testsuite] [ppc64] expect error on vxworks too
https://gcc.gnu.org/g:818ec41d50bc906523f8fd86d7c463dd90e16d24 commit r15-16-g818ec41d50bc906523f8fd86d7c463dd90e16d24 Author: Alexandre Oliva Date: Sun Apr 28 04:30:00 2024 -0300 [testsuite] [ppc64] expect error on vxworks too These ppc lp64 tests check for errors or warnings on -mno-powerpc64. On powerpc64-*-vxworks* we get the same errors as on most other covered platforms, but the tests did not mark them as expected for this target. On powerpc-*-vxworks*, the tests are skipped because lp64 is not satisfied, so I'm naming powerpc*-*-vxworks* rather than something more specific. for gcc/testsuite/ChangeLog * gcc.target/powerpc/pr106680-1.c: Error on vxworks too. * gcc.target/powerpc/pr106680-2.c: Likewise. * gcc.target/powerpc/pr106680-3.c: Likewise. Diff: --- gcc/testsuite/gcc.target/powerpc/pr106680-1.c | 2 +- gcc/testsuite/gcc.target/powerpc/pr106680-2.c | 2 +- gcc/testsuite/gcc.target/powerpc/pr106680-3.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.target/powerpc/pr106680-1.c b/gcc/testsuite/gcc.target/powerpc/pr106680-1.c index d624d43230a..aadaa614cfe 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr106680-1.c +++ b/gcc/testsuite/gcc.target/powerpc/pr106680-1.c @@ -8,6 +8,6 @@ int foo () return 1; } -/* { dg-error "'-m64' requires a PowerPC64 cpu" "PR106680" { target powerpc*-*-linux* powerpc*-*-freebsd* powerpc-*-rtems* } 0 } */ +/* { dg-error "'-m64' requires a PowerPC64 cpu" "PR106680" { target powerpc*-*-linux* powerpc*-*-freebsd* powerpc-*-rtems* powerpc*-*-vxworks* } 0 } */ /* { dg-warning "'-m64' requires PowerPC64 architecture, enabling" "PR106680" { target powerpc*-*-darwin* } 0 } */ /* { dg-warning "'-maix64' requires PowerPC64 architecture remain enabled" "PR106680" { target powerpc*-*-aix* } 0 } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr106680-2.c b/gcc/testsuite/gcc.target/powerpc/pr106680-2.c index a9ed73726ef..f0758e30335 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr106680-2.c +++ b/gcc/testsuite/gcc.target/powerpc/pr106680-2.c @@ -9,6 +9,6 @@ int foo () return 1; } -/* { dg-error "'-m64' requires a PowerPC64 cpu" "PR106680" { target powerpc*-*-linux* powerpc*-*-freebsd* powerpc-*-rtems* } 0 } */ +/* { dg-error "'-m64' requires a PowerPC64 cpu" "PR106680" { target powerpc*-*-linux* powerpc*-*-freebsd* powerpc-*-rtems* powerpc*-*-vxworks* } 0 } */ /* { dg-warning "'-m64' requires PowerPC64 architecture, enabling" "PR106680" { target powerpc*-*-darwin* } 0 } */ /* { dg-warning "'-maix64' requires PowerPC64 architecture remain enabled" "PR106680" { target powerpc*-*-aix* } 0 } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr106680-3.c b/gcc/testsuite/gcc.target/powerpc/pr106680-3.c index b642d5c7a00..bca012e2cf6 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr106680-3.c +++ b/gcc/testsuite/gcc.target/powerpc/pr106680-3.c @@ -8,6 +8,6 @@ int foo () return 1; } -/* { dg-error "'-m64' requires a PowerPC64 cpu" "PR106680" { target powerpc*-*-linux* powerpc*-*-freebsd* powerpc-*-rtems* } 0 } */ +/* { dg-error "'-m64' requires a PowerPC64 cpu" "PR106680" { target powerpc*-*-linux* powerpc*-*-freebsd* powerpc-*-rtems* powerpc*-*-vxworks* } 0 } */ /* { dg-warning "'-m64' requires PowerPC64 architecture, enabling" "PR106680" { target powerpc*-*-darwin* } 0 } */ /* { dg-warning "'-maix64' requires PowerPC64 architecture remain enabled" "PR106680" { target powerpc*-*-aix* } 0 } */
[gcc r15-17] Request check for hw support in ppc run tests with -maltivec/-mvsx
https://gcc.gnu.org/g:9929a683dae6d8d584acef38a8652f186492560f commit r15-17-g9929a683dae6d8d584acef38a8652f186492560f Author: Olivier Hainque Date: Sun Apr 28 04:30:06 2024 -0300 Request check for hw support in ppc run tests with -maltivec/-mvsx for gcc/testsuite/ChangeLog * gcc.target/powerpc/swaps-p8-20.c: Change powerpc_altivec_ok require-effective-target test into vmx_hw. * gcc.target/powerpc/vsx-vector-5.c: Change powerpc_vsx_ok require-effective-target test into vsx_hw. Diff: --- gcc/testsuite/gcc.target/powerpc/swaps-p8-20.c | 2 +- gcc/testsuite/gcc.target/powerpc/vsx-vector-5.c | 5 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.target/powerpc/swaps-p8-20.c b/gcc/testsuite/gcc.target/powerpc/swaps-p8-20.c index 564e8acb1f4..755519bfe84 100644 --- a/gcc/testsuite/gcc.target/powerpc/swaps-p8-20.c +++ b/gcc/testsuite/gcc.target/powerpc/swaps-p8-20.c @@ -1,5 +1,5 @@ /* { dg-do run } */ -/* { dg-require-effective-target powerpc_altivec_ok } */ +/* { dg-require-effective-target vmx_hw } */ /* { dg-options "-O2 -mdejagnu-cpu=power8 -maltivec" } */ /* The expansion for vector character multiply introduces a vperm operation. diff --git a/gcc/testsuite/gcc.target/powerpc/vsx-vector-5.c b/gcc/testsuite/gcc.target/powerpc/vsx-vector-5.c index dcc88b1f3a4..37a324b6f89 100644 --- a/gcc/testsuite/gcc.target/powerpc/vsx-vector-5.c +++ b/gcc/testsuite/gcc.target/powerpc/vsx-vector-5.c @@ -1,11 +1,8 @@ /* { dg-do run { target lp64 } } */ /* { dg-skip-if "" { powerpc*-*-darwin* } } */ -/* { dg-require-effective-target powerpc_vsx_ok } */ +/* { dg-require-effective-target vsx_hw } */ /* { dg-options "-mvsx -O2" } */ -/* This will run, and someday we should add the support to test whether we are - running on VSX hardware. */ - #include #include
[gcc r15-18] disable ldist for test, to restore vectorizing-candidate loop
https://gcc.gnu.org/g:cc6a439fdab933963b00c488e221ae33d7199aeb commit r15-18-gcc6a439fdab933963b00c488e221ae33d7199aeb Author: Alexandre Oliva Date: Sun Apr 28 04:30:15 2024 -0300 disable ldist for test, to restore vectorizing-candidate loop The loop we're supposed to try to vectorize in gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c is turned into a memset before the vectorizer runs. Various other tests in this set have already run into this, and the solution has been to disable this loop distribution transformation, enabled at -O2, so that the vectorizer gets a chance to transform the loop and, in this testcase, fail to do so. for gcc/testsuite/ChangeLog * gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c: Disable ldist. Diff: --- gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c b/gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c index 454a714a309..90b5d5a7f40 100644 --- a/gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c +++ b/gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-31a.c @@ -1,4 +1,5 @@ /* { dg-require-effective-target vect_int } */ +/* { dg-additional-options "-fno-tree-loop-distribute-patterns" } */ #include #include "../../tree-vect.h"
[gcc r15-19] ppc: testsuite: vec-mul requires vsx runtime
https://gcc.gnu.org/g:d48aba3c8b61e4a33d0f1fdd126e5cd15dc99a7f commit r15-19-gd48aba3c8b61e4a33d0f1fdd126e5cd15dc99a7f Author: Alexandre Oliva Date: Sun Apr 28 04:30:19 2024 -0300 ppc: testsuite: vec-mul requires vsx runtime vec-mul is an execution test, but it only requires a powerpc_vsx_ok effective target, which is enough only for compile tests. In order to check for runtime and execution environment support, we need to require vsx_hw. Make that a condition for execution, but still perform a compile test if the condition is not satisfied. for gcc/testsuite/ChangeLog * gcc.target/powerpc/vec-mul.c: Run on target vsx_hw, just compile otherwise. Diff: --- gcc/testsuite/gcc.target/powerpc/vec-mul.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/testsuite/gcc.target/powerpc/vec-mul.c b/gcc/testsuite/gcc.target/powerpc/vec-mul.c index bfcaf80719d..aa0ef7aa45a 100644 --- a/gcc/testsuite/gcc.target/powerpc/vec-mul.c +++ b/gcc/testsuite/gcc.target/powerpc/vec-mul.c @@ -1,5 +1,5 @@ -/* { dg-do run } */ -/* { dg-require-effective-target powerpc_vsx_ok } */ +/* { dg-do compile { target { { ! vsx_hw } && powerpc_vsx_ok } } } */ +/* { dg-do run { target vsx_hw } } */ /* { dg-options "-mvsx -O3" } */ /* Test that the vec_mul builtin works as expected. */
[gcc r15-20] xfail fetestexcept test - ppc always uses fcmpu
https://gcc.gnu.org/g:6e95dca31c6b4688e0f0a25c9c3aa8a0bedc9056 commit r15-20-g6e95dca31c6b4688e0f0a25c9c3aa8a0bedc9056 Author: Alexandre Oliva Date: Sun Apr 28 04:30:24 2024 -0300 xfail fetestexcept test - ppc always uses fcmpu gcc.dg/torture/pr91323.c tests that a compare with NaNf doesn't set an exception using builtin compare intrinsics, and that it does when using regular compare operators. That doesn't seem to be expected to work on powerpc targets. It fails on GNU/Linux, it's marked to be skipped on AIX, and a similar test, gcc.dg/torture/pr93133.c, has the execution test xfailed for all of powerpc*-*-*. In this test, the functions that use intrinsics for the compare end up with the same code as the one that uses compare operators, using fcmpu, a floating compare that, unlike fcmpo, does not set the invalid operand exception for quiet NaN. I couldn't find any evidence that the rs6000 backend ever outputs fcmpo. Therefore, I'm adding the same execution xfail marker to this test. for gcc/testsuite/ChangeLog PR target/58684 * gcc.dg/torture/pr91323.c: Expect execution fail on powerpc*-*-*. Diff: --- gcc/testsuite/gcc.dg/torture/pr91323.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/torture/pr91323.c b/gcc/testsuite/gcc.dg/torture/pr91323.c index 1411fcaa396..4574342e728 100644 --- a/gcc/testsuite/gcc.dg/torture/pr91323.c +++ b/gcc/testsuite/gcc.dg/torture/pr91323.c @@ -1,4 +1,5 @@ -/* { dg-do run } */ +/* { dg-do run { xfail powerpc*-*-* } } */ +/* remove the xfail for powerpc when pr58684 is fixed */ /* { dg-add-options ieee } */ /* { dg-require-effective-target fenv_exceptions } */ /* { dg-skip-if "fenv" { powerpc-ibm-aix* } } */
[gcc r15-21] [testsuite] require sqrt_insn effective target where needed
https://gcc.gnu.org/g:bc07fa6af54cc67f7fc85cc144f9686fad07f205 commit r15-21-gbc07fa6af54cc67f7fc85cc144f9686fad07f205 Author: Alexandre Oliva Date: Sun Apr 28 04:30:30 2024 -0300 [testsuite] require sqrt_insn effective target where needed Some tests fail on ppc and ppc64 when testing a compiler [with options for] for a CPU [emulator] that doesn't support the sqrt insn. The gcc.dg/cdce3.c is one in which the expected shrink-wrap optimization only takes place when the target CPU supports a sqrt insn. The gcc.target/powerpc/pr46728-1[0-4].c tests use -mpowerpc-gpopt and call sqrt(), which involves the sqrt insn that the target CPU under test may not support. Require a sqrt_insn effective target for all the affected tests. for gcc/testsuite/ChangeLog * gcc.dg/cdce3.c: Require sqrt_insn effective target. * gcc.target/powerpc/pr46728-10.c: Likewise. Drop darwin explicit skipping. * gcc.target/powerpc/pr46728-11.c: Likewise. Likewise. * gcc.target/powerpc/pr46728-13.c: Likewise. Likewise. * gcc.target/powerpc/pr46728-14.c: Likewise. Likewise. Diff: --- gcc/testsuite/gcc.dg/cdce3.c | 3 ++- gcc/testsuite/gcc.target/powerpc/pr46728-10.c | 2 +- gcc/testsuite/gcc.target/powerpc/pr46728-11.c | 2 +- gcc/testsuite/gcc.target/powerpc/pr46728-13.c | 2 +- gcc/testsuite/gcc.target/powerpc/pr46728-14.c | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.dg/cdce3.c b/gcc/testsuite/gcc.dg/cdce3.c index 601ddf055fd..f759a95972e 100644 --- a/gcc/testsuite/gcc.dg/cdce3.c +++ b/gcc/testsuite/gcc.dg/cdce3.c @@ -1,7 +1,8 @@ /* { dg-do compile } */ /* { dg-require-effective-target hard_float } */ +/* { dg-require-effective-target sqrt_insn } */ /* { dg-options "-O2 -fmath-errno -fdump-tree-cdce-details -fdump-tree-optimized" } */ -/* { dg-final { scan-tree-dump "cdce3.c:11: \[^\n\r]* function call is shrink-wrapped into error conditions\." "cdce" } } */ +/* { dg-final { scan-tree-dump "cdce3.c:12: \[^\n\r]* function call is shrink-wrapped into error conditions\." "cdce" } } */ /* { dg-final { scan-tree-dump "sqrtf \\(\[^\n\r]*\\); \\\[tail call\\\]" "optimized" } } */ /* { dg-skip-if "doesn't have a sqrtf insn" { mmix-*-* } } */ diff --git a/gcc/testsuite/gcc.target/powerpc/pr46728-10.c b/gcc/testsuite/gcc.target/powerpc/pr46728-10.c index 3be4728d333..c04a3101c11 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr46728-10.c +++ b/gcc/testsuite/gcc.target/powerpc/pr46728-10.c @@ -1,6 +1,6 @@ /* { dg-do run } */ -/* { dg-skip-if "-mpowerpc-gpopt not supported" { powerpc*-*-darwin* } } */ /* { dg-options "-O2 -ffast-math -fno-inline -fno-unroll-loops -lm -mpowerpc-gpopt" } */ +/* { dg-require-effective-target sqrt_insn } */ #include diff --git a/gcc/testsuite/gcc.target/powerpc/pr46728-11.c b/gcc/testsuite/gcc.target/powerpc/pr46728-11.c index 43b6728a4b8..d0e3d602121 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr46728-11.c +++ b/gcc/testsuite/gcc.target/powerpc/pr46728-11.c @@ -1,6 +1,6 @@ /* { dg-do run } */ -/* { dg-skip-if "-mpowerpc-gpopt not supported" { powerpc*-*-darwin* } } */ /* { dg-options "-O2 -ffast-math -fno-inline -fno-unroll-loops -lm -mpowerpc-gpopt" } */ +/* { dg-require-effective-target sqrt_insn } */ #include diff --git a/gcc/testsuite/gcc.target/powerpc/pr46728-13.c b/gcc/testsuite/gcc.target/powerpc/pr46728-13.c index b9fd63973b7..2b9df737a9b 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr46728-13.c +++ b/gcc/testsuite/gcc.target/powerpc/pr46728-13.c @@ -1,6 +1,6 @@ /* { dg-do run } */ -/* { dg-skip-if "-mpowerpc-gpopt not supported" { powerpc*-*-darwin* } } */ /* { dg-options "-O2 -ffast-math -fno-inline -fno-unroll-loops -lm -mpowerpc-gpopt" } */ +/* { dg-require-effective-target sqrt_insn } */ #include diff --git a/gcc/testsuite/gcc.target/powerpc/pr46728-14.c b/gcc/testsuite/gcc.target/powerpc/pr46728-14.c index 5a13bdb..e6836f515e4 100644 --- a/gcc/testsuite/gcc.target/powerpc/pr46728-14.c +++ b/gcc/testsuite/gcc.target/powerpc/pr46728-14.c @@ -1,6 +1,6 @@ /* { dg-do run } */ -/* { dg-skip-if "-mpowerpc-gpopt not supported" { powerpc*-*-darwin* } } */ /* { dg-options "-O2 -ffast-math -fno-inline -fno-unroll-loops -lm -mpowerpc-gpopt" } */ +/* { dg-require-effective-target sqrt_insn } */ #include
[gcc r15-22] Adjust alternative *k to ?k for avx512 mask in zero_extend patterns
https://gcc.gnu.org/g:c19a674d03847b900919b97d0957c8ae5164f8f1 commit r15-22-gc19a674d03847b900919b97d0957c8ae5164f8f1 Author: liuhongt Date: Tue Apr 16 08:37:22 2024 +0800 Adjust alternative *k to ?k for avx512 mask in zero_extend patterns So when both source operand and dest operand require avx512 MASK_REGS, RA can allocate MASK_REGS register instead of GPR to avoid reload it from GPR to MASK_REGS. gcc/ChangeLog: * config/i386/i386.md: (zero_extendsidi2): Adjust alternative *k to ?k. (zero_extenddi2): Ditto. (*zero_extendsi2): Ditto. (*zero_extendqihi2): Ditto. Diff: --- gcc/config/i386/i386.md | 16 - gcc/testsuite/gcc.target/i386/zero_extendkmask.c | 43 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 80e64c603eb..764bfe20ff2 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -4569,10 +4569,10 @@ (define_insn "*zero_extendsidi2" [(set (match_operand:DI 0 "nonimmediate_operand" - "=r,?r,?o,r ,o,?*y,?!*y,$r,$v,$x,*x,*v,*r,*k") + "=r,?r,?o,r ,o,?*y,?!*y,$r,$v,$x,*x,*v,?r,?k") (zero_extend:DI (match_operand:SI 1 "x86_64_zext_operand" - "0 ,rm,r ,rmWz,0,r ,m ,v ,r ,m ,*x,*v,*k,*km")))] + "0 ,rm,r ,rmWz,0,r ,m ,v ,r ,m ,*x,*v,?k,?km")))] "" { switch (get_attr_type (insn)) @@ -4705,9 +4705,9 @@ [(QI "avx512dq") (HI "avx512f") (SI "avx512bw") (DI "avx512bw")]) (define_insn "zero_extenddi2" - [(set (match_operand:DI 0 "register_operand" "=r,*r,*k") + [(set (match_operand:DI 0 "register_operand" "=r,?r,?k") (zero_extend:DI -(match_operand:SWI12 1 "nonimmediate_operand" "m,*k,*km")))] +(match_operand:SWI12 1 "nonimmediate_operand" "m,?k,?km")))] "TARGET_64BIT" "@ movz{l|x}\t{%1, %k0|%k0, %1} @@ -4760,9 +4760,9 @@ (set_attr "mode" "SI")]) (define_insn "*zero_extendsi2" - [(set (match_operand:SI 0 "register_operand" "=r,*r,*k") + [(set (match_operand:SI 0 "register_operand" "=r,?r,?k") (zero_extend:SI - (match_operand:SWI12 1 "nonimmediate_operand" "m,*k,*km")))] + (match_operand:SWI12 1 "nonimmediate_operand" "m,?k,?km")))] "!(TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))" "@ movz{l|x}\t{%1, %0|%0, %1} @@ -4815,8 +4815,8 @@ ; zero extend to SImode to avoid partial register stalls (define_insn "*zero_extendqihi2" - [(set (match_operand:HI 0 "register_operand" "=r,*r,*k") - (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm,*k,*km")))] + [(set (match_operand:HI 0 "register_operand" "=r,?r,?k") + (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "qm,?k,?km")))] "!(TARGET_ZERO_EXTEND_WITH_AND && optimize_function_for_speed_p (cfun))" "@ movz{bl|x}\t{%1, %k0|%k0, %1} diff --git a/gcc/testsuite/gcc.target/i386/zero_extendkmask.c b/gcc/testsuite/gcc.target/i386/zero_extendkmask.c new file mode 100644 index 000..6b18980bbd1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/zero_extendkmask.c @@ -0,0 +1,43 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-march=x86-64-v4 -O2" } */ +/* { dg-final { scan-assembler-not {(?n)shr[bwl]} } } */ +/* { dg-final { scan-assembler-not {(?n)movz[bw]} } } */ + +#include + +__m512 +foo (__m512d a, __m512d b, __m512 c, __m512 d) +{ + return _mm512_mask_mov_ps (c, (__mmask16) (_mm512_cmpeq_pd_mask (a, b) >> 1), d); +} + + +__m512i +foo1 (__m512d a, __m512d b, __m512i c, __m512i d) +{ + return _mm512_mask_mov_epi16 (c, (__mmask32) (_mm512_cmpeq_pd_mask (a, b) >> 1), d); +} + +__m512i +foo2 (__m512d a, __m512d b, __m512i c, __m512i d) +{ + return _mm512_mask_mov_epi8 (c, (__mmask64) (_mm512_cmpeq_pd_mask (a, b) >> 1), d); +} + +__m512i +foo3 (__m512 a, __m512 b, __m512i c, __m512i d) +{ + return _mm512_mask_mov_epi16 (c, (__mmask32) (_mm512_cmpeq_ps_mask (a, b) >> 1), d); +} + +__m512i +foo4 (__m512 a, __m512 b, __m512i c, __m512i d) +{ + return _mm512_mask_mov_epi8 (c, (__mmask64) (_mm512_cmpeq_ps_mask (a, b) >> 1), d); +} + +__m512i +foo5 (__m512i a, __m512i b, __m512i c, __m512i d) +{ + return _mm512_mask_mov_epi8 (c, (__mmask64) (_mm512_cmp_epi16_mask (a, b, 5) >> 1), d); +}
[gcc r15-23] doc: Update David Binderman's entry in contrib.texi
https://gcc.gnu.org/g:62177c91213bd06c75b3ea6cdf052d550db2bf6b commit r15-23-g62177c91213bd06c75b3ea6cdf052d550db2bf6b Author: Gerald Pfeifer Date: Sun Apr 28 13:40:53 2024 +0200 doc: Update David Binderman's entry in contrib.texi gcc/ChangeLog: * doc/contrib.texi: Update David Binderman's entry. Diff: --- gcc/doc/contrib.texi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/doc/contrib.texi b/gcc/doc/contrib.texi index 2a15fd05883..32e89d6df25 100644 --- a/gcc/doc/contrib.texi +++ b/gcc/doc/contrib.texi @@ -64,8 +64,8 @@ improved alias analysis, plus migrating GCC to Bugzilla. Geoff Berry for his Java object serialization work and various patches. @item -David Binderman tests weekly snapshots of GCC trunk against Fedora Rawhide -for several architectures. +David Binderman for testing GCC trunk against Fedora Rawhide +and csmith. @item Laurynas Biveinis for memory management work and DJGPP port fixes.
[gcc r15-24] doc: Remove references to FreeBSD 7 and older
https://gcc.gnu.org/g:507f3ce34c55e78b23eeaf57bc4d927a1f25f8fb commit r15-24-g507f3ce34c55e78b23eeaf57bc4d927a1f25f8fb Author: Gerald Pfeifer Date: Sun Apr 28 14:59:14 2024 +0200 doc: Remove references to FreeBSD 7 and older FreeBSD 7 has been end of life for years and current GCC most likely would not build there anymore anyways. gcc: PR target/69374 PR target/112959 * doc/install.texi (Specific) <*-*-freebsd*>: Remove references to FreeBSD 7 and older. Diff: --- gcc/doc/install.texi | 9 ++--- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index 4b4f1e3e639..b13c62ed2b7 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -4096,18 +4096,13 @@ debugging formats. Otherwise, this release of GCC should now match more of the configuration used in the stock FreeBSD configuration of GCC@. In particular, @option{--enable-threads} is now configured by default. However, as a general user, do not attempt to replace the -system compiler with this release. Known to bootstrap and check with -good results on FreeBSD 7.2-STABLE@. In the past, known to bootstrap -and check with good results on FreeBSD 3.0, 3.4, 4.0, 4.2, 4.3, 4.4, -4.5, 4.8, 4.9 and 5-CURRENT@. +system compiler with this release. The version of binutils installed in @file{/usr/bin} probably works with this release of GCC@. Bootstrapping against the latest GNU binutils and/or the version found in @file{/usr/ports/devel/binutils} has been known to enable additional features and improve overall testsuite -results. However, it is currently known that boehm-gc may not configure -properly on FreeBSD prior to the FreeBSD 7.0 release with GNU binutils -after 2.16.1. +results. @html
[gcc r11-11385] Darwin: Fix constant CFString code-gen [PR105522].
https://gcc.gnu.org/g:a1b0ace9737a40957bfb298de22066d8ee9a6603 commit r11-11385-ga1b0ace9737a40957bfb298de22066d8ee9a6603 Author: Iain Sandoe Date: Sat Jan 6 10:52:38 2024 + Darwin: Fix constant CFString code-gen [PR105522]. Although this only fires for one of the Darwin sub-ports, it is latent elsewhere, it is also a regression c.f. the Darwin system compiler. In the code we imported from an earlier branch, CFString objects (which are constant aggregates) are constructed as CONST_DECLs. Although our current documentation suggests that these are reserved for enumeration values, in fact they are used elsewhere in the compiler for constants. This includes Objective-C where they are used to form NSString constants. In the particular case, we take the address of the constant and that triggers varasm.cc:decode_addr_constant, which does not currently support CONST_DECL. If there is a general intent to allow/encourage wider use of CONST_DECL, then we should fix decode_addr_constant to look through these and evaluate the initializer (a two-line patch, but I'm not suggesting it for stage-4). We also need to update the GCC internals documentation to allow for the additional uses. This patch is Darwin-local and fixes the problem by making the CFString constants into regular variable but TREE_CONSTANT+TREE_READONLY. I plan to back-port this to the open branches once it has baked a while on trunk. Since, for Darwin, the Objective-C default is to construct constant NSString objects as CFStrings; this will also cover the majority of cases there (this patch does not make any changes to Objective-C NSStrings). PR target/105522 gcc/ChangeLog: * config/darwin.c (machopic_select_section): Handle C and C++ CFStrings. (darwin_rename_builtins): Move this out of the CFString code. (darwin_libc_has_function): Likewise. (darwin_build_constant_cfstring): Create an anonymous var to hold each CFString. * config/darwin.h (ASM_OUTPUT_LABELREF): Handle constant CFstrings. Signed-off-by: Iain Sandoe (cherry picked from commit aecc0d4ba73d0810334b351da1e67232cea450d3) Diff: --- gcc/config/darwin.c | 97 - gcc/config/darwin.h | 2 + gcc/testsuite/gcc.dg/pr105522.c | 17 3 files changed, 76 insertions(+), 40 deletions(-) diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 2a3de33ee95..4f1221d636c 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -1689,7 +1689,16 @@ machopic_select_section (tree decl, base_section = darwin_sections[zobj_data_section]; } else if (ro) - base_section = darwin_sections[const_data_section]; + { + if (VAR_P (decl) && TREE_TYPE (decl) + && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE + && DECL_NAME (decl) + && strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)), + "__anon_cfstring", 15) == 0) + base_section = darwin_sections[cfstring_constant_object_section]; + else + base_section = darwin_sections[const_data_section]; + } else base_section = data_section; break; @@ -1753,8 +1762,6 @@ machopic_select_section (tree decl, else return darwin_sections[objc_string_object_section]; } - else if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_CFString")) - return darwin_sections[cfstring_constant_object_section]; else return base_section; } @@ -3570,6 +3577,29 @@ darwin_patch_builtins (void) } #endif +void +darwin_rename_builtins (void) +{ +} + +/* Implementation for the TARGET_LIBC_HAS_FUNCTION hook. */ + +bool +darwin_libc_has_function (enum function_class fn_class, + tree type ATTRIBUTE_UNUSED) +{ + if (fn_class == function_sincos && darwin_macosx_version_min) +return (strverscmp (darwin_macosx_version_min, "10.9") >= 0); +#if DARWIN_PPC && SUPPORT_DARWIN_LEGACY + if (fn_class == function_c99_math_complex + || fn_class == function_c99_misc) +return (TARGET_64BIT + || (darwin_macosx_version_min && + strverscmp (darwin_macosx_version_min, "10.3") >= 0)); +#endif + return default_libc_has_function (fn_class, type); +} + /* CFStrings implementation. */ static GTY(()) tree cfstring_class_reference = NULL_TREE; static GTY(()) tree cfstring_type_node = NULL_TREE; @@ -3587,7 +3617,7 @@ typedef struct GTY ((for_user)) cfstring_descriptor { /* The string literal. */ tree literal; /* The resulting constant CFString. */ - tree constructor; + tree ccf_str; } cfstring_descriptor; struct cfstring_hasher : ggc_ptr_hash @@ -3662,7 +3692,7 @@ darwin_init_cfstring_builtins
[gcc r11-11386] Darwin: Fix a typo in Objective-C meta-data.
https://gcc.gnu.org/g:310b047f4b723e0dd21a212c8ba051c380030cf4 commit r11-11386-g310b047f4b723e0dd21a212c8ba051c380030cf4 Author: Iain Sandoe Date: Mon Jan 8 16:17:04 2024 + Darwin: Fix a typo in Objective-C meta-data. We have a typo in the metadata for assigning NSStrings to a specific section for the V1 (32b) ABI. When that is fixed we should never see the case where the section needs to be deduced from the properties of the DECLs. gcc/ChangeLog: * config/darwin.c (darwin_objc1_section): Use the correct meta-data version for constant strings. (machopic_select_section): Assert if we fail to handle CFString sections as Obejctive-C meta-data or drectly. Signed-off-by: Iain Sandoe (cherry picked from commit 8d26636f0da31e6c17b57ced52bfc61a45f23cee) Diff: --- gcc/config/darwin.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 4f1221d636c..ec779332544 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -1596,7 +1596,7 @@ darwin_objc1_section (tree decl ATTRIBUTE_UNUSED, tree meta, section * base) else if (!strncmp (p, "V1_CEXT", 7)) return darwin_sections[objc1_class_ext_section]; - else if (!strncmp (p, "V2_CSTR", 7)) + else if (!strncmp (p, "V1_CSTR", 7)) return darwin_sections[objc_constant_string_object_section]; return base; @@ -1740,7 +1740,7 @@ machopic_select_section (tree decl, return base_section; /* GNU runtime is happy with it all in one pot. */ } - /* b) Constant string objects. */ + /* b) Constructors for constant NSstring [but not CFString] objects. */ if (TREE_CODE (decl) == CONSTRUCTOR && TREE_TYPE (decl) && TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE @@ -1762,6 +1762,12 @@ machopic_select_section (tree decl, else return darwin_sections[objc_string_object_section]; } + else if (!strcmp (IDENTIFIER_POINTER (name), "__builtin_CFString")) + { + /* We should have handled __anon_cfstrings above. */ + gcc_checking_assert (0); + return darwin_sections[cfstring_constant_object_section]; + } else return base_section; }
[gcc r11-11387] Objective-C/C++: Ensure sufficient setup for the preprocessor.
https://gcc.gnu.org/g:acfa562eaa440bf2bd5bd09035bd8bbde5d37d60 commit r11-11387-gacfa562eaa440bf2bd5bd09035bd8bbde5d37d60 Author: Iain Sandoe Date: Tue Jan 9 17:31:41 2024 + Objective-C/C++: Ensure sufficient setup for the preprocessor. The tokenizer makes use of functions that determine if identifiers are interface or class names, and those functions need a hash map to be set up. This ensures that these are initialized before pre-process-only jobs are run. gcc/objc/ChangeLog: * objc-act.c (objc_init): Initialize interface and class name hash maps before the preprocessor uses them. Signed-off-by: Iain Sandoe (cherry picked from commit 60f58d0630805e8dce79f5489658fd83e42fa8f1) Diff: --- gcc/objc/objc-act.c | 7 +-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 536ec028dbd..cb1fcbb2086 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -347,6 +347,11 @@ bool objc_init (void) { bool ok; + + /* Set up stuff used by the preprocessor as well as FE parser. */ + interface_hash_init (); + hash_init (); + #ifdef OBJCPLUS if (cxx_init () == false) #else @@ -376,8 +381,6 @@ objc_init (void) /* Set up stuff used by FE parser and all runtimes. */ errbuf = XNEWVEC (char, 1024 * 10); - interface_hash_init (); - hash_init (); objc_encoding_init (); /* ... and then check flags and set-up for the selected runtime ... */ if (flag_next_runtime && flag_objc_abi >= 2)
[gcc r11-11388] Objective-C, Darwin: Do not overalign CFStrings and Objective-C metadata.
https://gcc.gnu.org/g:88d9c5bfb17ef5c5288eb58ddc64dee7d52ecdf4 commit r11-11388-g88d9c5bfb17ef5c5288eb58ddc64dee7d52ecdf4 Author: Iain Sandoe Date: Thu Jan 25 20:11:09 2024 + Objective-C, Darwin: Do not overalign CFStrings and Objective-C metadata. We have reports of regressions in both Objective-C and Objective-C++ on Darwin23 (macOS 14). In some cases, these are linker warnings about the alignment of CFString constants; in other cases the built executables crash during runtime initialization. The underlying issue is the same in both cases; since the objects (CFStrings, Objective-C meta-data) are TU- local, we are choosing to increase their alignment for efficiency - to values greater than ABI alignment. However, although these objects are TU-local, they are also visible to the linker (since they are placed in specific named sections). In many cases the metadata can be regarded as tables of data, and thus it is expected that these sections can be concatenated from multiple TUs and the data treated as tabular. In order for this to work the data cannot be allowed to exceed ABI alignment - which leads to the crashes. For GCC-15+ it would be nice to find a more elegant solution to this issue (perhaps by adjusting the concept of binds-locally to exclude specific named sections) - but I do not want to do that in stage 4. The solution here is to force the alignment to be preserved as created by setting DECL_USER_ALIGN on the relevant objects. gcc/ChangeLog: * config/darwin.c (darwin_build_constant_cfstring): Prevent over- alignment of CFString constants by setting DECL_USER_ALIGN. gcc/objc/ChangeLog: * objc-next-runtime-abi-02.c (build_v2_address_table): Prevent over-alignment of Objective-C metadata by setting DECL_USER_ALIGN on relevant variables. (build_v2_protocol_list_address_table): Likewise. (generate_v2_protocol_list): Likewise. (generate_v2_meth_descriptor_table): Likewise. (generate_v2_meth_type_list): Likewise. (generate_v2_property_table): Likewise. (generate_v2_dispatch_table): Likewise. (generate_v2_ivars_list): Likewise. (generate_v2_class_structs): Likewise. (build_ehtype): Likewise. * objc-runtime-shared-support.c (generate_strings): Likewise. Signed-off-by: Iain Sandoe (cherry picked from commit f74f840d35117bcaf995cee99fb2ab30c60f64f3) Diff: --- gcc/config/darwin.c| 1 + gcc/objc/objc-next-runtime-abi-02.c| 18 +++--- gcc/objc/objc-runtime-shared-support.c | 4 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index ec779332544..6e887a9ba5a 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -3867,6 +3867,7 @@ darwin_build_constant_cfstring (tree str) /* global namespace. */ DECL_CONTEXT (var) = NULL_TREE; DECL_INITIAL (var) = constructor; + DECL_USER_ALIGN (var) = 1; lang_hooks.decls.pushdecl (var); rest_of_decl_compilation (var, 1, 0); desc->ccf_str = var; diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c index 0c59299db05..cb22a773fcb 100644 --- a/gcc/objc/objc-next-runtime-abi-02.c +++ b/gcc/objc/objc-next-runtime-abi-02.c @@ -2251,6 +2251,7 @@ build_v2_address_table (vec *src, const char *nam, tree attr) DECL_PRESERVE_P (decl) = 1; expr = objc_build_constructor (type, initlist); OBJCMETA (decl, objc_meta, attr); + DECL_USER_ALIGN (decl) = 1; finish_var_decl (decl, expr); } @@ -2325,8 +2326,9 @@ build_v2_protocol_list_address_table (void) decl = create_global_decl (objc_protocol_type, buf, /*is def=*/true); expr = convert (objc_protocol_type, build_fold_addr_expr (ref->refdecl)); OBJCMETA (decl, objc_meta, meta_label_protocollist); - finish_var_decl (decl, expr); DECL_PRESERVE_P (decl) = 1; + DECL_USER_ALIGN (decl) = 1; + finish_var_decl (decl, expr); } /* TODO: delete the vec. */ @@ -2404,6 +2406,7 @@ generate_v2_protocol_list (tree i_or_p, tree klass_ctxt) /* ObjC2 puts all these in the base section. */ OBJCMETA (refs_decl, objc_meta, meta_base); DECL_PRESERVE_P (refs_decl) = 1; + DECL_USER_ALIGN (refs_decl) = 1; finish_var_decl (refs_decl, objc_build_constructor (TREE_TYPE (refs_decl),initlist)); return refs_decl; @@ -2512,6 +2515,7 @@ generate_v2_meth_descriptor_table (tree chain, tree protocol, CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, initlist); /* Get into the right section. */ OBJCMETA (decl, objc_meta, attr); + DECL_USER_ALIGN (decl) = 1; finish_var_decl (decl, objc_build_constructor (method_list_template, v)); return decl; } @@ -2530,13 +2
[gcc r11-11389] Darwin: Correct handling of weak crts.
https://gcc.gnu.org/g:61d0cd29f9f107bee1d193b75b87d0ebe0766ede commit r11-11389-g61d0cd29f9f107bee1d193b75b87d0ebe0766ede Author: Iain Sandoe Date: Thu Mar 21 14:34:44 2024 + Darwin: Correct handling of weak crts. Backport part of 506e74f53a5 from trunk. We need the weak crts to be considered ahead of GCC target libraries (except libgcc_s) to avoid spurious dependencies on otherwise unused libs. gcc/ChangeLog: * config/darwin.h (LINK_COMMAND_SPEC_A): Handle weak crts before other objects. (REAL_LIBGCC_SPEC): Remove weak crts from here. (DARWIN_WEAK_CRTS): New. Signed-off-by: Iain Sandoe Diff: --- gcc/config/darwin.h | 37 ++--- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/gcc/config/darwin.h b/gcc/config/darwin.h index e2aa6b745d0..1fded756c60 100644 --- a/gcc/config/darwin.h +++ b/gcc/config/darwin.h @@ -351,7 +351,9 @@ extern GTY(()) int darwin_ms_struct; %{e*} %{r} \ %{o*}%{!o:-o a.out} \ %{!r:%{!nostdlib:%{!nostartfiles:%S}}} \ -%{L*} %(link_libgcc) %o \ +%{L*} %(link_libgcc) \ +%{!r:%{!nostdlib:%{!nodefaultlibs: " DARWIN_WEAK_CRTS "}}} \ +%o \ %{!r:%{!nostdlib:%{!nodefaultlibs:\ %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \ %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): \ @@ -365,15 +367,15 @@ extern GTY(()) int darwin_ms_struct; %(link_ssp) \ %:version-compare(>< 10.6 10.7 mmacosx-version-min= -ld10-uwfef) \ %(link_gcc_c_sequence) \ - %{!nodefaultexport:%{dylib|dynamiclib|bundle: \ - %:version-compare(>= 10.11 asm_macosx_version_min= -U) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \ - %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_get_address) \ - %:version-compare(>= 10.11 asm_macosx_version_min= -U) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \ - %:version-compare(>= 10.11 asm_macosx_version_min= -exported_symbol) \ - %:version-compare(>= 10.11 asm_macosx_version_min= ___emutls_register_common) \ + %{!nodefaultexport: \ + %{%:version-compare(>= 10.11 asm_macosx_version_min= -U): \ + ___emutls_get_address -exported_symbol ___emutls_get_address \ + -U ___emutls_register_common \ + -exported_symbol ___emutls_register_common \ + -U ___gcc_nested_func_ptr_created \ + -exported_symbol ___gcc_nested_func_ptr_created \ + -U ___gcc_nested_func_ptr_deleted \ + -exported_symbol ___gcc_nested_func_ptr_deleted \ }} \ }}}\ %{!r:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} %{F*} "\ @@ -500,17 +502,22 @@ extern GTY(()) int darwin_ms_struct; #undef REAL_LIBGCC_SPEC #define REAL_LIBGCC_SPEC \ "%{static-libgcc|static: \ -%:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh) \ -%:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w); \ +%:version-compare(!> 10.6 mmacosx-version-min= -lgcc_eh);\ shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ %:version-compare(!> 10.11 mmacosx-version-min= -lgcc_s.1.1) \ -%:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) \ %:version-compare(!> 10.3.9 mmacosx-version-min= -lgcc_eh) \ %:version-compare(>< 10.3.9 10.5 mmacosx-version-min= -lgcc_s.10.4) \ -%:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5); \ - : -lemutls_w \ +%:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5)\ } -lgcc " +#define DARWIN_WEAK_CRTS \ +"%{static-libgcc|static: \ + %:version-compare(>= 10.6 mmacosx-version-min= -lemutls_w) ; \ + shared-libgcc|fexceptions|fobjc-exceptions|fgnu-runtime: \ + %:version-compare(>= 10.11 mmacosx-version-min= -lemutls_w) ; \ + : -lemutls_w \ + }" + /* We specify crt0.o as -lcrt0.o so that ld will search the library path. */ #undef STARTFILE_SPEC
[gcc r11-11390] testsuite, Objective-C: Fix duplicate libobjc cases.
https://gcc.gnu.org/g:e07bed1e7f67aebc288e8e220402b6d628d4b443 commit r11-11390-ge07bed1e7f67aebc288e8e220402b6d628d4b443 Author: Iain Sandoe Date: Thu Jan 25 20:17:42 2024 + testsuite, Objective-C: Fix duplicate libobjc cases. Two of the encode testcases include '-lobjc' as their dg-options. Since the library is already appended as part of the generic testsuite handling, this means that two instances appear on the link line leading to spurious warnings from Darwin's new linker. gcc/testsuite/ChangeLog: * obj-c++.dg/encode-10.mm: Remove unneeded '-lobjc' option addition. * obj-c++.dg/encode-9.mm: Likewise. Signed-off-by: Iain Sandoe (cherry picked from commit 30d9e81c19d69e15b2e9c53e4377879cbf9b0b84) Diff: --- gcc/testsuite/obj-c++.dg/encode-10.mm | 1 - gcc/testsuite/obj-c++.dg/encode-9.mm | 1 - 2 files changed, 2 deletions(-) diff --git a/gcc/testsuite/obj-c++.dg/encode-10.mm b/gcc/testsuite/obj-c++.dg/encode-10.mm index 2b3af88dcb1..2477400b7f3 100644 --- a/gcc/testsuite/obj-c++.dg/encode-10.mm +++ b/gcc/testsuite/obj-c++.dg/encode-10.mm @@ -1,5 +1,4 @@ /* Test for @encode in templates. */ -/* { dg-options "-lobjc" } */ /* { dg-do run } */ #include #include diff --git a/gcc/testsuite/obj-c++.dg/encode-9.mm b/gcc/testsuite/obj-c++.dg/encode-9.mm index 6b064dfdc09..4fdb5fa50fb 100644 --- a/gcc/testsuite/obj-c++.dg/encode-9.mm +++ b/gcc/testsuite/obj-c++.dg/encode-9.mm @@ -1,5 +1,4 @@ /* Test than @encode is properly instantiated. */ -/* { dg-options "-lobjc" } */ /* { dg-do run } */ #include
[gcc r11-11391] Testsuite: mark IPA test as requiring alias support
https://gcc.gnu.org/g:f80d7cf40f986bc6983008cd2fb24853a3b87ab1 commit r11-11391-gf80d7cf40f986bc6983008cd2fb24853a3b87ab1 Author: Francois-Xavier Coudert Date: Sun Aug 20 14:13:22 2023 +0200 Testsuite: mark IPA test as requiring alias support This was indicated in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85656 but never committed. Without it, the test fails on darwin. gcc/testsuite/ChangeLog: * gcc.dg/ipa/ipa-icf-38.c: Require alias support. (cherry picked from commit 02393e4b5eabe1c64720b022cb6f819e7b4dc08b) Diff: --- gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c b/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c index 452e1b88514..57c5262dd4a 100644 --- a/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c +++ b/gcc/testsuite/gcc.dg/ipa/ipa-icf-38.c @@ -1,4 +1,5 @@ /* { dg-do link } */ +/* { dg-require-alias "" } */ /* { dg-options "-O2 -fdump-ipa-icf-optimized -flto -fdump-tree-optimized" } */ /* { dg-require-effective-target lto } */ /* { dg-additional-sources "ipa-icf-38a.c" }*/
[gcc r11-11392] testsuite, asan: Avoid color in asan test output.
https://gcc.gnu.org/g:57596bb82e31d2dfdba2eb41c16e45a9bbeb38a7 commit r11-11392-g57596bb82e31d2dfdba2eb41c16e45a9bbeb38a7 Author: Iain Sandoe Date: Sun Jun 19 10:31:01 2022 +0100 testsuite, asan: Avoid color in asan test output. The presence of the color markers in the some of the asan tests appears to confuse the dg-output matching (possibly a platform TCL or termios bug) on some Darwin platforms. Since the color is not being tested, switch it off (makes the log files easier to read too). This fixes a large number of spurious test fails on AVX512 Darwin19. Signed-off-by: Iain Sandoe gcc/testsuite/ChangeLog: * lib/asan-dg.exp: Do not apply color to asan output when under test. (cherry picked from commit 607118dfa47a1865dc59f98e7d161da98471d688) Diff: --- gcc/testsuite/lib/asan-dg.exp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/testsuite/lib/asan-dg.exp b/gcc/testsuite/lib/asan-dg.exp index e926dc3ad03..954b0ae22d4 100644 --- a/gcc/testsuite/lib/asan-dg.exp +++ b/gcc/testsuite/lib/asan-dg.exp @@ -111,6 +111,8 @@ proc asan_init { args } { global asan_saved_TEST_ALWAYS_FLAGS global asan_saved_ALWAYS_CXXFLAGS +setenv ASAN_OPTIONS "color=never" + set link_flags "" if ![is_remote host] { if [info exists TOOL_OPTIONS] {
[gcc r11-11393] Testsuite: fix analyzer tests on Darwin
https://gcc.gnu.org/g:ee2f7a02371aba24f6db6231ae862cd2248bf45f commit r11-11393-gee2f7a02371aba24f6db6231ae862cd2248bf45f Author: Francois-Xavier Coudert Date: Sat Aug 19 23:22:06 2023 +0200 Testsuite: fix analyzer tests on Darwin On macOS, system headers redefine by default some macros (memcpy, memmove, etc) to checked versions, which defeats the analyzer. We want to turn this off. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042 gcc/testsuite/ChangeLog: PR analyzer/104042 * gcc.dg/analyzer/analyzer.exp: Pass -D_FORTIFY_SOURCE=0 on Darwin. (cherry picked from commit ce33bbfcbc7dd3afc6c96fb48a19ed00f0c598ce) Diff: --- gcc/testsuite/gcc.dg/analyzer/analyzer.exp | 8 1 file changed, 8 insertions(+) diff --git a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp index e4b198bee87..7a2f7e906e9 100644 --- a/gcc/testsuite/gcc.dg/analyzer/analyzer.exp +++ b/gcc/testsuite/gcc.dg/analyzer/analyzer.exp @@ -32,6 +32,14 @@ if [info exists DEFAULT_CFLAGS] then { # If a testcase doesn't have special options, use these. set DEFAULT_CFLAGS "-fanalyzer -Wanalyzer-too-complex -fanalyzer-call-summaries" +if { [istarget "*-*-darwin*" ] } { + # On macOS, system headers redefine by default some macros (memcpy, + # memmove, etc) to checked versions, which defeats the analyzer. We + # want to turn this off. + # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104042 + set DEFAULT_CFLAGS "$DEFAULT_CFLAGS -D_FORTIFY_SOURCE=0" +} + # Initialize `dg'. dg-init
[gcc r11-11394] Testsuite, i386: Mark test as requiring ifunc
https://gcc.gnu.org/g:35b198ed957d089f095724e91165cf082e9be1bc commit r11-11394-g35b198ed957d089f095724e91165cf082e9be1bc Author: Francois-Xavier Coudert Date: Mon Oct 30 15:41:10 2023 +0100 Testsuite, i386: Mark test as requiring ifunc Test is currently failing on x86_64-apple-darwin. gcc/testsuite/ChangeLog: * gcc.target/i386/pr105554.c: Require ifunc. (cherry picked from commit 7666d94db0684f04264712f3e3fdb542518960c5) Diff: --- gcc/testsuite/gcc.target/i386/pr105554.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/testsuite/gcc.target/i386/pr105554.c b/gcc/testsuite/gcc.target/i386/pr105554.c index 08e90bb3368..e9ef494270a 100644 --- a/gcc/testsuite/gcc.target/i386/pr105554.c +++ b/gcc/testsuite/gcc.target/i386/pr105554.c @@ -1,5 +1,6 @@ /* PR target/105554 */ /* { dg-do compile } */ +/* { dg-require-ifunc "" } */ /* { dg-options "-O2 -Wno-psabi -mno-sse3" } */ typedef long long v4di __attribute__((__vector_size__(32)));
[gcc r15-25] libbacktrace: load Windows modules
https://gcc.gnu.org/g:942a9cf2a958113d2ab46f5b015c36e569abedcf commit r15-25-g942a9cf2a958113d2ab46f5b015c36e569abedcf Author: Ian Lance Taylor Date: Sun Apr 28 11:14:17 2024 -0700 libbacktrace: load Windows modules Patch from Björn Schäpers . * configure.ac: Checked for tlhelp32.h * pecoff.c: Include if available. (backtrace_initialize): Use tlhelp32 api for a snapshot to detect loaded modules. (coff_add): New argument for the module handle of the file, to get the base address. * configure, config.h.in: Regenerate. Diff: --- libbacktrace/config.h.in | 3 ++ libbacktrace/configure| 15 ++ libbacktrace/configure.ac | 4 +++ libbacktrace/pecoff.c | 73 +-- 4 files changed, 87 insertions(+), 8 deletions(-) diff --git a/libbacktrace/config.h.in b/libbacktrace/config.h.in index ee2616335c7..9b8ab88ab63 100644 --- a/libbacktrace/config.h.in +++ b/libbacktrace/config.h.in @@ -101,6 +101,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_SYS_TYPES_H +/* Define to 1 if you have the header file. */ +#undef HAVE_TLHELP32_H + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H diff --git a/libbacktrace/configure b/libbacktrace/configure index d6d6606a72c..ab94a85f45c 100755 --- a/libbacktrace/configure +++ b/libbacktrace/configure @@ -13523,6 +13523,21 @@ fi done +for ac_header in tlhelp32.h +do : + ac_fn_c_check_header_compile "$LINENO" "tlhelp32.h" "ac_cv_header_tlhelp32_h" "#ifdef HAVE_WINDOWS_H +# include +#endif +" +if test "x$ac_cv_header_tlhelp32_h" = xyes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_TLHELP32_H 1 +_ACEOF + +fi + +done + # Check for the fcntl function. if test -n "${with_target_subdir}"; then diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index 3e0075a2b79..59e9c415db8 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -380,6 +380,10 @@ if test "$have_loadquery" = "yes"; then fi AC_CHECK_HEADERS(windows.h) +AC_CHECK_HEADERS(tlhelp32.h, [], [], +[#ifdef HAVE_WINDOWS_H +# include +#endif]) # Check for the fcntl function. if test -n "${with_target_subdir}"; then diff --git a/libbacktrace/pecoff.c b/libbacktrace/pecoff.c index 9e437d810c7..4f267841178 100644 --- a/libbacktrace/pecoff.c +++ b/libbacktrace/pecoff.c @@ -49,6 +49,18 @@ POSSIBILITY OF SUCH DAMAGE. */ #endif #include + +#ifdef HAVE_TLHELP32_H +#include + +#ifdef UNICODE +/* If UNICODE is defined, all the symbols are replaced by a macro to use the + wide variant. But we need the ansi variant, so undef the macros. */ +#undef MODULEENTRY32 +#undef Module32First +#undef Module32Next +#endif +#endif #endif /* Coff file header. */ @@ -592,7 +604,8 @@ coff_syminfo (struct backtrace_state *state, uintptr_t addr, static int coff_add (struct backtrace_state *state, int descriptor, backtrace_error_callback error_callback, void *data, - fileline *fileline_fn, int *found_sym, int *found_dwarf) + fileline *fileline_fn, int *found_sym, int *found_dwarf, + uintptr_t module_handle ATTRIBUTE_UNUSED) { struct backtrace_view fhdr_view; off_t fhdr_off; @@ -870,12 +883,7 @@ coff_add (struct backtrace_state *state, int descriptor, } #ifdef HAVE_WINDOWS_H - { -uintptr_t module_handle; - -module_handle = (uintptr_t) GetModuleHandle (NULL); -base_address = module_handle - image_base; - } + base_address = module_handle - image_base; #endif if (!backtrace_dwarf_add (state, base_address, &dwarf_sections, @@ -917,12 +925,61 @@ backtrace_initialize (struct backtrace_state *state, int found_sym; int found_dwarf; fileline coff_fileline_fn; + uintptr_t module_handle = 0; +#ifdef HAVE_TLHELP32_H + fileline module_fileline_fn; + int module_found_sym; + HANDLE snapshot; +#endif + +#ifdef HAVE_WINDOWS_H + module_handle = (uintptr_t) GetModuleHandle (NULL); +#endif ret = coff_add (state, descriptor, error_callback, data, - &coff_fileline_fn, &found_sym, &found_dwarf); + &coff_fileline_fn, &found_sym, &found_dwarf, module_handle); if (!ret) return 0; +#ifdef HAVE_TLHELP32_H + do +{ + snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0); +} + while (snapshot == INVALID_HANDLE_VALUE +&& GetLastError () == ERROR_BAD_LENGTH); + + if (snapshot != INVALID_HANDLE_VALUE) +{ + MODULEENTRY32 entry; + BOOL ok; + entry.dwSize = sizeof (MODULEENTRY32); + + for (ok = Module32First (snapshot, &entry); ok; ok = Module32Next (snapshot, &entry)) + { + if (strcmp (filename, entry.szExePath) == 0) + continue; + + module_handle = (uintptr_t) entry.hModule; + if (module_handle == 0) + continue; + + descriptor = backtrace_open (entry.szExePath, error_callback, data
[gcc r11-11395] Darwin: Correct a merge error.
https://gcc.gnu.org/g:b54b43396c9c716c43d58a60efafb21419d2fbb5 commit r11-11395-gb54b43396c9c716c43d58a60efafb21419d2fbb5 Author: Iain Sandoe Date: Sun Apr 28 17:05:06 2024 +0100 Darwin: Correct a merge error. For this branch the default_libc_has_function () is not available. Signed-off-by: Iain Sandoe gcc/ChangeLog: * config/darwin.c: Return true as the default libc avaiability. Diff: --- gcc/config/darwin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c index 6e887a9ba5a..a473ea79b1b 100644 --- a/gcc/config/darwin.c +++ b/gcc/config/darwin.c @@ -3603,7 +3603,7 @@ darwin_libc_has_function (enum function_class fn_class, || (darwin_macosx_version_min && strverscmp (darwin_macosx_version_min, "10.3") >= 0)); #endif - return default_libc_has_function (fn_class, type); + return true; } /* CFStrings implementation. */
[gcc r11-11396] Darwin, testsuite: -bind_at_load is deprecated
https://gcc.gnu.org/g:1ac65249cb9553bda683b3b1a2f85fccb2562bb8 commit r11-11396-g1ac65249cb9553bda683b3b1a2f85fccb2562bb8 Author: Francois-Xavier Coudert Date: Sat Feb 10 12:55:29 2024 +0100 Darwin, testsuite: -bind_at_load is deprecated gcc/testsuite/ChangeLog: * gcc.dg/darwin-ld-2.c: Ignore warning that -bind_at_load is deprecated. (cherry picked from commit f88219333e85a05a98468f67d2f2190fc330044e) Diff: --- gcc/testsuite/gcc.dg/darwin-ld-2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/testsuite/gcc.dg/darwin-ld-2.c b/gcc/testsuite/gcc.dg/darwin-ld-2.c index 5de19524f0b..2a6b491da5b 100644 --- a/gcc/testsuite/gcc.dg/darwin-ld-2.c +++ b/gcc/testsuite/gcc.dg/darwin-ld-2.c @@ -3,6 +3,7 @@ /* { dg-options "-bind_at_load" } */ /* { dg-do link { target *-*-darwin* } } */ +/* { dg-prune-output "-bind_at_load is deprecated" } */ int main() {
[gcc r11-11397] Darwin, testsuite: -multiply_defined is obsolete
https://gcc.gnu.org/g:f6c1f80fd9a9ba6f891514171d0236f366b373aa commit r11-11397-gf6c1f80fd9a9ba6f891514171d0236f366b373aa Author: Francois-Xavier Coudert Date: Sat Feb 10 15:52:44 2024 +0100 Darwin, testsuite: -multiply_defined is obsolete gcc/testsuite/ChangeLog: * gcc.dg/ssp-2.c: Ignore warning that -multiply_defined is obsolete (cherry picked from commit 6b13e32162adf9e4f552e09c46f1de531ffa8c05) Diff: --- gcc/testsuite/gcc.dg/ssp-2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/testsuite/gcc.dg/ssp-2.c b/gcc/testsuite/gcc.dg/ssp-2.c index 752fe5393f4..608ca300032 100644 --- a/gcc/testsuite/gcc.dg/ssp-2.c +++ b/gcc/testsuite/gcc.dg/ssp-2.c @@ -1,6 +1,7 @@ /* { dg-do run { target native } } */ /* { dg-options "-fstack-protector" } */ /* { dg-options "-fstack-protector -Wl,-multiply_defined,suppress" { target *-*-darwin* } } */ +/* { dg-prune-output "-multiply_defined is obsolete" } */ /* { dg-require-effective-target fstack_protector } */ #include
[gcc r15-26] Make vrange an abstract class.
https://gcc.gnu.org/g:21713edf52974d14238cdda865fc662eca58302a commit r15-26-g21713edf52974d14238cdda865fc662eca58302a Author: Aldy Hernandez Date: Wed Feb 21 20:37:14 2024 +0100 Make vrange an abstract class. Explicitly make vrange an abstract class. This involves fleshing out the unsupported_range overrides which we were inheriting by default from vrange. gcc/ChangeLog: * value-range.cc (unsupported_range::accept): Move down. (vrange::contains_p): Rename to... (unsupported_range::contains_p): ...this. (vrange::singleton_p): Rename to... (unsupported_range::singleton_p): ...this. (vrange::set): Rename to... (unsupported_range::set): ...this. (vrange::type): Rename to... (unsupported_range::type): ...this. (vrange::supports_type_p): Rename to... (unsupported_range::supports_type_p): ...this. (vrange::set_undefined): Rename to... (unsupported_range::set_undefined): ...this. (vrange::set_varying): Rename to... (unsupported_range::set_varying): ...this. (vrange::union_): Rename to... (unsupported_range::union_): ...this. (vrange::intersect): Rename to... (unsupported_range::intersect): ...this. (vrange::zero_p): Rename to... (unsupported_range::zero_p): ...this. (vrange::nonzero_p): Rename to... (unsupported_range::nonzero_p): ...this. (vrange::set_nonzero): Rename to... (unsupported_range::set_nonzero): ...this. (vrange::set_zero): Rename to... (unsupported_range::set_zero): ...this. (vrange::set_nonnegative): Rename to... (unsupported_range::set_nonnegative): ...this. (vrange::fits_p): Rename to... (unsupported_range::fits_p): ...this. (unsupported_range::operator=): New. (frange::fits_p): New. * value-range.h (class vrange): Make an abstract class. (class unsupported_range): Declare override methods. Diff: --- gcc/value-range.cc | 62 +++--- gcc/value-range.h | 53 -- 2 files changed, 73 insertions(+), 42 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 70375f7abf9..632d77305cc 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -37,12 +37,6 @@ irange::accept (const vrange_visitor &v) const v.visit (*this); } -void -unsupported_range::accept (const vrange_visitor &v) const -{ - v.visit (*this); -} - // Convenience function only available for integers and pointers. wide_int @@ -86,52 +80,58 @@ debug (const irange_bitmask &bm) fprintf (stderr, "\n"); } -// Default vrange definitions. +// Definitions for unsupported_range. + +void +unsupported_range::accept (const vrange_visitor &v) const +{ + v.visit (*this); +} bool -vrange::contains_p (tree) const +unsupported_range::contains_p (tree) const { return varying_p (); } bool -vrange::singleton_p (tree *) const +unsupported_range::singleton_p (tree *) const { return false; } void -vrange::set (tree min, tree, value_range_kind) +unsupported_range::set (tree min, tree, value_range_kind) { set_varying (TREE_TYPE (min)); } tree -vrange::type () const +unsupported_range::type () const { return void_type_node; } bool -vrange::supports_type_p (const_tree) const +unsupported_range::supports_type_p (const_tree) const { return false; } void -vrange::set_undefined () +unsupported_range::set_undefined () { m_kind = VR_UNDEFINED; } void -vrange::set_varying (tree) +unsupported_range::set_varying (tree) { m_kind = VR_VARYING; } bool -vrange::union_ (const vrange &r) +unsupported_range::union_ (const vrange &r) { if (r.undefined_p () || varying_p ()) return false; @@ -145,7 +145,7 @@ vrange::union_ (const vrange &r) } bool -vrange::intersect (const vrange &r) +unsupported_range::intersect (const vrange &r) { if (undefined_p () || r.varying_p ()) return false; @@ -164,41 +164,53 @@ vrange::intersect (const vrange &r) } bool -vrange::zero_p () const +unsupported_range::zero_p () const { return false; } bool -vrange::nonzero_p () const +unsupported_range::nonzero_p () const { return false; } void -vrange::set_nonzero (tree type) +unsupported_range::set_nonzero (tree type) { set_varying (type); } void -vrange::set_zero (tree type) +unsupported_range::set_zero (tree type) { set_varying (type); } void -vrange::set_nonnegative (tree type) +unsupported_range::set_nonnegative (tree type) { set_varying (type); } bool -vrange::fits_p (const vrange &) const +unsupported_range::fits_p (const vrange &) const { return true; } +unsupported_range & +unsupported_range::
[gcc r15-27] Add a virtual vrange destructor.
https://gcc.gnu.org/g:a78dfb0fc83606e9b83b76575deb7e43300254fa commit r15-27-ga78dfb0fc83606e9b83b76575deb7e43300254fa Author: Aldy Hernandez Date: Wed Feb 21 09:33:19 2024 +0100 Add a virtual vrange destructor. Richi mentioned in PR113476 that it would be cleaner to move the destructor from int_range to the base class. Although this isn't strictly necessary, as there are no users, it is good to future proof things, and the overall impact is miniscule. gcc/ChangeLog: * value-range.h (vrange::~vrange): New. (int_range::~int_range): Make final override. Diff: --- gcc/value-range.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gcc/value-range.h b/gcc/value-range.h index e7f61950a24..b7c83982385 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -95,6 +95,7 @@ public: virtual void set_zero (tree type) = 0; virtual void set_nonnegative (tree type) = 0; virtual bool fits_p (const vrange &r) const = 0; + virtual ~vrange () { } bool varying_p () const; bool undefined_p () const; @@ -382,7 +383,7 @@ public: int_range (tree type); int_range (const int_range &); int_range (const irange &); - virtual ~int_range (); + ~int_range () final override; int_range& operator= (const int_range &); protected: int_range (tree, tree, value_range_kind = VR_RANGE);
[gcc r15-28] Make some Value_Range's explicitly integer.
https://gcc.gnu.org/g:a46564e4876c9a863d9897d72963cc4f03689adc commit r15-28-ga46564e4876c9a863d9897d72963cc4f03689adc Author: Aldy Hernandez Date: Mon Apr 22 13:29:39 2024 +0200 Make some Value_Range's explicitly integer. Fix some Value_Range's that we know ahead of time will be only integers. This avoids using the polymorphic Value_Range unnecessarily gcc/ChangeLog: * gimple-ssa-warn-access.cc (check_nul_terminated_array): Make Value_Range an int_range. (memmodel_to_uhwi): Same * tree-ssa-loop-niter.cc (refine_value_range_using_guard): Same. (determine_value_range): Same. (infer_loop_bounds_from_signedness): Same. (scev_var_range_cant_overflow): Same. Diff: --- gcc/gimple-ssa-warn-access.cc | 4 ++-- gcc/tree-ssa-loop-niter.cc| 12 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc index dedaae27b31..450c1caa765 100644 --- a/gcc/gimple-ssa-warn-access.cc +++ b/gcc/gimple-ssa-warn-access.cc @@ -330,7 +330,7 @@ check_nul_terminated_array (GimpleOrTree expr, tree src, tree bound) wide_int bndrng[2]; if (bound) { - Value_Range r (TREE_TYPE (bound)); + int_range<2> r (TREE_TYPE (bound)); get_range_query (cfun)->range_of_expr (r, bound); @@ -2816,7 +2816,7 @@ memmodel_to_uhwi (tree ord, gimple *stmt, unsigned HOST_WIDE_INT *cstval) { /* Use the range query to determine constant values in the absence of constant propagation (such as at -O0). */ - Value_Range rng (TREE_TYPE (ord)); + int_range<2> rng (TREE_TYPE (ord)); if (!get_range_query (cfun)->range_of_expr (rng, ord, stmt) || !rng.singleton_p (&ord)) return false; diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index c6d010f6d89..cbc9dbc5a1f 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -214,7 +214,7 @@ refine_value_range_using_guard (tree type, tree var, get_type_static_bounds (type, mint, maxt); mpz_init (minc1); mpz_init (maxc1); - Value_Range r (TREE_TYPE (varc1)); + int_range<2> r (TREE_TYPE (varc1)); /* Setup range information for varc1. */ if (integer_zerop (varc1)) { @@ -368,7 +368,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off, gphi_iterator gsi; /* Either for VAR itself... */ - Value_Range var_range (TREE_TYPE (var)); + int_range<2> var_range (TREE_TYPE (var)); get_range_query (cfun)->range_of_expr (var_range, var); if (var_range.varying_p () || var_range.undefined_p ()) rtype = VR_VARYING; @@ -382,7 +382,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off, /* Or for PHI results in loop->header where VAR is used as PHI argument from the loop preheader edge. */ - Value_Range phi_range (TREE_TYPE (var)); + int_range<2> phi_range (TREE_TYPE (var)); for (gsi = gsi_start_phis (loop->header); !gsi_end_p (gsi); gsi_next (&gsi)) { gphi *phi = gsi.phi (); @@ -408,7 +408,7 @@ determine_value_range (class loop *loop, tree type, tree var, mpz_t off, involved. */ if (wi::gt_p (minv, maxv, sgn)) { - Value_Range vr (TREE_TYPE (var)); + int_range<2> vr (TREE_TYPE (var)); get_range_query (cfun)->range_of_expr (vr, var); if (vr.varying_p () || vr.undefined_p ()) rtype = VR_VARYING; @@ -4367,7 +4367,7 @@ infer_loop_bounds_from_signedness (class loop *loop, gimple *stmt) low = lower_bound_in_type (type, type); high = upper_bound_in_type (type, type); - Value_Range r (TREE_TYPE (def)); + int_range<2> r (TREE_TYPE (def)); get_range_query (cfun)->range_of_expr (r, def); if (!r.varying_p () && !r.undefined_p ()) { @@ -5426,7 +5426,7 @@ scev_var_range_cant_overflow (tree var, tree step, class loop *loop) if (!def_bb || !dominated_by_p (CDI_DOMINATORS, loop->latch, def_bb)) return false; - Value_Range r (TREE_TYPE (var)); + int_range<2> r (TREE_TYPE (var)); get_range_query (cfun)->range_of_expr (r, var); if (r.varying_p () || r.undefined_p ()) return false;
[gcc r15-30] Move bitmask routines to vrange base class.
https://gcc.gnu.org/g:fd4cf7a092bb2ce21c0d8246c17c0b7f82de440c commit r15-30-gfd4cf7a092bb2ce21c0d8246c17c0b7f82de440c Author: Aldy Hernandez Date: Thu Feb 22 09:18:46 2024 +0100 Move bitmask routines to vrange base class. Any range can theoretically have a bitmask of set bits. This patch moves the bitmask accessors to the base class. This cleans up some users in IPA*, and will provide a cleaner interface when prange is in place. gcc/ChangeLog: * ipa-cp.cc (propagate_bits_across_jump_function): Access bitmask through base class. (ipcp_store_vr_results): Same. * ipa-prop.cc (ipa_compute_jump_functions_for_edge): Same. (ipcp_get_parm_bits): Same. (ipcp_update_vr): Same. * range-op-mixed.h (update_known_bitmask): Change argument to vrange. * range-op.cc (update_known_bitmask): Same. * value-range.cc (vrange::update_bitmask): New. (irange::set_nonzero_bits): Move to vrange class. (irange::get_nonzero_bits): Same. * value-range.h (class vrange): Add update_bitmask, get_bitmask, get_nonzero_bits, and set_nonzero_bits. (class irange): Make bitmask methods virtual overrides. (class Value_Range): Add get_bitmask and update_bitmask. Diff: --- gcc/ipa-cp.cc| 9 +++-- gcc/ipa-prop.cc | 10 -- gcc/range-op-mixed.h | 2 +- gcc/range-op.cc | 4 ++-- gcc/value-range.cc | 16 ++-- gcc/value-range.h| 14 +- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc index b7add455bd5..a688dced5c9 100644 --- a/gcc/ipa-cp.cc +++ b/gcc/ipa-cp.cc @@ -2485,8 +2485,7 @@ propagate_bits_across_jump_function (cgraph_edge *cs, int idx, jfunc->m_vr->get_vrange (vr); if (!vr.undefined_p () && !vr.varying_p ()) { - irange &r = as_a (vr); - irange_bitmask bm = r.get_bitmask (); + irange_bitmask bm = vr.get_bitmask (); widest_int mask = widest_int::from (bm.mask (), TYPE_SIGN (parm_type)); widest_int value @@ -6346,14 +6345,13 @@ ipcp_store_vr_results (void) { Value_Range tmp = plats->m_value_range.m_vr; tree type = ipa_get_type (info, i); - irange &r = as_a (tmp); irange_bitmask bm (wide_int::from (bits->get_value (), TYPE_PRECISION (type), TYPE_SIGN (type)), wide_int::from (bits->get_mask (), TYPE_PRECISION (type), TYPE_SIGN (type))); - r.update_bitmask (bm); + tmp.update_bitmask (bm); ipa_vr vr (tmp); ts->m_vr->quick_push (vr); } @@ -6368,14 +6366,13 @@ ipcp_store_vr_results (void) tree type = ipa_get_type (info, i); Value_Range tmp; tmp.set_varying (type); - irange &r = as_a (tmp); irange_bitmask bm (wide_int::from (bits->get_value (), TYPE_PRECISION (type), TYPE_SIGN (type)), wide_int::from (bits->get_mask (), TYPE_PRECISION (type), TYPE_SIGN (type))); - r.update_bitmask (bm); + tmp.update_bitmask (bm); ipa_vr vr (tmp); ts->m_vr->quick_push (vr); } diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index 374e998aa64..b57f9750431 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2381,8 +2381,7 @@ ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi, irange_bitmask bm (value, mask); if (!addr_nonzero) vr.set_varying (TREE_TYPE (arg)); - irange &r = as_a (vr); - r.update_bitmask (bm); + vr.update_bitmask (bm); ipa_set_jfunc_vr (jfunc, vr); } else if (addr_nonzero) @@ -5785,8 +5784,8 @@ ipcp_get_parm_bits (tree parm, tree *value, widest_int *mask) vr[i].get_vrange (tmp); if (tmp.undefined_p () || tmp.varying_p ()) return false; - irange &r = as_a (tmp); - irange_bitmask bm = r.get_bitmask (); + irange_bitmask bm; + bm = tmp.get_bitmask (); *mask = widest_int::from (bm.mask (), TYPE_SIGN (TREE_TYPE (parm))); *value = wide_int_to_tree (TREE_TYPE (parm), bm.value ()); return true; @@ -5857,8 +5856,7 @@ ipcp_update_vr (struct cgraph_node *node, ipcp_transformation *ts) if (POINTER_TYPE_P (TREE_TYPE (parm)
[gcc r15-29] Add tree versions of lower and upper bounds to vrange.
https://gcc.gnu.org/g:ba1a8e8eed963c0253c6e5550c8bccc264c5d469 commit r15-29-gba1a8e8eed963c0253c6e5550c8bccc264c5d469 Author: Aldy Hernandez Date: Mon Apr 22 13:34:48 2024 +0200 Add tree versions of lower and upper bounds to vrange. This patch adds vrange::lbound() and vrange::ubound() that return trees. These can be used in generic code that is type agnostic, and avoids special casing for pointers and integers in places where we handle both. It also cleans up a wart in the Value_Range class. gcc/ChangeLog: * tree-ssa-loop-niter.cc (refine_value_range_using_guard): Convert bound to wide_int. * value-range.cc (Value_Range::lower_bound): Remove. (Value_Range::upper_bound): Remove. (unsupported_range::lbound): New. (unsupported_range::ubound): New. (frange::lbound): New. (frange::ubound): New. (irange::lbound): New. (irange::ubound): New. * value-range.h (class vrange): Add lbound() and ubound(). (class irange): Same. (class frange): Same. (class unsupported_range): Same. (class Value_Range): Rename lower_bound and upper_bound to lbound and ubound respectively. Diff: --- gcc/tree-ssa-loop-niter.cc | 4 ++-- gcc/value-range.cc | 56 +- gcc/value-range.h | 13 --- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc index cbc9dbc5a1f..adbc1936982 100644 --- a/gcc/tree-ssa-loop-niter.cc +++ b/gcc/tree-ssa-loop-niter.cc @@ -4067,7 +4067,7 @@ record_nonwrapping_iv (class loop *loop, tree base, tree step, gimple *stmt, Value_Range base_range (TREE_TYPE (orig_base)); if (get_range_query (cfun)->range_of_expr (base_range, orig_base) && !base_range.undefined_p ()) - max = base_range.upper_bound (); + max = wi::to_wide (base_range.ubound ()); extreme = fold_convert (unsigned_type, low); if (TREE_CODE (orig_base) == SSA_NAME && TREE_CODE (high) == INTEGER_CST @@ -4090,7 +4090,7 @@ record_nonwrapping_iv (class loop *loop, tree base, tree step, gimple *stmt, Value_Range base_range (TREE_TYPE (orig_base)); if (get_range_query (cfun)->range_of_expr (base_range, orig_base) && !base_range.undefined_p ()) - min = base_range.lower_bound (); + min = wi::to_wide (base_range.lbound ()); extreme = fold_convert (unsigned_type, high); if (TREE_CODE (orig_base) == SSA_NAME && TREE_CODE (low) == INTEGER_CST diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 632d77305cc..ccac517d4c4 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -37,26 +37,6 @@ irange::accept (const vrange_visitor &v) const v.visit (*this); } -// Convenience function only available for integers and pointers. - -wide_int -Value_Range::lower_bound () const -{ - if (is_a (*m_vrange)) -return as_a (*m_vrange).lower_bound (); - gcc_unreachable (); -} - -// Convenience function only available for integers and pointers. - -wide_int -Value_Range::upper_bound () const -{ - if (is_a (*m_vrange)) -return as_a (*m_vrange).upper_bound (); - gcc_unreachable (); -} - void Value_Range::dump (FILE *out) const { @@ -211,6 +191,18 @@ unsupported_range::operator= (const vrange &r) return *this; } +tree +unsupported_range::lbound () const +{ + return NULL; +} + +tree +unsupported_range::ubound () const +{ + return NULL; +} + // Assignment operator for generic ranges. Copying incompatible types // is not allowed. @@ -957,6 +949,18 @@ frange::set_nonnegative (tree type) set (type, dconst0, frange_val_max (type)); } +tree +frange::lbound () const +{ + return build_real (type (), lower_bound ()); +} + +tree +frange::ubound () const +{ + return build_real (type (), upper_bound ()); +} + // Here we copy between any two irange's. irange & @@ -2086,6 +2090,18 @@ irange::union_bitmask (const irange &r) return true; } +tree +irange::lbound () const +{ + return wide_int_to_tree (type (), lower_bound ()); +} + +tree +irange::ubound () const +{ + return wide_int_to_tree (type (), upper_bound ()); +} + void irange_bitmask::verify_mask () const { diff --git a/gcc/value-range.h b/gcc/value-range.h index b7c83982385..f216f1b82c1 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -96,6 +96,8 @@ public: virtual void set_nonnegative (tree type) = 0; virtual bool fits_p (const vrange &r) const = 0; virtual ~vrange () { } + virtual tree lbound () const = 0; + virtual tree ubound () const = 0; bool varying_p () const; bool undefined_p () const; @@ -298,6 +300,8 @@ public: wide_int lower_bound (unsigned = 0) const; wide_int upper_bound (unsigned) const; wide_int upper_bound () const; + virtual tree lbound (
[gcc r15-31] Remove GTY support for vrange and derived classes.
https://gcc.gnu.org/g:eeef1f69c5e77ecf13fdcf44df5bcf592a9993e6 commit r15-31-geeef1f69c5e77ecf13fdcf44df5bcf592a9993e6 Author: Aldy Hernandez Date: Wed Feb 21 09:34:29 2024 +0100 Remove GTY support for vrange and derived classes. Now that we have a vrange storage class to save ranges in long-term memory, there is no need for GTY markers for any of the vrange classes, since they should never live in GC. gcc/ChangeLog: * value-range-storage.h: Remove friends. * value-range.cc (gt_ggc_mx): Remove. (gt_pch_nx): Remove. * value-range.h (class vrange): Remove GTY markers. (class irange): Same. (class int_range): Same. (class frange): Same. (gt_ggc_mx): Remove. (gt_pch_nx): Remove. Diff: --- gcc/value-range-storage.h | 4 --- gcc/value-range.cc| 73 --- gcc/value-range.h | 46 +++-- 3 files changed, 4 insertions(+), 119 deletions(-) diff --git a/gcc/value-range-storage.h b/gcc/value-range-storage.h index d94c520aa73..5756de7e32d 100644 --- a/gcc/value-range-storage.h +++ b/gcc/value-range-storage.h @@ -75,10 +75,6 @@ private: static size_t size (const irange &r); const unsigned short *lengths_address () const; unsigned short *write_lengths_address (); - friend void gt_ggc_mx_irange_storage (void *); - friend void gt_pch_p_14irange_storage (void *, void *, - gt_pointer_operator, void *); - friend void gt_pch_nx_irange_storage (void *); // The shared precision of each number. unsigned short m_precision; diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 926f7b707ea..b901c864a7b 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -2165,79 +2165,6 @@ vrp_operand_equal_p (const_tree val1, const_tree val2) return true; } -void -gt_ggc_mx (irange *x) -{ - if (!x->undefined_p ()) -gt_ggc_mx (x->m_type); -} - -void -gt_pch_nx (irange *x) -{ - if (!x->undefined_p ()) -gt_pch_nx (x->m_type); -} - -void -gt_pch_nx (irange *x, gt_pointer_operator op, void *cookie) -{ - for (unsigned i = 0; i < x->m_num_ranges; ++i) -{ - op (&x->m_base[i * 2], NULL, cookie); - op (&x->m_base[i * 2 + 1], NULL, cookie); -} -} - -void -gt_ggc_mx (frange *x) -{ - gt_ggc_mx (x->m_type); -} - -void -gt_pch_nx (frange *x) -{ - gt_pch_nx (x->m_type); -} - -void -gt_pch_nx (frange *x, gt_pointer_operator op, void *cookie) -{ - op (&x->m_type, NULL, cookie); -} - -void -gt_ggc_mx (vrange *x) -{ - if (is_a (*x)) -return gt_ggc_mx ((irange *) x); - if (is_a (*x)) -return gt_ggc_mx ((frange *) x); - gcc_unreachable (); -} - -void -gt_pch_nx (vrange *x) -{ - if (is_a (*x)) -return gt_pch_nx ((irange *) x); - if (is_a (*x)) -return gt_pch_nx ((frange *) x); - gcc_unreachable (); -} - -void -gt_pch_nx (vrange *x, gt_pointer_operator op, void *cookie) -{ - if (is_a (*x)) -gt_pch_nx ((irange *) x, op, cookie); - else if (is_a (*x)) -gt_pch_nx ((frange *) x, op, cookie); - else -gcc_unreachable (); -} - #define DEFINE_INT_RANGE_INSTANCE(N) \ template int_range::int_range(tree_node *, \ const wide_int &,\ diff --git a/gcc/value-range.h b/gcc/value-range.h index 991ffeafcb8..2650ded6d10 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -72,7 +72,7 @@ enum value_range_discriminator // if (f.supports_type_p (type)) ... //} -class GTY((user)) vrange +class vrange { template friend bool is_a (vrange &); friend class Value_Range; @@ -279,7 +279,7 @@ irange_bitmask::intersect (const irange_bitmask &orig_src) // An integer range without any storage. -class GTY((user)) irange : public vrange +class irange : public vrange { friend value_range_kind get_legacy_range (const irange &, tree &, tree &); friend class irange_storage; @@ -350,10 +350,6 @@ protected: // Hard limit on max ranges allowed. static const int HARD_MAX_RANGES = 255; private: - friend void gt_ggc_mx (irange *); - friend void gt_pch_nx (irange *); - friend void gt_pch_nx (irange *, gt_pointer_operator, void *); - bool varying_compatible_p () const; bool intersect_bitmask (const irange &r); bool union_bitmask (const irange &r); @@ -379,7 +375,7 @@ protected: // HARD_MAX_RANGES. This new storage is freed upon destruction. template -class GTY((user)) int_range : public irange +class int_range : public irange { public: int_range (); @@ -484,13 +480,10 @@ nan_state::neg_p () const // The representation is a type with a couple of endpoints, unioned // with the set of { -NAN, +Nan }. -class GTY((user)) frange : public vrange +class frange : public vrange { friend class frange_storage; friend class vrange_printer; - friend v
[gcc r15-32] Make fold_cond_with_ops use a boolean type for range_true/range_false.
https://gcc.gnu.org/g:039e88b1aea5723221e8b0b926c35afb2f96a8a9 commit r15-32-g039e88b1aea5723221e8b0b926c35afb2f96a8a9 Author: Aldy Hernandez Date: Wed Feb 7 11:27:29 2024 +0100 Make fold_cond_with_ops use a boolean type for range_true/range_false. Conditional operators are always boolean, regardless of their operands. Getting the type wrong is not currently a problem, but will be when prange's can no longer store an integer. gcc/ChangeLog: * vr-values.cc (simplify_using_ranges::fold_cond_with_ops): Remove type from range_true and range_false. Diff: --- gcc/vr-values.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index a7e291a16e5..ff68d40c355 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -320,9 +320,9 @@ simplify_using_ranges::fold_cond_with_ops (enum tree_code code, range_op_handler handler (code); if (handler && handler.fold_range (res, type, r0, r1)) { - if (res == range_true (type)) + if (res == range_true ()) return boolean_true_node; - if (res == range_false (type)) + if (res == range_false ()) return boolean_false_node; } return NULL;
[gcc r15-33] Change range_includes_zero_p argument to a reference.
https://gcc.gnu.org/g:d883fc7d00ed6bf5ee151de4fd3e05431582bd5f commit r15-33-gd883fc7d00ed6bf5ee151de4fd3e05431582bd5f Author: Aldy Hernandez Date: Tue Mar 19 16:33:47 2024 +0100 Change range_includes_zero_p argument to a reference. Make range_includes_zero_p take an argument instead of a pointer for consistency in the range-op code. gcc/ChangeLog: * gimple-range-op.cc (cfn_clz::fold_range): Change range_includes_zero_p argument to a reference. (cfn_ctz::fold_range): Same. * range-op.cc (operator_plus::lhs_op1_relation): Same. * value-range.h (range_includes_zero_p): Same. Diff: --- gcc/gimple-range-op.cc | 6 +++--- gcc/range-op.cc| 2 +- gcc/value-range.h | 10 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc index a98f7db62a7..9c50c00549e 100644 --- a/gcc/gimple-range-op.cc +++ b/gcc/gimple-range-op.cc @@ -853,7 +853,7 @@ public: // __builtin_ffs* and __builtin_popcount* return [0, prec]. int prec = TYPE_PRECISION (lh.type ()); // If arg is non-zero, then ffs or popcount are non-zero. -int mini = range_includes_zero_p (&lh) ? 0 : 1; +int mini = range_includes_zero_p (lh) ? 0 : 1; int maxi = prec; // If some high bits are known to be zero, decrease the maximum. @@ -945,7 +945,7 @@ cfn_clz::fold_range (irange &r, tree type, const irange &lh, if (mini == -2) mini = 0; } - else if (!range_includes_zero_p (&lh)) + else if (!range_includes_zero_p (lh)) { mini = 0; maxi = prec - 1; @@ -1007,7 +1007,7 @@ cfn_ctz::fold_range (irange &r, tree type, const irange &lh, mini = -2; } // If arg is non-zero, then use [0, prec - 1]. - if (!range_includes_zero_p (&lh)) + if (!range_includes_zero_p (lh)) { mini = 0; maxi = prec - 1; diff --git a/gcc/range-op.cc b/gcc/range-op.cc index aeff55cfd78..6ea7d624a9b 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1657,7 +1657,7 @@ operator_plus::lhs_op1_relation (const irange &lhs, } // If op2 does not contain 0, then LHS and OP1 can never be equal. - if (!range_includes_zero_p (&op2)) + if (!range_includes_zero_p (op2)) return VREL_NE; return VREL_VARYING; diff --git a/gcc/value-range.h b/gcc/value-range.h index 2650ded6d10..62f123e2a4b 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -972,16 +972,16 @@ irange::contains_p (tree cst) const } inline bool -range_includes_zero_p (const irange *vr) +range_includes_zero_p (const irange &vr) { - if (vr->undefined_p ()) + if (vr.undefined_p ()) return false; - if (vr->varying_p ()) + if (vr.varying_p ()) return true; - wide_int zero = wi::zero (TYPE_PRECISION (vr->type ())); - return vr->contains_p (zero); + wide_int zero = wi::zero (TYPE_PRECISION (vr.type ())); + return vr.contains_p (zero); } // Constructors for irange
[gcc r15-35] Accept a vrange in get_legacy_range.
https://gcc.gnu.org/g:9a2f0d152d98dd55efc9accd07ea507b929c3516 commit r15-35-g9a2f0d152d98dd55efc9accd07ea507b929c3516 Author: Aldy Hernandez Date: Tue Mar 19 17:17:53 2024 +0100 Accept a vrange in get_legacy_range. In preparation for prange, make get_legacy_range take a generic vrange, not just an irange. gcc/ChangeLog: * value-range.cc (get_legacy_range): Make static and add another version of get_legacy_range that takes a vrange. * value-range.h (class irange): Remove unnecessary friendship with get_legacy_range. (get_legacy_range): Accept a vrange. Diff: --- gcc/value-range.cc | 17 - gcc/value-range.h | 3 +-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index b901c864a7b..44929b210aa 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -1004,7 +1004,7 @@ irange::operator= (const irange &src) return *this; } -value_range_kind +static value_range_kind get_legacy_range (const irange &r, tree &min, tree &max) { if (r.undefined_p ()) @@ -1041,6 +1041,21 @@ get_legacy_range (const irange &r, tree &min, tree &max) return VR_RANGE; } +// Given a range in V, return an old-style legacy range consisting of +// a value_range_kind with a MIN/MAX. This is to maintain +// compatibility with passes that still depend on VR_ANTI_RANGE, and +// only works for integers and pointers. + +value_range_kind +get_legacy_range (const vrange &v, tree &min, tree &max) +{ + if (is_a (v)) +return get_legacy_range (as_a (v), min, max); + + gcc_unreachable (); + return VR_UNDEFINED; +} + /* Set value range to the canonical form of {VRTYPE, MIN, MAX, EQUIV}. This means adjusting VRTYPE, MIN and MAX representing the case of a wrapping range with MAX < MIN covering [MIN, type_max] U [type_min, MAX] diff --git a/gcc/value-range.h b/gcc/value-range.h index 62f123e2a4b..d2e8fd5a4d9 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -281,7 +281,6 @@ irange_bitmask::intersect (const irange_bitmask &orig_src) class irange : public vrange { - friend value_range_kind get_legacy_range (const irange &, tree &, tree &); friend class irange_storage; friend class vrange_printer; public: @@ -886,7 +885,7 @@ Value_Range::supports_type_p (const_tree type) return irange::supports_p (type) || frange::supports_p (type); } -extern value_range_kind get_legacy_range (const irange &, tree &min, tree &max); +extern value_range_kind get_legacy_range (const vrange &, tree &min, tree &max); extern void dump_value_range (FILE *, const vrange *); extern bool vrp_operand_equal_p (const_tree, const_tree); inline REAL_VALUE_TYPE frange_val_min (const_tree type);
[gcc r15-34] Verify that reading back from vrange_storage doesn't drop bits.
https://gcc.gnu.org/g:92f74ee21218cab08d7bb7769004a65e8a291fa3 commit r15-34-g92f74ee21218cab08d7bb7769004a65e8a291fa3 Author: Aldy Hernandez Date: Tue Mar 19 16:35:41 2024 +0100 Verify that reading back from vrange_storage doesn't drop bits. We have a sanity check in the irange storage code to make sure that reading back a cache entry we have just written to yields exactly the same range. There's no need to do this only for integers. This patch moves the code to a more generic place. However, doing so tickles a latent bug in the frange code where a range is being pessimized from [0.0, 1.0] to [-0.0, 1.0]. Exclude checking frange's until this bug is fixed. gcc/ChangeLog: * value-range-storage.cc (irange_storage::set_irange): Move verification code from here... (vrange_storage::set_vrange): ...to here. Diff: --- gcc/value-range-storage.cc | 20 +--- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/gcc/value-range-storage.cc b/gcc/value-range-storage.cc index f00474ad0e6..09a29776a0e 100644 --- a/gcc/value-range-storage.cc +++ b/gcc/value-range-storage.cc @@ -165,6 +165,19 @@ vrange_storage::set_vrange (const vrange &r) } else gcc_unreachable (); + + // Verify that reading back from the cache didn't drop bits. + if (flag_checking + // FIXME: Avoid checking frange, as it currently pessimizes some ranges: + // + // gfortran.dg/pr49472.f90 pessimizes [0.0, 1.0] into [-0.0, 1.0]. + && !is_a (r) + && !r.undefined_p ()) +{ + Value_Range tmp (r); + get_vrange (tmp, r.type ()); + gcc_checking_assert (tmp == r); +} } // Restore R from storage. @@ -306,13 +319,6 @@ irange_storage::set_irange (const irange &r) irange_bitmask bm = r.m_bitmask; write_wide_int (val, len, bm.value ()); write_wide_int (val, len, bm.mask ()); - - if (flag_checking) -{ - int_range_max tmp; - get_irange (tmp, r.type ()); - gcc_checking_assert (tmp == r); -} } static inline void
[gcc r15-36] Move get_bitmask_from_range out of irange class.
https://gcc.gnu.org/g:2caf7a50a6a9de80d2767d82b8cdb69d63469aaf commit r15-36-g2caf7a50a6a9de80d2767d82b8cdb69d63469aaf Author: Aldy Hernandez Date: Tue Mar 19 18:04:55 2024 +0100 Move get_bitmask_from_range out of irange class. prange will also have bitmasks, so it will need to use get_bitmask_from_range. gcc/ChangeLog: * value-range.cc (get_bitmask_from_range): Move out of irange class. (irange::get_bitmask): Call function instead of internal method. * value-range.h (class irange): Remove get_bitmask_from_range. Diff: --- gcc/value-range.cc | 52 ++-- gcc/value-range.h | 1 - 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 44929b210aa..d9689bd469f 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -31,6 +31,30 @@ along with GCC; see the file COPYING3. If not see #include "fold-const.h" #include "gimple-range.h" +// Return the bitmask inherent in a range. + +static irange_bitmask +get_bitmask_from_range (tree type, + const wide_int &min, const wide_int &max) +{ + unsigned prec = TYPE_PRECISION (type); + + // All the bits of a singleton are known. + if (min == max) +{ + wide_int mask = wi::zero (prec); + wide_int value = min; + return irange_bitmask (value, mask); +} + + wide_int xorv = min ^ max; + + if (xorv != 0) +xorv = wi::mask (prec - wi::clz (xorv), false, prec); + + return irange_bitmask (wi::zero (prec), min | xorv); +} + void irange::accept (const vrange_visitor &v) const { @@ -1881,31 +1905,6 @@ irange::invert () verify_range (); } -// Return the bitmask inherent in the range. - -irange_bitmask -irange::get_bitmask_from_range () const -{ - unsigned prec = TYPE_PRECISION (type ()); - wide_int min = lower_bound (); - wide_int max = upper_bound (); - - // All the bits of a singleton are known. - if (min == max) -{ - wide_int mask = wi::zero (prec); - wide_int value = lower_bound (); - return irange_bitmask (value, mask); -} - - wide_int xorv = min ^ max; - - if (xorv != 0) -xorv = wi::mask (prec - wi::clz (xorv), false, prec); - - return irange_bitmask (wi::zero (prec), min | xorv); -} - // Remove trailing ranges that this bitmask indicates can't exist. void @@ -2027,7 +2026,8 @@ irange::get_bitmask () const // in the mask. // // See also the note in irange_bitmask::intersect. - irange_bitmask bm = get_bitmask_from_range (); + irange_bitmask bm += get_bitmask_from_range (type (), lower_bound (), upper_bound ()); if (!m_bitmask.unknown_p ()) bm.intersect (m_bitmask); return bm; diff --git a/gcc/value-range.h b/gcc/value-range.h index d2e8fd5a4d9..ede90a496d8 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -352,7 +352,6 @@ private: bool varying_compatible_p () const; bool intersect_bitmask (const irange &r); bool union_bitmask (const irange &r); - irange_bitmask get_bitmask_from_range () const; bool set_range_from_bitmask (); bool intersect (const wide_int& lb, const wide_int& ub);
[gcc r15-38] Accept any vrange in range_includes_zero_p.
https://gcc.gnu.org/g:b102633be7d0b763d106b0a883679bb1497ca17c commit r15-38-gb102633be7d0b763d106b0a883679bb1497ca17c Author: Aldy Hernandez Date: Tue Mar 19 18:29:21 2024 +0100 Accept any vrange in range_includes_zero_p. Accept a vrange, as this will be used for either integers or pointers. gcc/ChangeLog: * value-range.h (range_includes_zero_p): Accept vrange. Diff: --- gcc/value-range.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gcc/value-range.h b/gcc/value-range.h index ede90a496d8..0ab717697f0 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -970,7 +970,7 @@ irange::contains_p (tree cst) const } inline bool -range_includes_zero_p (const irange &vr) +range_includes_zero_p (const vrange &vr) { if (vr.undefined_p ()) return false; @@ -978,8 +978,7 @@ range_includes_zero_p (const irange &vr) if (vr.varying_p ()) return true; - wide_int zero = wi::zero (TYPE_PRECISION (vr.type ())); - return vr.contains_p (zero); + return vr.contains_p (build_zero_cst (vr.type ())); } // Constructors for irange
[gcc r15-37] Make some integer specific ranges generic Value_Range's.
https://gcc.gnu.org/g:c284f8d2d16ce9c29defce3329419ccc54605ad4 commit r15-37-gc284f8d2d16ce9c29defce3329419ccc54605ad4 Author: Aldy Hernandez Date: Tue Mar 19 18:22:08 2024 +0100 Make some integer specific ranges generic Value_Range's. There are some irange uses that should be Value_Range, because they can be either integers or pointers. This will become a problem when prange comes live. gcc/ChangeLog: * tree-ssa-loop-split.cc (split_at_bb_p): Make int_range a Value_Range. * tree-ssa-strlen.cc (get_range): Same. * value-query.cc (range_query::get_tree_range): Handle both integers and pointers. * vr-values.cc (simplify_using_ranges::fold_cond_with_ops): Make r0 and r1 Value_Range's. Diff: --- gcc/tree-ssa-loop-split.cc | 6 +++--- gcc/tree-ssa-strlen.cc | 2 +- gcc/value-query.cc | 4 +--- gcc/vr-values.cc | 3 ++- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gcc/tree-ssa-loop-split.cc b/gcc/tree-ssa-loop-split.cc index a770ea371a2..a6be0cef7b0 100644 --- a/gcc/tree-ssa-loop-split.cc +++ b/gcc/tree-ssa-loop-split.cc @@ -144,18 +144,18 @@ split_at_bb_p (class loop *loop, basic_block bb, tree *border, affine_iv *iv, value range. */ else { - int_range<2> r; + Value_Range r (TREE_TYPE (op0)); get_global_range_query ()->range_of_expr (r, op0, stmt); if (!r.varying_p () && !r.undefined_p () && TREE_CODE (op1) == INTEGER_CST) { wide_int val = wi::to_wide (op1); - if (known_eq (val, r.lower_bound ())) + if (known_eq (val, wi::to_wide (r.lbound ( { code = (code == EQ_EXPR) ? LE_EXPR : GT_EXPR; break; } - else if (known_eq (val, r.upper_bound ())) + else if (known_eq (val, wi::to_wide (r.ubound ( { code = (code == EQ_EXPR) ? GE_EXPR : LT_EXPR; break; diff --git a/gcc/tree-ssa-strlen.cc b/gcc/tree-ssa-strlen.cc index e09c9cc081f..61c3da22322 100644 --- a/gcc/tree-ssa-strlen.cc +++ b/gcc/tree-ssa-strlen.cc @@ -215,7 +215,7 @@ get_range (tree val, gimple *stmt, wide_int minmax[2], rvals = get_range_query (cfun); } - value_range vr; + Value_Range vr (TREE_TYPE (val)); if (!rvals->range_of_expr (vr, val, stmt)) return NULL_TREE; diff --git a/gcc/value-query.cc b/gcc/value-query.cc index eda71dc89d3..052b7511565 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -156,11 +156,9 @@ range_query::get_tree_range (vrange &r, tree expr, gimple *stmt) { case INTEGER_CST: { - irange &i = as_a (r); if (TREE_OVERFLOW_P (expr)) expr = drop_tree_overflow (expr); - wide_int w = wi::to_wide (expr); - i.set (TREE_TYPE (expr), w, w); + r.set (expr, expr); return true; } diff --git a/gcc/vr-values.cc b/gcc/vr-values.cc index ff68d40c355..0572bf6c8c7 100644 --- a/gcc/vr-values.cc +++ b/gcc/vr-values.cc @@ -310,7 +310,8 @@ tree simplify_using_ranges::fold_cond_with_ops (enum tree_code code, tree op0, tree op1, gimple *s) { - int_range_max r0, r1; + Value_Range r0 (TREE_TYPE (op0)); + Value_Range r1 (TREE_TYPE (op1)); if (!query->range_of_expr (r0, op0, s) || !query->range_of_expr (r1, op1, s)) return NULL_TREE;
[gcc r15-39] Move print_irange_* out of vrange_printer class.
https://gcc.gnu.org/g:df6a1bc59a355c9fee10d29f54c9dca81612afb6 commit r15-39-gdf6a1bc59a355c9fee10d29f54c9dca81612afb6 Author: Aldy Hernandez Date: Tue Mar 19 20:26:27 2024 +0100 Move print_irange_* out of vrange_printer class. Move some code out of the irange pretty printers so it can be shared with pointers. gcc/ChangeLog: * value-range-pretty-print.cc (print_int_bound): New. (print_irange_bitmasks): New. (vrange_printer::print_irange_bound): Remove. (vrange_printer::print_irange_bitmasks): Remove. * value-range-pretty-print.h: Remove print_irange_bitmasks and print_irange_bound Diff: --- gcc/value-range-pretty-print.cc | 83 - gcc/value-range-pretty-print.h | 2 - 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/gcc/value-range-pretty-print.cc b/gcc/value-range-pretty-print.cc index c75cbea3955..b6d23dce6d2 100644 --- a/gcc/value-range-pretty-print.cc +++ b/gcc/value-range-pretty-print.cc @@ -30,6 +30,44 @@ along with GCC; see the file COPYING3. If not see #include "gimple-range.h" #include "value-range-pretty-print.h" +static void +print_int_bound (pretty_printer *pp, const wide_int &bound, tree type) +{ + wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); + + if (INTEGRAL_TYPE_P (type) + && !TYPE_UNSIGNED (type) + && bound == type_min + && TYPE_PRECISION (type) != 1) +pp_string (pp, "-INF"); + else if (bound == type_max && TYPE_PRECISION (type) != 1) +pp_string (pp, "+INF"); + else +pp_wide_int (pp, bound, TYPE_SIGN (type)); +} + +static void +print_irange_bitmasks (pretty_printer *pp, const irange_bitmask &bm) +{ + if (bm.unknown_p ()) +return; + + pp_string (pp, " MASK "); + char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p; + unsigned len_mask, len_val; + if (print_hex_buf_size (bm.mask (), &len_mask) + | print_hex_buf_size (bm.value (), &len_val)) +p = XALLOCAVEC (char, MAX (len_mask, len_val)); + else +p = buf; + print_hex (bm.mask (), p); + pp_string (pp, p); + pp_string (pp, " VALUE "); + print_hex (bm.value (), p); + pp_string (pp, p); +} + void vrange_printer::visit (const unsupported_range &r) const { @@ -66,51 +104,12 @@ vrange_printer::visit (const irange &r) const for (unsigned i = 0; i < r.num_pairs (); ++i) { pp_character (pp, '['); - print_irange_bound (r.lower_bound (i), r.type ()); + print_int_bound (pp, r.lower_bound (i), r.type ()); pp_string (pp, ", "); - print_irange_bound (r.upper_bound (i), r.type ()); + print_int_bound (pp, r.upper_bound (i), r.type ()); pp_character (pp, ']'); } - print_irange_bitmasks (r); -} - -void -vrange_printer::print_irange_bound (const wide_int &bound, tree type) const -{ - wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type)); - wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type)); - - if (INTEGRAL_TYPE_P (type) - && !TYPE_UNSIGNED (type) - && bound == type_min - && TYPE_PRECISION (type) != 1) -pp_string (pp, "-INF"); - else if (bound == type_max && TYPE_PRECISION (type) != 1) -pp_string (pp, "+INF"); - else -pp_wide_int (pp, bound, TYPE_SIGN (type)); -} - -void -vrange_printer::print_irange_bitmasks (const irange &r) const -{ - irange_bitmask bm = r.m_bitmask; - if (bm.unknown_p ()) -return; - - pp_string (pp, " MASK "); - char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p; - unsigned len_mask, len_val; - if (print_hex_buf_size (bm.mask (), &len_mask) - | print_hex_buf_size (bm.value (), &len_val)) -p = XALLOCAVEC (char, MAX (len_mask, len_val)); - else -p = buf; - print_hex (bm.mask (), p); - pp_string (pp, p); - pp_string (pp, " VALUE "); - print_hex (bm.value (), p); - pp_string (pp, p); + print_irange_bitmasks (pp, r.m_bitmask); } void diff --git a/gcc/value-range-pretty-print.h b/gcc/value-range-pretty-print.h index ca85fd6157c..44cd6e81298 100644 --- a/gcc/value-range-pretty-print.h +++ b/gcc/value-range-pretty-print.h @@ -29,8 +29,6 @@ public: void visit (const irange &) const override; void visit (const frange &) const override; private: - void print_irange_bound (const wide_int &w, tree type) const; - void print_irange_bitmasks (const irange &) const; void print_frange_nan (const frange &) const; void print_real_value (tree type, const REAL_VALUE_TYPE &r) const;
[gcc r15-40] Remove range_zero and range_nonzero.
https://gcc.gnu.org/g:3b9abfd2df5fe720798aab1e21b4a11876607561 commit r15-40-g3b9abfd2df5fe720798aab1e21b4a11876607561 Author: Aldy Hernandez Date: Wed Mar 20 05:51:55 2024 +0100 Remove range_zero and range_nonzero. Remove legacy range_zero and range_nonzero as they return by value, which make it not work in a separate irange and prange world. Also, we already have set_zero and set_nonzero methods in vrange. gcc/ChangeLog: * range-op-ptr.cc (pointer_plus_operator::wi_fold): Use method range setters instead of out of line functions. (pointer_min_max_operator::wi_fold): Same. (pointer_and_operator::wi_fold): Same. (pointer_or_operator::wi_fold): Same. * range-op.cc (operator_negate::fold_range): Same. (operator_addr_expr::fold_range): Same. (range_op_cast_tests): Same. * range.cc (range_zero): Remove. (range_nonzero): Remove. * range.h (range_zero): Remove. (range_nonzero): Remove. * value-range.cc (range_tests_misc): Use method instead of out of line function. Diff: --- gcc/range-op-ptr.cc | 14 +++--- gcc/range-op.cc | 14 -- gcc/range.cc| 14 -- gcc/range.h | 2 -- gcc/value-range.cc | 7 --- 5 files changed, 19 insertions(+), 32 deletions(-) diff --git a/gcc/range-op-ptr.cc b/gcc/range-op-ptr.cc index 2c85d75b5e8..7343ef635f3 100644 --- a/gcc/range-op-ptr.cc +++ b/gcc/range-op-ptr.cc @@ -101,10 +101,10 @@ pointer_plus_operator::wi_fold (irange &r, tree type, && !TYPE_OVERFLOW_WRAPS (type) && (flag_delete_null_pointer_checks || !wi::sign_mask (rh_ub))) -r = range_nonzero (type); +r.set_nonzero (type); else if (lh_lb == lh_ub && lh_lb == 0 && rh_lb == rh_ub && rh_lb == 0) -r = range_zero (type); +r.set_zero (type); else r.set_varying (type); } @@ -150,9 +150,9 @@ pointer_min_max_operator::wi_fold (irange &r, tree type, // are varying. if (!wi_includes_zero_p (type, lh_lb, lh_ub) && !wi_includes_zero_p (type, rh_lb, rh_ub)) -r = range_nonzero (type); +r.set_nonzero (type); else if (wi_zero_p (type, lh_lb, lh_ub) && wi_zero_p (type, rh_lb, rh_ub)) -r = range_zero (type); +r.set_zero (type); else r.set_varying (type); } @@ -175,7 +175,7 @@ pointer_and_operator::wi_fold (irange &r, tree type, // For pointer types, we are really only interested in asserting // whether the expression evaluates to non-NULL. if (wi_zero_p (type, lh_lb, lh_ub) || wi_zero_p (type, lh_lb, lh_ub)) -r = range_zero (type); +r.set_zero (type); else r.set_varying (type); } @@ -236,9 +236,9 @@ pointer_or_operator::wi_fold (irange &r, tree type, // whether the expression evaluates to non-NULL. if (!wi_includes_zero_p (type, lh_lb, lh_ub) && !wi_includes_zero_p (type, rh_lb, rh_ub)) -r = range_nonzero (type); +r.set_nonzero (type); else if (wi_zero_p (type, lh_lb, lh_ub) && wi_zero_p (type, rh_lb, rh_ub)) -r = range_zero (type); +r.set_zero (type); else r.set_varying (type); } diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 6ea7d624a9b..ab3a4f0b200 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4364,9 +4364,11 @@ operator_negate::fold_range (irange &r, tree type, { if (empty_range_varying (r, type, lh, rh)) return true; - // -X is simply 0 - X. - return range_op_handler (MINUS_EXPR).fold_range (r, type, - range_zero (type), lh); + +// -X is simply 0 - X. + int_range<1> zero; + zero.set_zero (type); + return range_op_handler (MINUS_EXPR).fold_range (r, type, zero, lh); } bool @@ -4391,7 +4393,7 @@ operator_addr_expr::fold_range (irange &r, tree type, // Return a non-null pointer of the LHS type (passed in op2). if (lh.zero_p ()) -r = range_zero (type); +r.set_zero (type); else if (lh.undefined_p () || contains_zero_p (lh)) r.set_varying (type); else @@ -4675,7 +4677,7 @@ range_op_cast_tests () if (TYPE_PRECISION (integer_type_node) > TYPE_PRECISION (short_integer_type_node)) { - r0 = range_nonzero (integer_type_node); + r0.set_nonzero (integer_type_node); range_cast (r0, short_integer_type_node); r1 = int_range<1> (short_integer_type_node, min_limit (short_integer_type_node), @@ -4687,7 +4689,7 @@ range_op_cast_tests () // // NONZERO signed 16-bits is [-MIN_16,-1][1, +MAX_16]. // Converting this to 32-bits signed is [-MIN_16,-1][1, +MAX_16]. - r0 = range_nonzero (short_integer_type_node); + r0.set_nonzero (short_integer_type_node); range_cast (r0, integer_type_node); r1 = int_range<1> (integer_type_node, INT (-32768), INT (-1)); r2 = int_range<1> (integer_type_node, INT (1), INT (32767)); diff --git a/gcc/range.cc b/gcc/ra
[gcc r15-41] Callers of irange_bitmask must normalize value/mask pairs.
https://gcc.gnu.org/g:d71308d5a681de00ea291136c162e5b46c7c commit r15-41-gd71308d5a681de00ea291136c162e5b46c7c Author: Aldy Hernandez Date: Tue Apr 23 10:12:56 2024 +0200 Callers of irange_bitmask must normalize value/mask pairs. As per the documentation, irange_bitmask must have the unknown bits in the mask set to 0 in the value field. Even though we say we must have normalized value/mask bits, we don't enforce it, opting to normalize on the fly in union and intersect. Avoiding this lazy enforcing as well as the extra saving/restoring involved in returning the changed status, gives us a performance increase of 1.25% for VRP and 1.51% for ipa-CP. gcc/ChangeLog: * tree-ssa-ccp.cc (ccp_finalize): Normalize before calling set_bitmask. * value-range.cc (irange::intersect_bitmask): Calculate changed irange_bitmask bits on our own. (irange::union_bitmask): Same. (irange_bitmask::verify_mask): Verify that bits are normalized. * value-range.h (irange_bitmask::union_): Do not normalize. Remove return value. (irange_bitmask::intersect): Same. Diff: --- gcc/tree-ssa-ccp.cc | 1 + gcc/value-range.cc | 7 +-- gcc/value-range.h | 24 ++-- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc index f6a5cd0ee6e..3749126b5f7 100644 --- a/gcc/tree-ssa-ccp.cc +++ b/gcc/tree-ssa-ccp.cc @@ -1024,6 +1024,7 @@ ccp_finalize (bool nonzero_p) unsigned int precision = TYPE_PRECISION (TREE_TYPE (val->value)); wide_int value = wi::to_wide (val->value); wide_int mask = wide_int::from (val->mask, precision, UNSIGNED); + value = value & ~mask; set_bitmask (name, value, mask); } } diff --git a/gcc/value-range.cc b/gcc/value-range.cc index a27de5534e1..ca6d521c625 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -2067,7 +2067,8 @@ irange::intersect_bitmask (const irange &r) irange_bitmask bm = get_bitmask (); irange_bitmask save = bm; - if (!bm.intersect (r.get_bitmask ())) + bm.intersect (r.get_bitmask ()); + if (save == bm) return false; m_bitmask = bm; @@ -2099,7 +2100,8 @@ irange::union_bitmask (const irange &r) irange_bitmask bm = get_bitmask (); irange_bitmask save = bm; - if (!bm.union_ (r.get_bitmask ())) + bm.union_ (r.get_bitmask ()); + if (save == bm) return false; m_bitmask = bm; @@ -2133,6 +2135,7 @@ void irange_bitmask::verify_mask () const { gcc_assert (m_value.get_precision () == m_mask.get_precision ()); + gcc_checking_assert (wi::bit_and (m_mask, m_value) == 0); } void diff --git a/gcc/value-range.h b/gcc/value-range.h index 0ab717697f0..11c73faca1b 100644 --- a/gcc/value-range.h +++ b/gcc/value-range.h @@ -139,8 +139,8 @@ public: void set_unknown (unsigned prec); bool unknown_p () const; unsigned get_precision () const; - bool union_ (const irange_bitmask &src); - bool intersect (const irange_bitmask &src); + void union_ (const irange_bitmask &src); + void intersect (const irange_bitmask &src); bool operator== (const irange_bitmask &src) const; bool operator!= (const irange_bitmask &src) const { return !(*this == src); } void verify_mask () const; @@ -233,29 +233,18 @@ irange_bitmask::operator== (const irange_bitmask &src) const return m_value == src.m_value && m_mask == src.m_mask; } -inline bool -irange_bitmask::union_ (const irange_bitmask &orig_src) +inline void +irange_bitmask::union_ (const irange_bitmask &src) { - // Normalize mask. - irange_bitmask src (orig_src.m_value & ~orig_src.m_mask, orig_src.m_mask); - m_value &= ~m_mask; - - irange_bitmask save (*this); m_mask = (m_mask | src.m_mask) | (m_value ^ src.m_value); m_value = m_value & src.m_value; if (flag_checking) verify_mask (); - return *this != save; } -inline bool -irange_bitmask::intersect (const irange_bitmask &orig_src) +inline void +irange_bitmask::intersect (const irange_bitmask &src) { - // Normalize mask. - irange_bitmask src (orig_src.m_value & ~orig_src.m_mask, orig_src.m_mask); - m_value &= ~m_mask; - - irange_bitmask save (*this); // If we have two known bits that are incompatible, the resulting // bit is undefined. It is unclear whether we should set the entire // range to UNDEFINED, or just a subset of it. For now, set the @@ -274,7 +263,6 @@ irange_bitmask::intersect (const irange_bitmask &orig_src) } if (flag_checking) verify_mask (); - return *this != save; } // An integer range without any storage.
[gcc r15-43] MIPS: Add MIN/MAX.fmt instructions support for MIPS R6
https://gcc.gnu.org/g:11c13111ac64a035d6c4ea6c118eff4ece7a9d9b commit r15-43-g11c13111ac64a035d6c4ea6c118eff4ece7a9d9b Author: Jie Mei Date: Sun Apr 28 16:57:31 2024 +0800 MIPS: Add MIN/MAX.fmt instructions support for MIPS R6 This patch adds the smin/smax RTL mode for the min/max.fmt instructions. Also, since the min/max.fmt instrucions applies to the IEEE 754-2008 "minNum" and "maxNum" operations, this patch also provides the new "fmin3" and "fmax3" modes. gcc/ChangeLog: * config/mips/i6400.md (i6400_fpu_minmax): New define_insn_reservation. * config/mips/mips.h (ISA_HAS_FMIN_FMAX): Define new macro. * config/mips/mips.md (UNSPEC_FMIN): New unspec. (UNSPEC_FMAX): Same as above. (type): Add fminmax. (smin3): Generates MIN.fmt instructions. (smax3): Generates MAX.fmt instructions. (fmin3): Generates MIN.fmt instructions. (fmax3): Generates MAX.fmt instructions. * config/mips/p6600.md (p6600_fpu_fabs): Include fminmax type. gcc/testsuite/ChangeLog: * gcc.target/mips/mips-minmax1.c: New test for MIPS R6. * gcc.target/mips/mips-minmax2.c: Same as above. Diff: --- gcc/config/mips/i6400.md | 6 gcc/config/mips/mips.h | 2 ++ gcc/config/mips/mips.md | 50 ++-- gcc/config/mips/p6600.md | 4 +-- gcc/testsuite/gcc.target/mips/mips-minmax1.c | 40 ++ gcc/testsuite/gcc.target/mips/mips-minmax2.c | 36 6 files changed, 134 insertions(+), 4 deletions(-) diff --git a/gcc/config/mips/i6400.md b/gcc/config/mips/i6400.md index 9f216fe0210..d6f691ee217 100644 --- a/gcc/config/mips/i6400.md +++ b/gcc/config/mips/i6400.md @@ -219,6 +219,12 @@ (eq_attr "type" "fabs,fneg,fmove")) "i6400_fpu_short, i6400_fpu_apu") +;; min, max +(define_insn_reservation "i6400_fpu_minmax" 2 + (and (eq_attr "cpu" "i6400") + (eq_attr "type" "fminmax")) + "i6400_fpu_short+i6400_fpu_logic") + ;; fadd, fsub, fcvt (define_insn_reservation "i6400_fpu_fadd" 4 (and (eq_attr "cpu" "i6400") diff --git a/gcc/config/mips/mips.h b/gcc/config/mips/mips.h index 616a275b918..9d965966f2f 100644 --- a/gcc/config/mips/mips.h +++ b/gcc/config/mips/mips.h @@ -1262,6 +1262,8 @@ struct mips_cpu_info { #define ISA_HAS_9BIT_DISPLACEMENT (mips_isa_rev >= 6 \ || ISA_HAS_MIPS16E2) +#define ISA_HAS_FMIN_FMAX (mips_isa_rev >= 6) + /* ISA has data indexed prefetch instructions. This controls use of 'prefx', along with TARGET_HARD_FLOAT and TARGET_DOUBLE_FLOAT. (prefx is a cop1x instruction, so can only be used if FP is diff --git a/gcc/config/mips/mips.md b/gcc/config/mips/mips.md index b0fb5850a9e..26f758c90dd 100644 --- a/gcc/config/mips/mips.md +++ b/gcc/config/mips/mips.md @@ -97,6 +97,10 @@ UNSPEC_GET_FCSR UNSPEC_SET_FCSR + ;; Floating-point unspecs. + UNSPEC_FMIN + UNSPEC_FMAX + ;; HI/LO moves. UNSPEC_MFHI UNSPEC_MTHI @@ -370,6 +374,7 @@ ;; frsqrt floating point reciprocal square root ;; frsqrt1 floating point reciprocal square root step1 ;; frsqrt2 floating point reciprocal square root step2 +;; fminmax floating point min/max ;; dspmac DSP MAC instructions not saturating the accumulator ;; dspmacsatDSP MAC instructions that saturate the accumulator ;; accext DSP accumulator extract instructions @@ -387,8 +392,8 @@ prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical, shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move, fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt, - frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat, - multi,atomic,syncloop,nop,ghost,multimem, + frsqrt,frsqrt1,frsqrt2,fminmax,dspmac,dspmacsat,accext,accmod,dspalu, + dspalusat,multi,atomic,syncloop,nop,ghost,multimem, simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd, simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp, simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill, @@ -7971,6 +7976,47 @@ [(set_attr "move_type" "load") (set_attr "insn_count" "2")]) +;; +;; Float point MIN/MAX +;; + +(define_insn "smin3" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (smin:SCALARF (match_operand:SCALARF 1 "register_operand" "f") + (match_operand:SCALARF 2 "register_operand" "f")))] + "ISA_HAS_FMIN_FMAX" + "min.\t%0,%1,%2" + [(set_attr "type" "fminmax") + (set_attr "mode" "")]) + +(define_insn "smax3" + [(set (match_operand:SCALARF 0 "register_operand" "=f") + (smax:SCALARF (match_operand:SCALARF 1 "register_operand" "f") +