Re: [PATCH] x86-64: Remove HAVE_LD_PIE_COPYRELOC
PING^4 https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570139.html One major design goal of PIE was to avoid copy relocations. The original patch for GCC 5 caused problems for many years. On Wed, Aug 18, 2021 at 11:54 PM Fāng-ruì Sòng wrote: > PING^3 https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570139.html > > On Fri, Jun 4, 2021 at 3:04 PM Fāng-ruì Sòng wrote: > > > > PING^2 https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570139.html > > > > On Mon, May 24, 2021 at 9:43 AM Fāng-ruì Sòng > wrote: > > > > > > Ping https://gcc.gnu.org/pipermail/gcc-patches/2021-May/570139.html > > > > > > On Tue, May 11, 2021 at 8:29 PM Fangrui Song > wrote: > > > > > > > > This was introduced in 2014-12 to use local binding for external > symbols > > > > for -fPIE. Now that we have H.J. Lu's GOTPCRELX for years which > mostly > > > > nullify the benefit of HAVE_LD_PIE_COPYRELOC, HAVE_LD_PIE_COPYRELOC > > > > should retire now. > > > > > > > > One design goal of -fPIE was to avoid copy relocations. > > > > HAVE_LD_PIE_COPYRELOC has deviated from the goal. With this change, > the > > > > -fPIE behavior of x86-64 will be closer to x86-32 and other targets. > > > > > > > > --- > > > > > > > > See https://gcc.gnu.org/legacy-ml/gcc/2019-05/msg00215.html for a > list > > > > of fixed and unfixed (e.g. gold incompatibility with protected > > > > https://sourceware.org/bugzilla/show_bug.cgi?id=19823) issues. > > > > > > > > If you prefer a longer write-up, see > > > > > https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected > > > > --- > > > > gcc/config.in | 6 --- > > > > gcc/config/i386/i386.c| 11 +--- > > > > gcc/configure | 52 > --- > > > > gcc/configure.ac | 48 > - > > > > gcc/doc/sourcebuild.texi | 3 -- > > > > .../gcc.target/i386/pie-copyrelocs-1.c| 14 - > > > > .../gcc.target/i386/pie-copyrelocs-2.c| 14 - > > > > .../gcc.target/i386/pie-copyrelocs-3.c| 14 - > > > > .../gcc.target/i386/pie-copyrelocs-4.c| 17 -- > > > > gcc/testsuite/lib/target-supports.exp | 47 - > > > > 10 files changed, 2 insertions(+), 224 deletions(-) > > > > delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-1.c > > > > delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-2.c > > > > delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-3.c > > > > delete mode 100644 gcc/testsuite/gcc.target/i386/pie-copyrelocs-4.c > > > > > > > > diff --git a/gcc/config.in b/gcc/config.in > > > > index e54f59ce0c3..a65bf5d4176 100644 > > > > --- a/gcc/config.in > > > > +++ b/gcc/config.in > > > > @@ -1659,12 +1659,6 @@ > > > > #endif > > > > > > > > > > > > -/* Define 0/1 if your linker supports -pie option with copy reloc. > */ > > > > -#ifndef USED_FOR_TARGET > > > > -#undef HAVE_LD_PIE_COPYRELOC > > > > -#endif > > > > - > > > > - > > > > /* Define if your PowerPC linker has .gnu.attributes long double > support. */ > > > > #ifndef USED_FOR_TARGET > > > > #undef HAVE_LD_PPC_GNU_ATTR_LONG_DOUBLE > > > > diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c > > > > index 915f89f571a..5ec3c6fd0c9 100644 > > > > --- a/gcc/config/i386/i386.c > > > > +++ b/gcc/config/i386/i386.c > > > > @@ -10579,11 +10579,7 @@ legitimate_pic_address_disp_p (rtx disp) > > > > return true; > > > > } > > > > else if (!SYMBOL_REF_FAR_ADDR_P (op0) > > > > - && (SYMBOL_REF_LOCAL_P (op0) > > > > - || (HAVE_LD_PIE_COPYRELOC > > > > - && flag_pie > > > > - && !SYMBOL_REF_WEAK (op0) > > > > - && !SYMBOL_REF_FUNCTION_P (op0))) > > > > + && SYMBOL_REF_LOCAL_P (op0) > > > >&& ix86_cmodel != CM_LARGE_PIC) > > > > return true; > > > > break; > > > > @@ -22892,10 +22888,7 @@ ix86_atomic_assign_expand_fenv (tree *hold, > tree *clear, tree *update) > > > > static bool > > > > ix86_binds_local_p (const_tree exp) > > > > { > > > > - return default_binds_local_p_3 (exp, flag_shlib != 0, true, true, > > > > - (!flag_pic > > > > - || (TARGET_64BIT > > > > - && HAVE_LD_PIE_COPYRELOC != > 0))); > > > > + return default_binds_local_p_3 (exp, flag_shlib != 0, true, true, > !flag_pic); > > > > } > > > > #endif > > > > > > > > diff --git a/gcc/configure b/gcc/configure > > > > index f03fe888384..c500f5ca11e 100755 > > > > --- a/gcc/configure > > > > +++ b/gcc/configure > > > > @@ -29968,58 +29968,6 @@ fi > > > > { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_pie" >&5 > > > > $as_echo "$gcc_cv_ld_pie" >&6; } > > > > > > > > -{ $as_echo "$as
[PATCH] x86: Add non-destructive source to @xorsign3_1
Add non-destructive source alternative to @xorsign3_1 for AVX. gcc/ PR target/89984 * config/i386/i386-expand.c (ix86_split_xorsign): Use operands[2]. * config/i386/i386.md (@xorsign3_1): Add non-destructive source alternative for AVX. gcc/testsuite/ PR target/89984 * gcc.target/i386/pr89984-1.c: New test. * gcc.target/i386/pr89984-2.c: Likewise. * gcc.target/i386/xorsign-avx.c: Likewise. --- gcc/config/i386/i386-expand.c | 13 - gcc/config/i386/i386.md | 11 ++- gcc/testsuite/gcc.target/i386/pr89984-1.c | 8 gcc/testsuite/gcc.target/i386/pr89984-2.c | 10 ++ gcc/testsuite/gcc.target/i386/xorsign-avx.c | 4 5 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr89984-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr89984-2.c create mode 100644 gcc/testsuite/gcc.target/i386/xorsign-avx.c diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 2500dbfa7fb..273a0ba8e3d 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -2279,21 +2279,24 @@ void ix86_split_xorsign (rtx operands[]) { machine_mode mode, vmode; - rtx dest, op0, mask, x; + rtx dest, op0, op1, mask, x; dest = operands[0]; op0 = operands[1]; + op1 = operands[2]; mask = operands[3]; mode = GET_MODE (dest); vmode = GET_MODE (mask); - dest = lowpart_subreg (vmode, dest, mode); - x = gen_rtx_AND (vmode, dest, mask); - emit_insn (gen_rtx_SET (dest, x)); + op1 = lowpart_subreg (vmode, op1, mode); + x = gen_rtx_AND (vmode, op1, mask); + emit_insn (gen_rtx_SET (op1, x)); op0 = lowpart_subreg (vmode, op0, mode); - x = gen_rtx_XOR (vmode, dest, op0); + x = gen_rtx_XOR (vmode, op1, op0); + + dest = lowpart_subreg (vmode, dest, mode); emit_insn (gen_rtx_SET (dest, x)); } diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 0cd151ce4e5..18b91c77937 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -10806,17 +10806,18 @@ (define_expand "xorsign3" "ix86_expand_xorsign (operands); DONE;") (define_insn_and_split "@xorsign3_1" - [(set (match_operand:MODEF 0 "register_operand" "=Yv") + [(set (match_operand:MODEF 0 "register_operand" "=Yv,Yv") (unspec:MODEF - [(match_operand:MODEF 1 "register_operand" "Yv") - (match_operand:MODEF 2 "register_operand" "0") - (match_operand: 3 "nonimmediate_operand" "Yvm")] + [(match_operand:MODEF 1 "register_operand" "Yv,Yv") + (match_operand:MODEF 2 "register_operand" "0,Yv") + (match_operand: 3 "nonimmediate_operand" "Yvm,Yvm")] UNSPEC_XORSIGN))] "SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH" "#" "&& reload_completed" [(const_int 0)] - "ix86_split_xorsign (operands); DONE;") + "ix86_split_xorsign (operands); DONE;" + [(set_attr "isa" "noavx,avx")]) ;; One complement instructions diff --git a/gcc/testsuite/gcc.target/i386/pr89984-1.c b/gcc/testsuite/gcc.target/i386/pr89984-1.c new file mode 100644 index 000..d77691c0da0 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr89984-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2 -mno-avx -msse2" } */ + +float +check_f_pos (float x, float y) +{ + return x * __builtin_copysignf (1.0f, y); +} diff --git a/gcc/testsuite/gcc.target/i386/pr89984-2.c b/gcc/testsuite/gcc.target/i386/pr89984-2.c new file mode 100644 index 000..ff6a8e50573 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr89984-2.c @@ -0,0 +1,10 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2 -mavx" } */ + +float +check_f_pos (float x, float y) +{ + return x * __builtin_copysignf (1.0f, y); +} + +/* { dg-final { scan-assembler-not "vmovaps" } } */ diff --git a/gcc/testsuite/gcc.target/i386/xorsign-avx.c b/gcc/testsuite/gcc.target/i386/xorsign-avx.c new file mode 100644 index 000..f2e2054b6fb --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/xorsign-avx.c @@ -0,0 +1,4 @@ +/* { dg-do run { target avx_runtime } } */ +/* { dg-options "-O2 -mavx -mfpmath=sse -ftree-vectorize" } */ + +#include "xorsign.c" -- 2.31.1
[PATCH] x86: Enable FMA in unsigned SI to SF expanders
Enable FMA in scalar/vector unsigned SI to SF expanders. gcc/ PR target/85819 * config/i386/i386-expand.c (ix86_expand_convert_uns_sisf_sse): Enable FMA. (ix86_expand_vector_convert_uns_vsivsf): Likewise. gcc/testsuite/ PR target/85819 * gcc.target/i386/pr85819-1.c: New test. * gcc.target/i386/pr85819-2a.c: Likewise. * gcc.target/i386/pr85819-2b.c: Likewise. * gcc.target/i386/pr85819-2c.c: Likewise. * gcc.target/i386/pr85819-3.c: Likewise. --- gcc/config/i386/i386-expand.c | 44 -- gcc/testsuite/gcc.target/i386/pr85819-1.c | 11 ++ gcc/testsuite/gcc.target/i386/pr85819-2a.c | 17 + gcc/testsuite/gcc.target/i386/pr85819-2b.c | 6 +++ gcc/testsuite/gcc.target/i386/pr85819-2c.c | 7 gcc/testsuite/gcc.target/i386/pr85819-3.c | 18 + 6 files changed, 91 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr85819-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr85819-2a.c create mode 100644 gcc/testsuite/gcc.target/i386/pr85819-2b.c create mode 100644 gcc/testsuite/gcc.target/i386/pr85819-2c.c create mode 100644 gcc/testsuite/gcc.target/i386/pr85819-3.c diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 2500dbfa7fb..26263bbe1af 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -1851,12 +1851,21 @@ ix86_expand_convert_uns_sisf_sse (rtx target, rtx input) fp_lo = gen_reg_rtx (SFmode); emit_insn (gen_floatsisf2 (fp_hi, int_hi)); emit_insn (gen_floatsisf2 (fp_lo, int_lo)); - fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi, - 0, OPTAB_DIRECT); - fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target, - 0, OPTAB_DIRECT); - if (!rtx_equal_p (target, fp_hi)) -emit_move_insn (target, fp_hi); + if (TARGET_FMA || TARGET_AVX512F) +{ + x = validize_mem (force_const_mem (SFmode, x)); + fp_hi = gen_rtx_FMA (SFmode, fp_hi, x, fp_lo); + emit_move_insn (target, fp_hi); +} + else +{ + fp_hi = expand_simple_binop (SFmode, MULT, fp_hi, x, fp_hi, + 0, OPTAB_DIRECT); + fp_hi = expand_simple_binop (SFmode, PLUS, fp_hi, fp_lo, target, + 0, OPTAB_DIRECT); + if (!rtx_equal_p (target, fp_hi)) + emit_move_insn (target, fp_hi); +} } /* floatunsv{4,8}siv{4,8}sf2 expander. Expand code to convert @@ -1888,12 +1897,23 @@ ix86_expand_vector_convert_uns_vsivsf (rtx target, rtx val) real_ldexp (&TWO16r, &dconst1, 16); tmp[5] = const_double_from_real_value (TWO16r, SFmode); tmp[5] = force_reg (fltmode, ix86_build_const_vector (fltmode, 1, tmp[5])); - tmp[6] = expand_simple_binop (fltmode, MULT, tmp[4], tmp[5], NULL_RTX, 1, - OPTAB_DIRECT); - tmp[7] = expand_simple_binop (fltmode, PLUS, tmp[3], tmp[6], target, 1, - OPTAB_DIRECT); - if (tmp[7] != target) -emit_move_insn (target, tmp[7]); + unsigned vector_size = GET_MODE_SIZE (fltmode); + if (TARGET_FMA + || (TARGET_AVX512F && vector_size == 64) + || (TARGET_AVX512VL && (vector_size == 32 || vector_size == 16))) +{ + tmp[6] = gen_rtx_FMA (fltmode, tmp[4], tmp[5], tmp[3]); + emit_move_insn (target, tmp[6]); +} + else +{ + tmp[6] = expand_simple_binop (fltmode, MULT, tmp[4], tmp[5], + NULL_RTX, 1, OPTAB_DIRECT); + tmp[7] = expand_simple_binop (fltmode, PLUS, tmp[3], tmp[6], + target, 1, OPTAB_DIRECT); + if (tmp[7] != target) + emit_move_insn (target, tmp[7]); +} } /* Adjust a V*SFmode/V*DFmode value VAL so that *sfix_trunc* resp. fix_trunc* diff --git a/gcc/testsuite/gcc.target/i386/pr85819-1.c b/gcc/testsuite/gcc.target/i386/pr85819-1.c new file mode 100644 index 000..db02282d100 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr85819-1.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mno-avx512f -mfma -mfpmath=sse" } */ + +float +foo (unsigned int x) +{ + return x; +} + +/* { dg-final { scan-assembler "vfmadd132ss" { target ia32 } } } */ +/* { dg-final { scan-assembler "vcvtsi2ssq" { target { ! ia32 } } } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr85819-2a.c b/gcc/testsuite/gcc.target/i386/pr85819-2a.c new file mode 100644 index 000..cea599fe416 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr85819-2a.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -mno-avx512f -mavx2 -mfma -mfpmath=sse" } */ + +typedef float To __attribute__ ((__vector_size__ (32))); +typedef unsigned int From __attribute__ ((__vector_size__ (32))); + +#define A2(I) (float)a[I], (float)a[1+I] +#define A4(I) A2(I), A2(2+I) +#define A8(I) A4(I), A4(4+I) + +To +f(From a) +{ + return __extension__ (To) {A8
[PATCH 0/2 v2] jit : Generate debug info for variables
Hi, This is a revision of my patch for debug info. The patches are posted as mails to this thread. Make check-jit runs fine on Debian x64. Below is the original mail and under it a rehash of the review comments. Regards, Petter - Hi, This is a patch to generate debug info for local variables as well as globals. With this, "ptype foo", "info variables", "info locals" etc works when debugging in GDB. Finalizing of global variable declares are moved to after locations are handled and done as Fortran, C, Go etc do it. Also, primitive types have their TYPE_NAME set for debug info on types to work. Below are the patch, and I attached a testcase. Since it requires GDB to run it might not be suitable? Make check-jit runs fine on Debian x64. Regards, - > Can you write non-empty ChangeLog entries please. Done. I think the python script chokes on asd/qwe/jit.db/ (the dot) though. > @@ -2984,15 +2975,22 @@ replay () > Looks like some whitespace churn above Fixed. > I don't see "Signed-off-by" tags in the patches. Added. > I think this should be "unsupported" rather than "xfail". Changed. > This is OK, but maybe using gcc_jit_context_dump_to_file with update_locations == 1 might be more sustainable in the long run? Ye I didn't remember that flag. Entering loc manually aint no fun.
[PATCH 1/2 v2] jit : Generate debug info for variables
>From 521349806136bef9096d094f4785f5868854a19d Mon Sep 17 00:00:00 2001 From: Petter Tomner Date: Sat, 4 Sep 2021 23:55:34 +0200 Subject: [PATCH 1/2] libgccjit: Generate debug info for variables Finalize declares via available helpers after location is set. Set TYPE_NAME of primitives and friends to "int" etc. Debug info is now set properly for variables. Signed-off-by: 2021-09-05 Petter Tomner gcc/jit/ * jit-playback.c: Moved global var processing to after loc handling. Setting TYPE_NAME for fundamental types. Using common functions for finalizing globals. * jit-playback.h: New method init_types(). Changed get_tree_node_for_type() to method. gcc/testsuite/jit.dg/ * test-error-array-bounds.c: Array is not unsigned --- gcc/jit/jit-playback.c| 70 +++ gcc/jit/jit-playback.h| 5 ++ .../jit.dg/test-error-array-bounds.c | 2 +- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index 79ac525e5df..bf1bd10dedd 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -165,7 +165,8 @@ gt_ggc_mx () /* Given an enum gcc_jit_types value, get a "tree" type. */ -static tree +tree +playback::context:: get_tree_node_for_type (enum gcc_jit_types type_) { switch (type_) @@ -192,11 +193,7 @@ get_tree_node_for_type (enum gcc_jit_types type_) return short_unsigned_type_node; case GCC_JIT_TYPE_CONST_CHAR_PTR: - { - tree const_char = build_qualified_type (char_type_node, - TYPE_QUAL_CONST); - return build_pointer_type (const_char); - } + return m_const_char_ptr; case GCC_JIT_TYPE_INT: return integer_type_node; @@ -579,10 +576,6 @@ playback::lvalue * playback::context:: global_finalize_lvalue (tree inner) { - varpool_node::get_create (inner); - - varpool_node::finalize_decl (inner); - m_globals.safe_push (inner); return new lvalue (this, inner); @@ -2952,9 +2945,7 @@ replay () { JIT_LOG_SCOPE (get_logger ()); - m_const_char_ptr -= build_pointer_type (build_qualified_type (char_type_node, - TYPE_QUAL_CONST)); + init_types (); /* Replay the recorded events: */ timevar_push (TV_JIT_REPLAY); @@ -2984,10 +2975,17 @@ replay () { int i; function *func; - + tree global; /* No GC can happen yet; process the cached source locations. */ handle_locations (); + /* Finalize globals. See how FORTRAN 95 does it in gfc_be_parse_file() + for a simple reference. */ + FOR_EACH_VEC_ELT (m_globals, i, global) +rest_of_decl_compilation (global, true, true); + + wrapup_global_declarations (m_globals.address(), m_globals.length()); + /* We've now created tree nodes for the stmts in the various blocks in each function, but we haven't built each function's single stmt list yet. Do so now. */ @@ -3081,6 +3079,50 @@ location_comparator (const void *lhs, const void *rhs) return loc_lhs->get_column_num () - loc_rhs->get_column_num (); } +/* Initialize the NAME_TYPE of the primitive types as well as some + others. */ +void +playback::context:: +init_types () +{ + /* See lto_init() in lto-lang.c or void visit (TypeBasic *t) in D's types.cc + for reference. If TYPE_NAME is not set, debug info will not contain types */ +#define NAME_TYPE(t,n) \ +if (t) \ + TYPE_NAME (t) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, \ + get_identifier (n), t) + + NAME_TYPE (integer_type_node, "int"); + NAME_TYPE (char_type_node, "char"); + NAME_TYPE (long_integer_type_node, "long int"); + NAME_TYPE (unsigned_type_node, "unsigned int"); + NAME_TYPE (long_unsigned_type_node, "long unsigned int"); + NAME_TYPE (long_long_integer_type_node, "long long int"); + NAME_TYPE (long_long_unsigned_type_node, "long long unsigned int"); + NAME_TYPE (short_integer_type_node, "short int"); + NAME_TYPE (short_unsigned_type_node, "short unsigned int"); + if (signed_char_type_node != char_type_node) +NAME_TYPE (signed_char_type_node, "signed char"); + if (unsigned_char_type_node != char_type_node) +NAME_TYPE (unsigned_char_type_node, "unsigned char"); + NAME_TYPE (float_type_node, "float"); + NAME_TYPE (double_type_node, "double"); + NAME_TYPE (long_double_type_node, "long double"); + NAME_TYPE (void_type_node, "void"); + NAME_TYPE (boolean_type_node, "bool"); + NAME_TYPE (complex_float_type_node, "complex float"); + NAME_TYPE (complex_double_type_node, "complex double"); + NAME_TYPE (complex_long_double_type_node, "complex long double"); + + m_const_char_ptr = build_pointer_type( +build_qualified_type (char_type_node, TYPE_QUAL_CONST)); + + NAME_TYPE (m_const_char_ptr, "char"); + NAME_TYPE (size_type_node, "size_t"); + NAME_TYPE
[PATCH 2/2 v2] jit : Generate debug info for variables, testcase
>From 87d081f6b4233446f8a45f76dfd674f1e0b6aafe Mon Sep 17 00:00:00 2001 From: Petter Tomner Date: Sun, 5 Sep 2021 00:18:10 +0200 Subject: [PATCH 2/2] libgccjit: Test cases for debug info Assure that debug info is available for a local and global variable and a function with GDB. Signed-off-by: 2021-09-05 Petter Tomner gcc/testsuite/jit.dg/ * jit.exp: Helper function * test-debuginfo.c: New file --- gcc/testsuite/jit.dg/jit.exp | 25 ++ gcc/testsuite/jit.dg/test-debuginfo.c | 72 +++ 2 files changed, 97 insertions(+) create mode 100644 gcc/testsuite/jit.dg/test-debuginfo.c diff --git a/gcc/testsuite/jit.dg/jit.exp b/gcc/testsuite/jit.dg/jit.exp index 005ba01601a..905ebe62fbd 100644 --- a/gcc/testsuite/jit.dg/jit.exp +++ b/gcc/testsuite/jit.dg/jit.exp @@ -377,6 +377,31 @@ proc dg-jit-set-exe-params { args } { } } +# For test-debuginfo.c. Starts gdb, does cmds and checks the output against match +proc jit-check-debug-info { obj_file cmds match } { +verbose "Checking debug info for $obj_file with match: $match" + +if { [catch {exec gdb -v} fid] } { +verbose "No gdb seems to be in path. Can't check debug info. Reporting 'unsupported'." +unsupported "No gdb seems to be in path. Can't check debug info" +return +} + +spawn gdb $obj_file + +foreach cmd $cmds { +send $cmd +} +expect { +-re $match { pass OK } +default { fail FAIL } +} + +# Quit gdb +send "set confirm off\n" +send "q\n" +} + proc jit-dg-test { prog do_what extra_tool_flags } { verbose "within jit-dg-test..." verbose " prog: $prog" diff --git a/gcc/testsuite/jit.dg/test-debuginfo.c b/gcc/testsuite/jit.dg/test-debuginfo.c new file mode 100644 index 000..49e8834a0ba --- /dev/null +++ b/gcc/testsuite/jit.dg/test-debuginfo.c @@ -0,0 +1,72 @@ +/* Essentially this test checks that debug info are generated for globals + locals and functions, including type info. The comment bellow is used + as fake code (does not affect the test, use for manual debugging). */ +/* +int a_global_for_test_debuginfo; +int main (int argc, char **argv) +{ +int a_local_for_test_debuginfo = 2; +return a_global_for_test_debuginfo + a_local_for_test_debuginfo; +} +*/ +#include "libgccjit.h" + +/* We don't want set_options() in harness.h to set -O3 so our little local + is optimized away. */ +#define TEST_ESCHEWS_SET_OPTIONS +static void set_options (gcc_jit_context *ctxt, const char *argv0) +{ +gcc_jit_context_set_bool_option(ctxt, GCC_JIT_BOOL_OPTION_DEBUGINFO, 1); +} + +#define TEST_COMPILING_TO_FILE +#define OUTPUT_KIND GCC_JIT_OUTPUT_KIND_EXECUTABLE +#define OUTPUT_FILENAME "jit-debuginfo.o" +#include "harness.h" + +#define LOC(row, col) gcc_jit_context_new_location(ctxt, "test-debuginfo.c", row, col) + +void +create_code (gcc_jit_context *ctxt, void* p) +{ + gcc_jit_type *int_type = gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_INT); + + gcc_jit_lvalue *bar = gcc_jit_context_new_global(ctxt, +LOC(5,1), GCC_JIT_GLOBAL_EXPORTED, +int_type, "a_global_for_test_debuginfo"); + + gcc_jit_param *argc_para = gcc_jit_context_new_param(ctxt, LOC(6,15), +int_type, "argc"); + gcc_jit_param *argv_para = gcc_jit_context_new_param(ctxt, LOC(6,28), +gcc_jit_type_get_pointer( + gcc_jit_type_get_pointer( +gcc_jit_context_get_type(ctxt, GCC_JIT_TYPE_CHAR))), +"argc"); + + gcc_jit_param *params[] = {argc_para, argv_para}; + + gcc_jit_function *foo_fn = gcc_jit_context_new_function(ctxt, LOC(6,5), +GCC_JIT_FUNCTION_EXPORTED, int_type, "main", 2, params, 0); + gcc_jit_block *start_block = gcc_jit_function_new_block(foo_fn, +"start_block"); + + gcc_jit_lvalue *a = gcc_jit_function_new_local(foo_fn, LOC(8,5), +int_type, "a_local_for_test_debuginfo"); + gcc_jit_block_add_assignment(start_block, LOC(8,36), a, +gcc_jit_context_new_rvalue_from_int(ctxt, int_type, 2)); + gcc_jit_rvalue *add = gcc_jit_context_new_binary_op(ctxt, LOC(9,40), +GCC_JIT_BINARY_OP_PLUS, int_type, +gcc_jit_lvalue_as_rvalue(a), gcc_jit_lvalue_as_rvalue(bar)); + + gcc_jit_block_end_with_return(start_block, LOC(9,5), add); +} + +#undef LOC + +/* jit-check-debug-info fires up gdb and checks that the variables have + debug info */ + +/* { dg-final { jit-check-debug-info "jit-debuginfo.o" {"info variables\n"} "int\\s+a_global_for_test_debuginfo;" } } */ +/* { dg-final { jit-check-debug-info "jit-debuginfo.o" {"pt main\n"} "int\\s*\\(\\s*int\\s*,\\s*char\\s*\\*\\*\\s*\\)"} } */ +/* { dg-final { jit-check-debug-info "jit-debuginfo.o" {"start\n" "info locals\n"} "a_local_for_test_debuginfo"} } */ +/* { dg-final { jit-check-debug-info "jit-debuginfo.o" {"start\n" "pt a_local_for_test_debuginfo\n"} "int"} } */ \ No newline at end of file -- 2.20.1
[PATCH, Fortran] Skip gfortran.dg/PR100914.f90 on targets that don't provide quadmath.h
The testcase gfortran.dg/PR100914.f90 that I recently checked in (originally written by José Rui Faustino de Sousa) depends on the header file to obtain a typedef for __complex128. It appears not to be possible to define an equivalent type in a portable way in the testcase itself (see https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Floating-Types.html) so this patch skips the test entirely on targets where quadmath.h is not available. The target-supports.exp change was cut-and-pasted from similar code in that file, but I haven't figured out how to test this change in a build that doesn't provide quadmath.h (e.g., my aarch64-linux-gnu toolchain build attempt croaked with an unrelated compilation error in glibc). Perhaps someone who previously encountered the FAILs on this testcase can confirm that it's skipped with this change? -Sandra commit 41fe3b50b3d92931fc99ef15f86cc9299e0c617e Author: Sandra Loosemore Date: Sat Sep 4 18:36:39 2021 -0700 Skip gfortran.dg/PR100914.f90 on targets that don't provide quadmath.h. This test uses the __complex128 type, which is provided by the header which may not be available on all targets. 2021-09-04 Sandra Loosemore gcc/testsuite/ * lib/target-supports.exp (check_effective_target_quadmath_h): New function. * gfortran.dg/PR100914.f90: Use it. Add comments. diff --git a/gcc/testsuite/gfortran.dg/PR100914.f90 b/gcc/testsuite/gfortran.dg/PR100914.f90 index 64b3335..aff405a 100644 --- a/gcc/testsuite/gfortran.dg/PR100914.f90 +++ b/gcc/testsuite/gfortran.dg/PR100914.f90 @@ -1,7 +1,10 @@ ! Fails on x86 targets where sizeof(long double) == 16. ! { dg-do run { xfail { { x86_64*-*-* i?86*-*-* } && longdouble128 } } } -! { dg-additional-sources PR100914.c } +! Requires Fortran support for __float128. ! { dg-require-effective-target fortran_real_c_float128 } +! Requires __complex128 type from quadmath.h. +! { dg-require-effective-target quadmath_h } +! { dg-additional-sources PR100914.c } ! ! Test the fix for PR100914 ! diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index ad8f011..072b776 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -8340,6 +8340,14 @@ proc check_effective_target_libc_has_complex_functions {} { }] } +# Return true if this target has the quadmath.h header. + +proc check_effective_target_quadmath_h {} { +return [check_no_compiler_messages quadmath_h object { + #include +}] +} + # Return 1 if # (a) an error of a few ULP is expected in string to floating-point # conversion functions; and
[committed] Improve H8/300 C bit handling
These are various minor improvements to our C bit setcc handling. First the mode of the operands being compared can be independent of the mode of the destination. This allows us to pick up a few more cases. Second, the result of an setcc can feed a negate insn. Producing -1,0 is actually cheaper for the C bit than 1,0, so clearly something we should be supporting and it happens fairly regularly. Third we can use bst, bist and rotxr to store the C bit into a variety of bit positions in the destination which allows us to combine the setcc with a subsequent left shift. I haven't really seen this with C, but I have seen it semi-regularly with Z (shifting it to the sign bit in the destination in particular). Regardless, the bits are in place to handle it for C. Overall it saves a few bytes & cycles here and there. Nothing near as effective as the initial C support. Tested without regressions. Installed on the trunk, Jeff commit b27416a7a91b7e6b6b018411ac85cad556ff9903 Author: Jeff Law Date: Sun Sep 5 00:08:34 2021 -0400 Improve handling of C bit for setcc insns gcc/ * config/h8300/h8300.md (QHSI2 mode iterator): New mode iterator. * config/h8300/testcompare.md (store_c): Update name, use new QHSI2 iterator. (store_neg_c, store_shifted_c): New patterns. diff --git a/gcc/config/h8300/h8300.md b/gcc/config/h8300/h8300.md index 89bfcf11126..e81e21b103e 100644 --- a/gcc/config/h8300/h8300.md +++ b/gcc/config/h8300/h8300.md @@ -223,6 +223,7 @@ (define_mode_iterator HSI [HI SI]) (define_mode_iterator QHSI [QI HI SI]) +(define_mode_iterator QHSI2 [QI HI SI]) (define_mode_iterator QHSIF [QI HI SI SF]) diff --git a/gcc/config/h8300/testcompare.md b/gcc/config/h8300/testcompare.md index 9ff7a51077e..0ee3e360bea 100644 --- a/gcc/config/h8300/testcompare.md +++ b/gcc/config/h8300/testcompare.md @@ -212,11 +212,96 @@ } [(set (attr "length") (symbol_ref "mode == SImode ? 6 : 4"))]) +;; Similarly, but with a negated result +(define_insn "*store_neg_c_" + [(set (match_operand:QHSI 0 "register_operand" "=r") + (neg:QHSI (ne:QHSI (reg:CCC CC_REG) (const_int 0] + "reload_completed" + { +if (mode == QImode) + return "subx\t%X0,%X0"; +else if (mode == HImode) + return "subx\t%X0,%X0\;exts.w\t%T0"; +else if (mode == SImode) + return "subx\t%X0,%X0\;exts.w\t%T0\;exts.l\t%S0"; +gcc_unreachable (); + } + [(set + (attr "length") + (symbol_ref "(mode == SImode ? 6 : mode == HImode ? 4 : 2)"))]) + +;; Using b[i]st we can store the C bit into any of the low 16 bits of +;; a destination. We can also rotate it up into the high bit of a 32 bit +;; destination. +(define_insn "*store_shifted_c" + [(set (match_operand:QHSI 0 "register_operand" "=r") + (ashift:QHSI (eqne:QHSI (reg:CCC CC_REG) (const_int 0)) +(match_operand 1 "immediate_operand" "n")))] + "(reload_completed +&& (INTVAL (operands[1]) == 31 || INTVAL (operands[1]) <= 15))" + { +if ( == NE) + { + if (mode == QImode) + return "xor.b\t%X0,%X0\;bst\t%1,%X0"; + else if (mode == HImode && INTVAL (operands[1]) < 8) + return "xor.w\t%T0,%T0\;bst\t%1,%X0"; + else if (mode == HImode) + { + operands[1] = GEN_INT (INTVAL (operands[1]) - 8); + output_asm_insn ("xor.w\t%T0,%T0\;bst\t%1,%t0", operands); + return ""; + } + else if (mode == SImode && INTVAL (operands[1]) == 31) + return "xor.l\t%S0,%S0\;rotxr.l\t%S0"; + else if (mode == SImode && INTVAL (operands[1]) < 8) + return "xor.l\t%S0,%S0\;bst\t%1,%X0"; + else if (mode == SImode) + { + operands[1] = GEN_INT (INTVAL (operands[1]) - 8); + output_asm_insn ("xor.l\t%S0,%S0\;bst\t%1,%t0", operands); + return ""; + } + gcc_unreachable (); + } +else if ( == EQ) + { + if (mode == QImode) + return "xor.b\t%X0,%X0\;bist\t%1,%X0"; + else if (mode == HImode && INTVAL (operands[1]) < 8) + return "xor.w\t%T0,%T0\;bist\t%1,%X0"; + else if (mode == HImode) + { + operands[1] = GEN_INT (INTVAL (operands[1]) - 8); + output_asm_insn ("xor.w\t%T0,%T0\;bist\t%1,%t0", operands); + return ""; + } + else if (mode == SImode && INTVAL (operands[1]) == 31) + return "xor.l\t%S0,%S0\;bixor\t#0,%X0\;rotxr.l\t%S0"; + else if (mode == SImode && INTVAL (operands[1]) < 8) + return "xor.l\t%S0,%S0\;bist\t%1,%X0"; + else if (mode == SImode) + { + operands[1] = GEN_INT (INTVAL (operands[1]) - 8); + output_asm_insn ("xor.l\t%S0,%S0\;bist\t%1,%t0", operands); + return ""; + } + gcc_unreachable (); + } +gcc_unreachable (); + } + [(set + (attr "length") + (symbol_ref "(mode == QImode ? 4 + : mode == H