Re: [PATCH] Fix typo in standard pattern name of trunc2.

2021-07-04 Thread Hongtao Liu via Gcc-patches
Hi:
  pushed to master.


Remove xfail for pr92658-avx512vl.c

Typo of standard pattern name has been fixed by r12-1970, remove those
xfails.

gcc/testsuite/ChangeLog

* gcc.target/i386/pr92658-avx512vl.c: Refine testcase.

diff --git a/gcc/testsuite/gcc.target/i386/pr92658-avx512vl.c
b/gcc/testsuite/gcc.target/i386/pr92658-avx512vl.c
index a9f7d7e6499..7ff9c19ee36 100644
--- a/gcc/testsuite/gcc.target/i386/pr92658-avx512vl.c
+++ b/gcc/testsuite/gcc.target/i386/pr92658-avx512vl.c
@@ -122,8 +122,7 @@ truncdb_128 (v16qi * dst, v4si * __restrict src)
 }

 /* { dg-final { scan-assembler-times "vpmovqd" 2 } } */
-/* { dg-final { scan-assembler-times "vpmovqw" 2 { xfail *-*-* } } } */
+/* { dg-final { scan-assembler-times "vpmovqw" 2 } } */
 /* { dg-final { scan-assembler-times "vpmovqb" 2 { xfail *-*-* } } } */
-/* { dg-final { scan-assembler-times "vpmovdw" 1 } } */
-/* { dg-final { scan-assembler-times "vpmovdw" 2 { xfail *-*-* } } } */
+/* { dg-final { scan-assembler-times "vpmovdw" 2 } } */
 /* { dg-final { scan-assembler-times "vpmovdb" 2 } } */

On Fri, Jul 2, 2021 at 4:14 PM Hongyu Wang via Gcc-patches
 wrote:
>
> This caused
>
> XPASS: gcc.target/i386/pr92658-avx512vl.c scan-assembler-times vpmovqw 2
> FAIL: gcc.target/i386/pr92658-avx512vl.c scan-assembler-times vpmovdw 1
> XPASS: gcc.target/i386/pr92658-avx512vl.c scan-assembler-times vpmovdw 2
>
> liuhongt via Gcc-patches  于2021年7月1日周四 下午3:45写道:
> >
> >   Bootstrapped and regtested on x86_64-linux-gnu{-m32,}.
> >   Pushed to trunk as abvious fix.
> >
> > gcc/ChangeLog
> >
> > * config/i386/sse.md (trunc2): Refined to ..
> > (trunc2): this.
> > ---
> >  gcc/config/i386/sse.md | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
> > index ffcc0c81964..c6be2aa144b 100644
> > --- a/gcc/config/i386/sse.md
> > +++ b/gcc/config/i386/sse.md
> > @@ -11199,12 +11199,14 @@ (define_insn_and_split 
> > "avx512vl_v8qi2_mask_store_2"
> >  (define_mode_iterator PMOV_SRC_MODE_4 [V4DI V2DI V4SI])
> >  (define_mode_attr pmov_dst_4
> >[(V4DI "V4HI") (V2DI "V2HI") (V4SI "V4HI")])
> > +(define_mode_attr pmov_dst_4_lower
> > +  [(V4DI "v4hi") (V2DI "v2hi") (V4SI "v4hi")])
> >  (define_mode_attr pmov_dst_zeroed_4
> >[(V4DI "V4HI") (V2DI "V6HI") (V4SI "V4HI")])
> >  (define_mode_attr pmov_suff_4
> >[(V4DI "qw") (V2DI "qw") (V4SI "dw")])
> >
> > -(define_expand "trunc2"
> > +(define_expand "trunc2"
> >[(set (match_operand: 0 "register_operand")
> > (truncate:
> >   (match_operand:PMOV_SRC_MODE_4 1 "register_operand")))]
> > --
> > 2.18.1
> >



-- 
BR,
Hongtao


Re: Ping: [PATCH 1/2] correct BB frequencies after loop changed

2021-07-04 Thread guojiufu via Gcc-patches

Hi Honza and All,

After more checks, I'm thinking these patches may still be useful.
For patch 1:

https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555871.html

This patch recalculates the loop's BB-count and could correct
some BB-count mismatch for loops which has a single exit.
From the test result, we could say it reduce mismatched BB-counts
slightly.

For patch 2:
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555872.html
I updated as below:
It reset the loop's probability when the loop count becomes 
unrealistically
small.  In theory, it seems this would be the right direction to do 
this.


Bootstrap/regtest on powerpc64le with no new regressions. I'm thinking 
if

this is acceptable for trunk?

BR,
Jiufu Guo

Subject: Reset edge probability and BB-count for peeled/unrolled loop

This patch fix handles the case where unrolling in an unreliable count
number can cause a loop to no longer look hot and therefore not get 
aligned.
This patch scale by profile_probability::likely () if unrolled count 
gets
unrealistically small.  And this patch fixes the COUNT/PROB of peeled 
loop.


gcc/ChangeLog:
2021-07-01  Jiufu Guo   
Pat Haugen  

PR rtl-optimization/68212
* cfgloopmanip.c (duplicate_loop_to_header_edge): Reset probablity
of unrolled/peeled loop.

testsuite/ChangeLog:
2021-07-01  Jiufu Guo   
Pat Haugen  
PR rtl-optimization/68212
* gcc.dg/pr68212.c: New test.


---
 gcc/cfgloopmanip.c | 20 ++--
 gcc/testsuite/gcc.dg/pr68212.c | 13 +
 2 files changed, 31 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr68212.c

diff --git a/gcc/cfgloopmanip.c b/gcc/cfgloopmanip.c
index 4a9ab74642c..29d858c878a 100644
--- a/gcc/cfgloopmanip.c
+++ b/gcc/cfgloopmanip.c
@@ -1258,14 +1258,30 @@ duplicate_loop_to_header_edge (class loop *loop, 
edge e,

  /* If original loop is executed COUNT_IN times, the unrolled
 loop will account SCALE_MAIN_DEN times.  */
  scale_main = count_in.probability_in (scale_main_den);
+
+ /* If we are guessing at the number of iterations and count_in
+becomes unrealistically small, reset probability.  */
+ if (!(count_in.reliable_p () || loop->any_estimate))
+   {
+	  profile_count new_count_in = count_in.apply_probability 
(scale_main);
+	  profile_count preheader_count = loop_preheader_edge 
(loop)->count ();

+ if (new_count_in.apply_scale (1, 10) < preheader_count)
+   scale_main = profile_probability::likely ();
+   }
+
  scale_act = scale_main * prob_pass_main;
}
   else
{
+ profile_count new_loop_count;
  profile_count preheader_count = e->count ();
- for (i = 0; i < ndupl; i++)
-   scale_main = scale_main * scale_step[i];
  scale_act = preheader_count.probability_in (count_in);
+ /* Compute final preheader count after peeling NDUPL copies.  */
+ for (i = 0; i < ndupl; i++)
+	preheader_count = preheader_count.apply_probability 
(scale_step[i]);

+ /* Subtract out exit(s) from peeled copies.  */
+ new_loop_count = count_in - (e->count () - preheader_count);
+ scale_main = new_loop_count.probability_in (count_in);
}
 }

diff --git a/gcc/testsuite/gcc.dg/pr68212.c 
b/gcc/testsuite/gcc.dg/pr68212.c

new file mode 100644
index 000..e0cf71d5202
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr68212.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-tree-vectorize -funroll-loops --param 
max-unroll-times=4 -fdump-rtl-alignments" } */

+
+void foo(long int *a, long int *b, long int n)
+{
+  long int i;
+
+  for (i = 0; i < n; i++)
+a[i] = *b;
+}
+
+/* { dg-final { scan-rtl-dump-times "internal loop alignment added" 1 
"alignments"} } */

+
--
2.17.1



On 2021-06-18 16:24, guojiufu via Gcc-patches wrote:

On 2021-06-15 12:57, guojiufu via Gcc-patches wrote:

On 2021-06-14 17:16, Jan Hubicka wrote:



On 5/6/2021 8:36 PM, guojiufu via Gcc-patches wrote:
> Gentle ping.
>
> Original message:
> https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555871.html
I think you need a more aggressive ping  :-)

OK for the trunk.  Sorry for the long delay.  I kept hoping someone 
else

would step in and look at it.

Sorry, the patch was on my todo list to think through for a while :(
It seems to me that both old and new code needs bit more work.  First
the exit loop frequency is set to

 prob = profile_probability::always ().apply_scale (1, new_est_niter 
+ 1);


which is only correct if the estimated number of iterations is 
accurate.
If we do not have profile feedback and trip count is not known 
precisely
in most cases it won't be.  We estimate loops to iterate about 3 
times
and then niter_for_unrolled_loop will apply the capping to 5 
iterations

that is completely arbitrary.

Forcing exit probability to 

Re: [PATCH 0/2] Initial support for AVX512FP16

2021-07-04 Thread Hongtao Liu via Gcc-patches
On Fri, Jul 2, 2021 at 4:03 PM Uros Bizjak  wrote:
>
> On Fri, Jul 2, 2021 at 8:25 AM Hongtao Liu  wrote:
>
> > > >   AVX512FP16 is disclosed, refer to [1].
> > > >   There're 100+ instructions for AVX512FP16, 67 gcc patches, for the 
> > > > convenience of review, we divide the 67 patches into 2 major parts.
> > > >   The first part is 2 patches containing basic support for AVX512FP16 
> > > > (options, cpuid, _Float16 type, libgcc, etc.), and the second part is 
> > > > 65 patches covering all instructions of AVX512FP16(including intrinsic 
> > > > support and some optimizations).
> > > >   There is a problem with the first part, _Float16 is not a C++ 
> > > > standard, so the front-end does not support this type and its mangling, 
> > > > so we "make up" a _Float16 type on the back-end and use _DF16 as its 
> > > > mangling. The purpose of this is to align with llvm side, because llvm 
> > > > C++ FE already supports _Float16[2].
> > > >
> > > > [1] 
> > > > https://software.intel.com/content/www/us/en/develop/download/intel-avx512-fp16-architecture-specification.html
> > > > [2] https://reviews.llvm.org/D33719
> > >
> > > Looking through implementation of _Float16 support, I think, there is
> > > no need for _Float16 support to depend on AVX512FP16.
> > >
> > > The compiler is smart enough to use either a named pattern that
> > > describes the instruction when available or diverts to a library call
> > > to a soft-fp implementation. So, I think that general _Float16 support
> > > should be implemented first (similar to _float128) and then upgraded
> > > with AVX512FP16 specific instructions.
> > >
> > > MOVW loads/stores to XMM reg can be emulated with MOVD and a SImode
> > > secondary_reload register.
> > >
> > MOVD is under sse2, so is pinsrw, which means if we want xmm
> > load/stores for HF, sse2 is the least requirement.
> > Also we support PEXTRW reg/m16, xmm, imm8 under SSE4_1 under which we
> > have 16bit direct load/store for HFmode and no need for a secondary
> > reload.
> > So for simplicity, can we just restrict _Float16 under sse4_1?
>
> When baseline is not met, the equivalent integer calling convention is
> used, for example:
Problem is under TARGET_SSE and w/ -mno-sse2, float calling convention
 is available for sse register, it's ok for float since there's movss
under sse, but there's no 16bit load/store for sse registers, nor
movement between gpr and sse register.
>
> --cut here--
> typedef int __v2si __attribute__ ((vector_size (8)));
>
> __v2si foo (__v2si a, __v2si b)
> {
>   return a + b;
> }
> --cut here--
>
> will still compile with -m32 -mno-mmx with warnings:
>
> mmx1.c: In function ‘foo’:
> mmx1.c:4:1: warning: MMX vector return without MMX enabled changes the
> ABI [-Wpsabi]
> mmx1.c:3:8: warning: MMX vector argument without MMX enabled changes
> the ABI [-Wpsabi]
>
> So, by setting the baseline to SSE4.1, a big pool of targets will be
> forced to use alternative ABI. This is quite inconvenient, and we
> revert to the alternative ABI if we *really*  can't satisfy ABI
> requirements (e.g. register type is not available, basic move insn
> can't be implemented). Based on your analysis, I think that SSE2
> should be the baseline.
Agreed.
>
> Also, looking at insn tables, it looks that movzwl from memory + movd
> is faster than pinsrw (and similar for pextrw to memory), but I have
> no hard data here.
>
> Regarding secondary_reload, a scratch register is needed in case of
> HImode moves between memory and XMM reg, since scratch register needs
> a different mode than source and destination. Please see
> TARGET_SECONDARY_RELOAD documentation and several examples in the
> source.
>
> Uros.



-- 
BR,
Hongtao


[PATCH] Darwin, libcc1: Handle hosts with mdynamic-no-pic support.

2021-07-04 Thread Iain Sandoe
Hi,

The default for building host-side binaries on Darwin hosts that support
mdynamic-no-pic is to enable it.  However, this is not compatible with
dynamic libraries, so must be switched off for libcc1.


OK for master?
thanks
Iain

Signed-off-by: Iain Sandoe 

libcc1/ChangeLog:

* Makefile.am: Switch mdynamic-no-pic to fPIC.
* Makefile.in: Regenerated.
---
 libcc1/Makefile.am | 1 +
 libcc1/Makefile.in | 1 +
 2 files changed, 2 insertions(+)

diff --git a/libcc1/Makefile.am b/libcc1/Makefile.am
index 9ec021030e2..49a9543ea7d 100644
--- a/libcc1/Makefile.am
+++ b/libcc1/Makefile.am
@@ -27,6 +27,7 @@ AM_CXXFLAGS = $(WARN_FLAGS) $(WERROR) $(visibility) 
$(CET_HOST_FLAGS)
 if DARWIN_DYNAMIC_LOOKUP
 AM_CXXFLAGS += -Wl,-undefined,dynamic_lookup
 endif
+override CXXFLAGS := $(subst -mdynamic-no-pic,-fPIC,$(CXXFLAGS))
 override CXXFLAGS := $(filter-out -fsanitize=address,$(CXXFLAGS))
 override LDFLAGS := $(filter-out -fsanitize=address,$(LDFLAGS))
 # Can be simplified when libiberty becomes a normal convenience library.
 
-- 
2.24.1




[PATCH] Darwin, configury : Allow for specification and detection of dsymutil.

2021-07-04 Thread Iain Sandoe
Hi,

IMO this was an omission when the dsymutil program was added
(before my time).  Essentially, we have been ‘getting away with it’
on Darwin because of (a) restrictions in DWARF versions and (b)
that the installed tools handle a wide range of platform versions and
archs.

However, (a) is a barrier to moving Darwin to DWARF-4 or greater
and (b) is no longer true for people who might build cross- toolchains
for older Darwin (or, the motiovating case, for brand new Arm64
Darwin).  In order to support necessary tests for (a) we produce a
version record that can be tested.

This replicates the logic used for ‘as’ and ‘ld’ and now correctly
reports for ‘-v’ and works with discovery of installed “binutils” in the
target dir (or for specific paths given).

tested across the Darwin range and on crosses and canadian (native)
crosses to powerpc and Arm64 darwin.  Also tested on x86_64 
and powerpc64 linux.

OK for master?
thanks
Iain

===

In order to enable DWARF versions > 2 we need a sufficiently modern
version of dsymutil (in addition to the assembler / linker).  This
allows the user to configure a different path from the installed one.

In addition, there are several sources of dsymutil so we differentiate
these in order to be get accurate version information.

Signed-off-by: Iain Sandoe 

gcc/ChangeLog:

* configure.ac: Handle --with-dsymutil in the same way as we
do for the assembler and linker.  (DEFAULT_DSYMUTIL): New.
Extract the type and version for the dsymutil configured or
found by the default searches.
* config.in: Regenerated.
* configure: Regenerated.
* collect2.c (do_dsymutil): Handle locating dsymutil in the
same way as for the assembler and  linker.
* config/darwin.h (DSYMUTIL): Delete.
* gcc.c: Report a configured dsymutil correctly.

ChangeLog:

* Makefile.def: Add dsymutil defs.
* Makefile.in: Regenerated.
* Makefile.tpl: Add dsymutil to flags.
* configure: Regenerated.
* configure.ac: Add dsymutil to target and build recipes.
---
 Makefile.def|   1 +
 Makefile.in |  10 ++
 Makefile.tpl|   9 +
 configure   | 413 
 configure.ac|   6 +
 gcc/collect2.c  |  40 -
 gcc/config.in   |  12 ++
 gcc/config/darwin.h |   2 -
 gcc/configure   | 166 +-
 gcc/configure.ac|  96 +-
 gcc/exec-tool.in|   8 +
 gcc/gcc.c   |   5 +
 12 files changed, 757 insertions(+), 11 deletions(-)

diff --git a/Makefile.def b/Makefile.def
index c83d9c4a813..fbfdb6fee08 100644
--- a/Makefile.def
+++ b/Makefile.def
@@ -291,6 +291,7 @@ flags_to_pass = { flag= CFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= CPPFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= CXXFLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= DLLTOOL_FOR_TARGET ; };
+flags_to_pass = { flag= DSYMUTIL_FOR_TARGET ; };
 flags_to_pass = { flag= FLAGS_FOR_TARGET ; };
 flags_to_pass = { flag= GFORTRAN_FOR_TARGET ; };
 flags_to_pass = { flag= GOC_FOR_TARGET ; };

diff --git a/Makefile.tpl b/Makefile.tpl
index 6e0337fb48f..bffd85bd68e 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -162,6 +162,7 @@ BUILD_EXPORTS = \
GDC="$(GDC_FOR_BUILD)"; export GDC; \
GDCFLAGS="$(GDCFLAGS_FOR_BUILD)"; export GDCFLAGS; \
DLLTOOL="$(DLLTOOL_FOR_BUILD)"; export DLLTOOL; \
+   DSYMUTIL="$(DSYMUTIL_FOR_BUILD)"; export DSYMUTIL; \
LD="$(LD_FOR_BUILD)"; export LD; \
LDFLAGS="$(LDFLAGS_FOR_BUILD)"; export LDFLAGS; \
NM="$(NM_FOR_BUILD)"; export NM; \
@@ -203,6 +204,7 @@ HOST_EXPORTS = \
CC_FOR_BUILD="$(CC_FOR_BUILD)"; export CC_FOR_BUILD; \
CXX_FOR_BUILD="$(CXX_FOR_BUILD)"; export CXX_FOR_BUILD; \
DLLTOOL="$(DLLTOOL)"; export DLLTOOL; \
+   DSYMUTIL="$(DSYMUTIL)"; export DSYMUTIL; \
LD="$(LD)"; export LD; \
LDFLAGS="$(STAGE1_LDFLAGS) $(LDFLAGS)"; export LDFLAGS; \
NM="$(NM)"; export NM; \
@@ -215,6 +217,7 @@ HOST_EXPORTS = \
READELF="$(READELF)"; export READELF; \
AR_FOR_TARGET="$(AR_FOR_TARGET)"; export AR_FOR_TARGET; \
AS_FOR_TARGET="$(AS_FOR_TARGET)"; export AS_FOR_TARGET; \
+   DSYMUTIL_FOR_TARGET="$(DSYMUTIL_FOR_TARGET)"; export 
DSYMUTIL_FOR_TARGET; \
GCC_FOR_TARGET="$(GCC_FOR_TARGET)"; export GCC_FOR_TARGET; \
LD_FOR_TARGET="$(LD_FOR_TARGET)"; export LD_FOR_TARGET; \
NM_FOR_TARGET="$(NM_FOR_TARGET)"; export NM_FOR_TARGET; \
@@ -297,6 +300,7 @@ BASE_TARGET_EXPORTS = \
GOC="$(GOC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GOC; \
GDC="$(GDC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export GDC; \
DLLTOOL="$(DLLTOOL_FOR_TARGET)"; export DLLTOOL; \
+   DSYMUTIL="$(DSYMUTIL_FOR_TARGET)"; export DSYMUTIL; \
LD="$(COMPILER_LD_FOR_TARGET)"; export LD; \
LDFLAGS="$(LDFLAGS_FOR_TARGET)"; export LDFLAGS; \

[PATCH] Darwini, X86: Adjust call clobbers to allow for lazy-binding [PR100152].

2021-07-04 Thread Iain Sandoe
Hi,

(I’m not going to defend the status quo here, it seems a bit prone
 to confusing a user [different interposition behaviour between the
 inlined and non-inlined cases] however, this is what the platform
 compilers implement).



We allow public functions defined in a TU to bind locally for PIC
code (the default) on 64bit Mach-O.

If such functions are not inlined, we cannot tell at compile-time if
they might be called via the lazy symbol resolver (this can depend on
options given at link-time).  Therefore, we must assume that the lazy
resolver could be used which clobbers R11 and R10.

The solution here is similar in form to the one used for veneer regs
on Arm (but I’m open to alternate suggestions).

tested on X86_64-darwin, linux
OK for master?
Iain

Signed-off-by: Iain Sandoe 

PR target/100152 - [10/11/12 Regression] used caller-saved register not 
preserved across a call.

PR target/100152

gcc/ChangeLog:

* config/i386/i386-expand.c (ix86_expand_call): If a call is
to a non-local-binding, or local but to a public symbol, then
assume that it might be indirected via the lazy symbol binder.
Mark R10 and R10 as clobbered in that case.
---
 gcc/config/i386/i386-expand.c | 16 +++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index b37642e35ee..1b860e027b0 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -8380,6 +8380,7 @@ ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
 pop = NULL;
   gcc_assert (!TARGET_64BIT || !pop);
 
+  rtx addr = XEXP (fnaddr, 0);
   if (TARGET_MACHO && !TARGET_64BIT)
 {
 #if TARGET_MACHO
@@ -8392,7 +8393,6 @@ ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
   /* Static functions and indirect calls don't need the pic register.  
Also,
 check if PLT was explicitly avoided via no-plt or "noplt" attribute, 
making
 it an indirect call.  */
-  rtx addr = XEXP (fnaddr, 0);
   if (flag_pic
  && GET_CODE (addr) == SYMBOL_REF
  && !SYMBOL_REF_LOCAL_P (addr))
@@ -8555,6 +8555,20 @@ ix86_expand_call (rtx retval, rtx fnaddr, rtx callarg1,
}
 }
 
+  if (TARGET_MACHO && TARGET_64BIT && !sibcall
+  && ((GET_CODE (addr) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (addr))
+ || !fndecl || TREE_PUBLIC (fndecl)))
+{
+  /* We allow public functions defined in a TU to bind locally for PIC
+code (the default) on 64bit Mach-O.
+If such functions are not inlined, we cannot tell at compile-time if
+they will be called via the lazy symbol resolver (this can depend on
+options given at link-time).  Therefore, we must assume that the lazy
+resolver could be used which clobbers R11 and R10.  */
+  clobber_reg (, gen_rtx_REG (DImode, R11_REG));
+  clobber_reg (, gen_rtx_REG (DImode, R10_REG));
+}
+
   if (vec_len > 1)
 call = gen_rtx_PARALLEL (VOIDmode, gen_rtvec_v (vec_len, vec));
   rtx_insn *call_insn = emit_call_insn (call);
-- 
2.24.1



[PATCH] X86: Provide a CTOR for stringop_algs [PR100246].

2021-07-04 Thread Iain Sandoe
Hi,

Several older compilers fail to build modern GCC because of missing
or incomplete C++11 support.

(although the PR mentions clang, specifically, this has also been reported
 for some GCC versions within the range that should be able to bootstrap
 GCC)

There are several possible solutions proposed in the PR, this one seems
 the least invasive.

The header is pulled into the gcov code that builds with C, so we have to
make the CTOR conditional on C++.

tested on Darwin12 with xcode-6, bootstrapped on x86_64-darwin and linux.
OK for master / GCC-11?
thanks
Iain

Signed-off-by: Iain Sandoe 

PR bootstrap/100246 - [11/12 Regression] GCC will not bootstrap with clang 
3.4/3.5 [xcode 5/6, Darwin 12/13]

PR bootstrap/100246

gcc/ChangeLog:

* config/i386/i386.h (struct stringop_algs): Define a CTOR for
this type.
---
 gcc/config/i386/i386.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 6e0340a4b60..84151156999 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -73,6 +73,11 @@ struct stringop_algs
 {
   const enum stringop_alg unknown_size;
   const struct stringop_strategy {
+#ifdef __cplusplus
+stringop_strategy(int _max = -1, enum stringop_alg _alg = libcall,
+ int _noalign = false)
+  : max (_max), alg (_alg), noalign (_noalign) {}
+#endif
 const int max;
 const enum stringop_alg alg;
 int noalign;
-- 
2.24.1




[pushed] Darwin, config : Adjust X86 biarch definitions ordering [PR100269].

2021-07-04 Thread Iain Sandoe
Hi

This reorganises the biarch definitions to cater for the
macro changes and removals at r12-36.

tested across the Darwin range,
pushed to master, thanks
Iain

Signed-off-by: Iain Sandoe 

PR target/100269 - [12 Regression] i686 biarch compiler fails for Darwin after 
r12-36.

PR target/100269

gcc/ChangeLog:

PR target/100269
* config.gcc: Ensure that Darwin biarch definitions are
added before i386.h.
* config/i386/darwin.h (TARGET_64BIT): Remove.
(PR80556_WORKAROUND): New.
(REAL_LIBGCC_SPEC): Amend to use PR80556_WORKAROUND.
(DARWIN_SUBARCH_SPEC): New.
* config/i386/darwin32-biarch.h (TARGET_64BIT_DEFAULT,
TARGET_BI_ARCH, PR80556_WORKAROUND): New.
(REAL_LIBGCC_SPEC): Remove.
* config/i386/darwin64-biarch.h (TARGET_64BIT_DEFAULT,
TARGET_BI_ARCH, PR80556_WORKAROUND): New.
(REAL_LIBGCC_SPEC): Remove.
---
 gcc/config.gcc| 10 +++---
 gcc/config/i386/darwin.h  | 22 ++
 gcc/config/i386/darwin32-biarch.h | 22 ++
 gcc/config/i386/darwin64-biarch.h | 22 ++
 4 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/gcc/config.gcc b/gcc/config.gcc
index 0230bb88861..f3e94f7c0d8 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -591,6 +591,8 @@ i[34567]86-*-*)
exit 1
fi
;;
+x86_64-*-darwin*)
+   ;;
 x86_64-*-*)
case ${with_abi} in
"")
@@ -1837,7 +1839,7 @@ hppa[12]*-*-hpux11*)
dwarf2=no
fi
;;
-i[34567]86-*-darwin1[89]*)
+i[34567]86-*-darwin1[89]* | i[34567]86-*-darwin2[0-9]*)
echo "Error: 32bit target is not supported after Darwin17" 1>&2
;;
 i[34567]86-*-darwin*)
@@ -1845,17 +1847,19 @@ i[34567]86-*-darwin*)
# Baseline choice for a machine that allows m64 support.
with_cpu=${with_cpu:-core2}
tmake_file="${tmake_file} ${cpu_type}/t-darwin32-biarch t-slibgcc"
-   tm_file="${tm_file} ${cpu_type}/darwin32-biarch.h"
+   tm_file="${cpu_type}/darwin32-biarch.h ${tm_file} "
;;
 x86_64-*-darwin1[89]* | x86_64-*-darwin2[01]*)
# Only 64b from now
+   tm_defines="${tm_defines} 
TARGET_64BIT_DEFAULT=(OPTION_MASK_ISA_64BIT|OPTION_MASK_ABI_64)"
+   tm_defines="${tm_defines} TARGET_BI_ARCH=0"
with_cpu=${with_cpu:-core2}
tmake_file="${tmake_file} t-slibgcc"
;;
 x86_64-*-darwin*)
with_cpu=${with_cpu:-core2}
tmake_file="${tmake_file} ${cpu_type}/t-darwin64-biarch t-slibgcc"
-   tm_file="${tm_file} ${cpu_type}/darwin64-biarch.h"
+   tm_file="${cpu_type}/darwin64-biarch.h ${tm_file} "
;;
 i[34567]86-*-elfiamcu)
tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h 
newlib-stdint.h i386/iamcu.h"
diff --git a/gcc/config/i386/darwin.h b/gcc/config/i386/darwin.h
index 5312003a321..bac32197e83 100644
--- a/gcc/config/i386/darwin.h
+++ b/gcc/config/i386/darwin.h
@@ -25,15 +25,6 @@ along with GCC; see the file COPYING3.  If not see
 #undef DARWIN_X86
 #define DARWIN_X86 1
 
-#ifdef IN_LIBGCC2
-#undef TARGET_64BIT
-#ifdef __x86_64__
-#define TARGET_64BIT 1
-#else
-#define TARGET_64BIT 0
-#endif
-#endif
-
 /* WORKAROUND pr80556:
For x86_64 Darwin10 and later, the unwinder is in libunwind (redirected
from libSystem).  This doesn't use the keymgr (see keymgr.c) and therefore
@@ -44,11 +35,15 @@ along with GCC; see the file COPYING3.  If not see
even when static-libgcc is specified.  We put libSystem first so that
unwinder symbols are satisfied from there.
We default to 64b for single-arch builds, so apply this unconditionally. */
+#ifndef PR80556_WORKAROUND
+#define PR80556_WORKAROUND \
+" %:version-compare(>= 10.6 mmacosx-version-min= -lSystem) "
+#endif
 #undef REAL_LIBGCC_SPEC
 #define REAL_LIBGCC_SPEC  \
-   "%{static-libgcc|static:   \
-   %:version-compare(>= 10.6 mmacosx-version-min= -lSystem)
   \
-   -lgcc_eh -lgcc;\
+   "%{static-libgcc|static: " \
+   PR80556_WORKAROUND \
+  " -lgcc_eh -lgcc;
   \
   shared-libgcc|fexceptions|fgnu-runtime: \
%:version-compare(!> 10.5 mmacosx-version-min= -lgcc_s.10.4)   \
%:version-compare(>< 10.5 10.6 mmacosx-version-min= -lgcc_s.10.5)   \
@@ -142,8 +137,11 @@ along with GCC; see the file COPYING3.  If not see
%{mpc64:crtprec64.o%s} \
%{mpc80:crtprec80.o%s}" TM_DESTRUCTOR
 
+#ifndef DARWIN_ARCH_SPEC
 /* We default to x86_64 for single-arch builds, bi-arch overrides.  */
 #define DARWIN_ARCH_SPEC "x86_64"
+#define DARWIN_SUBARCH_SPEC DARWIN_ARCH_SPEC
+#endif
 
 #undef 

[PATCH 5/5] Port most of the A CMP 0 ? A : -A to match

2021-07-04 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

To improve phiopt and be able to remove abs_replacement, this ports
most of "A CMP 0 ? A : -A" from fold_cond_expr_with_comparison to
match.pd.  There is a few extra changes that are needed to remove
the "A CMP 0 ? A : -A" part from fold_cond_expr_with_comparison:
   * Need to handle (A - B) case
   * Need to handle UN* comparisons.

I will handle those in a different patch.

Note phi-opt-15.c test needed to be updated as we get ABSU now
instead of not getting ABS.  When ABSU was added phiopt was not
updated even to use ABSU instead of not creating ABS.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

PR tree-optimization/101039
* match.pd (A CMP 0 ? A : -A): New patterns.
* tree-ssa-phiopt.c (abs_replacement): Delete function.
(tree_ssa_phiopt_worker): Don't call abs_replacement.
Update comment about abs_replacement.

gcc/testsuite/ChangeLog:

PR tree-optimization/101039
* gcc.dg/tree-ssa/phi-opt-15.c: Update test to expect
ABSU and still not expect ABS_EXPR.
* gcc.dg/tree-ssa/phi-opt-23.c: New test.
* gcc.dg/tree-ssa/phi-opt-24.c: New test.
---
 gcc/match.pd   |  60 +
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c |   4 +-
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c |  44 +++
 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c |  44 +++
 gcc/tree-ssa-phiopt.c  | 134 +
 5 files changed, 152 insertions(+), 134 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-24.c

diff --git a/gcc/match.pd b/gcc/match.pd
index 4e10d54383c..72860fbd448 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3976,6 +3976,66 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (cnd (logical_inverted_value truth_valued_p@0) @1 @2)
   (cnd @0 @2 @1)))
 
+/* abs/negative simplifications moved from fold_cond_expr_with_comparison,
+   Need to handle (A - B) case as fold_cond_expr_with_comparison does.
+   Need to handle UN* comparisons.
+
+   None of these transformations work for modes with signed
+   zeros.  If A is +/-0, the first two transformations will
+   change the sign of the result (from +0 to -0, or vice
+   versa).  The last four will fix the sign of the result,
+   even though the original expressions could be positive or
+   negative, depending on the sign of A.
+
+   Note that all these transformations are correct if A is
+   NaN, since the two alternatives (A and -A) are also NaNs.  */
+
+(for cnd (cond vec_cond)
+ /* A == 0 ? A : -Asame as -A */
+ (for cmp (eq uneq)
+  (simplify
+   (cnd (cmp @0 zerop) @0 (negate@1 @0))
+(if (!HONOR_SIGNED_ZEROS (type))
+ @1))
+  (simplify
+   (cnd (cmp @0 zerop) integer_zerop (negate@1 @0))
+(if (!HONOR_SIGNED_ZEROS (type))
+ @1))
+ )
+ /* A != 0 ? A : -Asame as A */
+ (for cmp (ne ltgt)
+  (simplify
+   (cnd (cmp @0 zerop) @0 (negate @0))
+(if (!HONOR_SIGNED_ZEROS (type))
+ @0))
+  (simplify
+   (cnd (cmp @0 zerop) @0 integer_zerop)
+(if (!HONOR_SIGNED_ZEROS (type))
+ @0))
+ )
+ /* A >=/> 0 ? A : -Asame as abs (A) */
+ (for cmp (ge gt)
+  (simplify
+   (cnd (cmp @0 zerop) @0 (negate @0))
+(if (!HONOR_SIGNED_ZEROS (type)
+&& !TYPE_UNSIGNED (type))
+ (abs @0
+ /* A <=/< 0 ? A : -Asame as -abs (A) */
+ (for cmp (le lt)
+  (simplify
+   (cnd (cmp @0 zerop) @0 (negate @0))
+(if (!HONOR_SIGNED_ZEROS (type)
+&& !TYPE_UNSIGNED (type))
+ (if (ANY_INTEGRAL_TYPE_P (type)
+ && !TYPE_OVERFLOW_WRAPS (type))
+  (with {
+   tree utype = unsigned_type_for (type);
+   }
+   (convert (negate (absu:utype @0
+   (negate (abs @0)
+ )
+)
+
 /* -(type)!A -> (type)A - 1.  */
 (simplify
  (negate (convert?:s (logical_inverted_value:s @0)))
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c 
b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c
index ac3018ef533..6aec68961cf 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-15.c
@@ -9,4 +9,6 @@ foo (int i)
   return i;
 }
 
-/* { dg-final { scan-tree-dump-not "ABS" "optimized" } } */
+/* We should not have ABS_EXPR but ABSU_EXPR instead. */
+/* { dg-final { scan-tree-dump-not "ABS_EXPR" "optimized" } } */
+/* { dg-final { scan-tree-dump "ABSU" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c 
b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c
new file mode 100644
index 000..ff658cd16a7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-23.c
@@ -0,0 +1,44 @@
+/* { dg-options "-O2 -fdump-tree-phiopt" } */
+
+int f0(int A)
+{
+// A == 0? A : -Asame as -A
+  if (A == 0)  return A;
+  return -A;
+}
+
+int f1(int A)
+{
+// A != 0? A : -Asame as A
+  if (A != 0)  return A;
+  return -A;
+}
+int f2(int A)
+{
+// A >= 0? A : -Asame as abs (A)
+  if (A >= 0)  return 

[PATCH 3/5] Allow match-and-simplified phiopt to run in early phiopt

2021-07-04 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

To move a few things more to match-and-simplify from phiopt,
we need to allow match_simplify_replacement to run in early
phiopt. To do this we add a replacement for gimple_simplify
that is explictly for phiopt.

OK? Bootstrapped and tested on x86_64-linux-gnu with no
regressions.

gcc/ChangeLog:

* tree-ssa-phiopt.c (match_simplify_replacement):
Add early_p argument. Call gimple_simplify_phiopt
instead of gimple_simplify.
(tree_ssa_phiopt_worker): Update call to
match_simplify_replacement and allow unconditionally.
(phiopt_early_allow): New function.
(gimple_simplify_phiopt): New function.
---
 gcc/tree-ssa-phiopt.c | 89 ++-
 1 file changed, 70 insertions(+), 19 deletions(-)

diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index 71f0019d877..d4449afcdca 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -50,13 +50,14 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "internal-fn.h"
 #include "gimple-range.h"
+#include "gimple-match.h"
 #include "dbgcnt.h"
 
 static unsigned int tree_ssa_phiopt_worker (bool, bool, bool);
 static bool two_value_replacement (basic_block, basic_block, edge, gphi *,
   tree, tree);
 static bool match_simplify_replacement (basic_block, basic_block,
-   edge, edge, gphi *, tree, tree);
+   edge, edge, gphi *, tree, tree, bool);
 static gphi *factor_out_conditional_conversion (edge, edge, gphi *, tree, tree,
gimple *);
 static int value_replacement (basic_block, basic_block,
@@ -347,9 +348,9 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool 
do_hoist_loads, bool early_p)
  /* Do the replacement of conditional if it can be done.  */
  if (!early_p && two_value_replacement (bb, bb1, e2, phi, arg0, arg1))
cfgchanged = true;
- else if (!early_p
-  && match_simplify_replacement (bb, bb1, e1, e2, phi,
- arg0, arg1))
+ else if (match_simplify_replacement (bb, bb1, e1, e2, phi,
+  arg0, arg1,
+  early_p))
cfgchanged = true;
  else if (abs_replacement (bb, bb1, e1, e2, phi, arg0, arg1))
cfgchanged = true;
@@ -819,6 +820,67 @@ two_value_replacement (basic_block cond_bb, basic_block 
middle_bb,
   return true;
 }
 
+/* Return TRUE if CODE should be allowed during early phiopt.
+   Currently this is to allow MIN/MAX and ABS/NEGATE.  */
+static bool
+phiopt_early_allow (enum tree_code code)
+{
+  switch (code)
+{
+  case MIN_EXPR:
+  case MAX_EXPR:
+  case ABS_EXPR:
+  case ABSU_EXPR:
+  case NEGATE_EXPR:
+  case SSA_NAME:
+   return true;
+  default:
+   return false;
+}
+}
+
+/* gimple_simplify_phiopt is like gimple_simplify but designed for PHIOPT.
+   Return NULL if nothing can be simplified or the resulting simplified value
+   with parts pushed if EARLY_P was true. Also rejects non allowed tree code
+   if EARLY_P is set.
+   Takes the comparison from COMP_STMT and two args, ARG0 and ARG1 and tries
+   to simplify CMP ? ARG0 : ARG1.  */
+static tree
+gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt,
+   tree arg0, tree arg1,
+   gimple_seq *seq)
+{
+  tree result;
+  enum tree_code comp_code = gimple_cond_code (comp_stmt);
+  location_t loc = gimple_location (comp_stmt);
+  tree cmp0 = gimple_cond_lhs (comp_stmt);
+  tree cmp1 = gimple_cond_rhs (comp_stmt);
+  /* To handle special cases like floating point comparison, it is easier and
+ less error-prone to build a tree and gimplify it on the fly though it is
+ less efficient.
+ Don't use fold_build2 here as that might create (bool)a instead of just
+ "a != 0".  */
+  tree cond = build2_loc (loc, comp_code, boolean_type_node,
+ cmp0, cmp1);
+  gimple_match_op op (gimple_match_cond::UNCOND,
+ COND_EXPR, type, cond, arg0, arg1);
+
+  if (op.resimplify (early_p ? NULL : seq, follow_all_ssa_edges))
+{
+  /* Early we want only to allow some generated tree codes. */
+  if (!early_p
+ || op.code.is_tree_code ()
+ || phiopt_early_allow ((tree_code)op.code))
+   {
+ result = maybe_push_res_to_seq (, seq);
+ if (result)
+   return result;
+   }
+}
+
+  return NULL;
+}
+
 /*  The function match_simplify_replacement does the main work of doing the
 replacement using match and simplify.  Return true if the replacement is 
done.
 Otherwise return false.
@@ -828,10 +890,9 @@ two_value_replacement (basic_block cond_bb, basic_block 
middle_bb,
 static bool
 

[PATCH 1/5] Fix 101256: Wrong code due to range incorrect from PHI-OPT

2021-07-04 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

So the problem here is that replace_phi_edge_with_variable
will copy range information to a already (not newly) defined
ssa name.  This causes wrong code later on.
This patch fixes the problem by requiring there to be statements
that are to be placed before the conditional to be able to
copy the range info; this assumes the statements will define
the ssa name.

gcc/ChangeLog:

PR tree-optimization/101256
* dbgcnt.def (phiopt_edge_range): New counter.
* tree-ssa-phiopt.c (replace_phi_edge_with_variable):
Add optional sequence which will be added before the old
conditional. Check sequence for non-null if we want to
update the range.
(two_value_replacement): Instead of inserting the sequence,
update the call to replace_phi_edge_with_variable.
(match_simplify_replacement): Likewise.
(minmax_replacement): Likewise.
(value_replacement): Create a sequence of statements
which would have defined the ssa name.  Update call
to replace_phi_edge_with_variable.

gcc/testsuite/ChangeLog:

PR tree-optimization/101256
* g++.dg/torture/pr101256.C: New test.
---
 gcc/dbgcnt.def  |  1 +
 gcc/testsuite/g++.dg/torture/pr101256.C | 28 +
 gcc/tree-ssa-phiopt.c   | 52 ++---
 3 files changed, 59 insertions(+), 22 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/torture/pr101256.C

diff --git a/gcc/dbgcnt.def b/gcc/dbgcnt.def
index 93e7b4fd30e..2345899ba68 100644
--- a/gcc/dbgcnt.def
+++ b/gcc/dbgcnt.def
@@ -183,6 +183,7 @@ DEBUG_COUNTER (lim)
 DEBUG_COUNTER (local_alloc_for_sched)
 DEBUG_COUNTER (match)
 DEBUG_COUNTER (merged_ipa_icf)
+DEBUG_COUNTER (phiopt_edge_range)
 DEBUG_COUNTER (postreload_cse)
 DEBUG_COUNTER (pre)
 DEBUG_COUNTER (pre_insn)
diff --git a/gcc/testsuite/g++.dg/torture/pr101256.C 
b/gcc/testsuite/g++.dg/torture/pr101256.C
new file mode 100644
index 000..973a8b4caf3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/torture/pr101256.C
@@ -0,0 +1,28 @@
+// { dg-do run }
+
+template 
+const T& max(const T& a, const T& b)
+{
+return (a < b) ? b : a;
+}
+
+signed char var_5 = -128;
+unsigned int var_11 = 2144479212U;
+unsigned long long int arr [22];
+
+void
+__attribute__((noipa))
+test(signed char var_5, unsigned var_11) {
+  for (short i_61 = 0; i_61 < var_5 + 149; i_61 += 1)
+arr[i_61] = max((signed char)0, var_5) ? max((signed char)1, var_5) : 
var_11;
+}
+
+int main() {
+  for (int i_0 = 0; i_0 < 22; ++i_0) 
+  arr [i_0] = 11834725929543695741ULL;
+
+  test(var_5, var_11);
+  if (arr [0] != 2144479212ULL && arr [0] != 11834725929543695741ULL)
+__builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index ab12e85569d..71f0019d877 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "internal-fn.h"
 #include "gimple-range.h"
+#include "dbgcnt.h"
 
 static unsigned int tree_ssa_phiopt_worker (bool, bool, bool);
 static bool two_value_replacement (basic_block, basic_block, edge, gphi *,
@@ -73,7 +74,8 @@ static bool cond_store_replacement (basic_block, basic_block, 
edge, edge,
hash_set *);
 static bool cond_if_else_store_replacement (basic_block, basic_block, 
basic_block);
 static hash_set * get_non_trapping ();
-static void replace_phi_edge_with_variable (basic_block, edge, gphi *, tree);
+static void replace_phi_edge_with_variable (basic_block, edge, gphi *, tree,
+   gimple_seq = NULL);
 static void hoist_adjacent_loads (basic_block, basic_block,
  basic_block, basic_block);
 static bool gate_hoist_loads (void);
@@ -382,18 +384,20 @@ tree_ssa_phiopt_worker (bool do_store_elim, bool 
do_hoist_loads, bool early_p)
 
 /* Replace PHI node element whose edge is E in block BB with variable NEW.
Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK
-   is known to have two edges, one of which must reach BB).  */
+   is known to have two edges, one of which must reach BB).
+   Optionally insert stmts before the old condition.  */
 
 static void
 replace_phi_edge_with_variable (basic_block cond_block,
-   edge e, gphi *phi, tree new_tree)
+   edge e, gphi *phi, tree new_tree,
+   gimple_seq stmts)
 {
   basic_block bb = gimple_bb (phi);
   basic_block block_to_remove;
   gimple_stmt_iterator gsi;
   tree phi_result = PHI_RESULT (phi);
 
-  /* Duplicate range info if we're the only things setting the target PHI.
+  /* Duplicate range info if they are the only things setting the target PHI.
  This is needed as later on, the new_tree will be replacing
  The assignement of the PHI.
  For an example:
@@ -401,19 +405,23 

[PATCH 2/5] Fix PR 101237: Remove element_type call when used with the functions from real

2021-07-04 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

HONOR_SIGNED_ZEROS, HONOR_SIGN_DEPENDENT_ROUNDING, and HONOR_SNANS all
have an overload for taking a tree type now, so we should do that instead.

OK?  Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

PR middle-end/101237
* fold-const.c (negate_expr_p): Remove call to element_mode
and TREE_MODE/TREE_TYPE when calling HONOR_SIGNED_ZEROS,
HONOR_SIGN_DEPENDENT_ROUNDING, and HONOR_SNANS.
(fold_negate_expr_1): Likewise.
(const_unop): Likewise.
(fold_cond_expr_with_comparison): Likewise.
(fold_binary_loc): Likewise.
(fold_ternary_loc): Likewise.
(tree_call_nonnegative_warnv_p): Likewise.
* match.pd (-(A + B) -> (-B) - A): Likewise.
---
 gcc/fold-const.c | 46 +++---
 gcc/match.pd |  4 ++--
 2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index dfccbaec683..e0cdb75fb26 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -432,8 +432,8 @@ negate_expr_p (tree t)
   return negate_expr_p (TREE_OPERAND (t, 0));
 
 case PLUS_EXPR:
-  if (HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
- || HONOR_SIGNED_ZEROS (element_mode (type))
+  if (HONOR_SIGN_DEPENDENT_ROUNDING (type)
+ || HONOR_SIGNED_ZEROS (type)
  || (ANY_INTEGRAL_TYPE_P (type)
  && ! TYPE_OVERFLOW_WRAPS (type)))
return false;
@@ -445,8 +445,8 @@ negate_expr_p (tree t)
 
 case MINUS_EXPR:
   /* We can't turn -(A-B) into B-A when we honor signed zeros.  */
-  return !HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
-&& !HONOR_SIGNED_ZEROS (element_mode (type))
+  return !HONOR_SIGN_DEPENDENT_ROUNDING (type)
+&& !HONOR_SIGNED_ZEROS (type)
 && (! ANY_INTEGRAL_TYPE_P (type)
 || TYPE_OVERFLOW_WRAPS (type));
 
@@ -468,7 +468,7 @@ negate_expr_p (tree t)
   /* Fall through.  */
 
 case RDIV_EXPR:
-  if (! HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (TREE_TYPE (t
+  if (! HONOR_SIGN_DEPENDENT_ROUNDING (t))
return negate_expr_p (TREE_OPERAND (t, 1))
   || negate_expr_p (TREE_OPERAND (t, 0));
   break;
@@ -605,8 +605,8 @@ fold_negate_expr_1 (location_t loc, tree t)
   break;
 
 case PLUS_EXPR:
-  if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
- && !HONOR_SIGNED_ZEROS (element_mode (type)))
+  if (!HONOR_SIGN_DEPENDENT_ROUNDING (type)
+ && !HONOR_SIGNED_ZEROS (type))
{
  /* -(A + B) -> (-B) - A.  */
  if (negate_expr_p (TREE_OPERAND (t, 1)))
@@ -628,8 +628,8 @@ fold_negate_expr_1 (location_t loc, tree t)
 
 case MINUS_EXPR:
   /* - (A - B) -> B - A  */
-  if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
- && !HONOR_SIGNED_ZEROS (element_mode (type)))
+  if (!HONOR_SIGN_DEPENDENT_ROUNDING (type)
+ && !HONOR_SIGNED_ZEROS (type))
return fold_build2_loc (loc, MINUS_EXPR, type,
TREE_OPERAND (t, 1), TREE_OPERAND (t, 0));
   break;
@@ -641,7 +641,7 @@ fold_negate_expr_1 (location_t loc, tree t)
   /* Fall through.  */
 
 case RDIV_EXPR:
-  if (! HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type)))
+  if (! HONOR_SIGN_DEPENDENT_ROUNDING (type))
{
  tem = TREE_OPERAND (t, 1);
  if (negate_expr_p (tem))
@@ -1725,7 +1725,7 @@ const_unop (enum tree_code code, tree type, tree arg0)
   /* Don't perform the operation, other than NEGATE and ABS, if
  flag_signaling_nans is on and the operand is a signaling NaN.  */
   if (TREE_CODE (arg0) == REAL_CST
-  && HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg0)))
+  && HONOR_SNANS (arg0)
   && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg0))
   && code != NEGATE_EXPR
   && code != ABS_EXPR
@@ -2135,7 +2135,7 @@ fold_convert_const_real_from_real (tree type, const_tree 
arg1)
 
   /* Don't perform the operation if flag_signaling_nans is on
  and the operand is a signaling NaN.  */
-  if (HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1)))
+  if (HONOR_SNANS (arg1)
   && REAL_VALUE_ISSIGNALING_NAN (TREE_REAL_CST (arg1)))
 return NULL_TREE; 
 
@@ -5773,7 +5773,7 @@ fold_cond_expr_with_comparison (location_t loc, tree type,
 
  Note that all these transformations are correct if A is
  NaN, since the two alternatives (A and -A) are also NaNs.  */
-  if (!HONOR_SIGNED_ZEROS (element_mode (type))
+  if (!HONOR_SIGNED_ZEROS (type)
   && (FLOAT_TYPE_P (TREE_TYPE (arg01))
  ? real_zerop (arg01)
  : integer_zerop (arg01))
@@ -5842,7 +5842,7 @@ fold_cond_expr_with_comparison (location_t loc, tree type,
  both transformations are correct when A is NaN: A != 0
  is then true, and A == 0 is false.  */
 
-  if (!HONOR_SIGNED_ZEROS (element_mode (type))
+  if (!HONOR_SIGNED_ZEROS (type)
   && integer_zerop (arg01) && 

[PATCH 4/5] Try inverted comparison for match_simplify in phiopt

2021-07-04 Thread apinski--- via Gcc-patches
From: Andrew Pinski 

Since match and simplify does not have all of the inverted
comparison patterns, it make sense to just have
phi-opt try to do the inversion and try match and simplify again.

OK? Bootstrapped and tested on x86_64-linux-gnu.

Thanks,
Andrew Pinski

gcc/ChangeLog:

* tree-ssa-phiopt.c (gimple_simplify_phiopt):
If "A ? B : C" fails to simplify, try "(!A) ? C : B".
---
 gcc/tree-ssa-phiopt.c | 27 ++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index d4449afcdca..fec8c02c062 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -844,7 +844,8 @@ phiopt_early_allow (enum tree_code code)
with parts pushed if EARLY_P was true. Also rejects non allowed tree code
if EARLY_P is set.
Takes the comparison from COMP_STMT and two args, ARG0 and ARG1 and tries
-   to simplify CMP ? ARG0 : ARG1.  */
+   to simplify CMP ? ARG0 : ARG1.
+   Also try to simplify (!CMP) ? ARG1 : ARG0 if the non-inverse failed.  */
 static tree
 gimple_simplify_phiopt (bool early_p, tree type, gimple *comp_stmt,
tree arg0, tree arg1,
@@ -877,6 +878,30 @@ gimple_simplify_phiopt (bool early_p, tree type, gimple 
*comp_stmt,
return result;
}
 }
+  /* Try the inverted comparison, that is !COMP ? ARG1 : ARG0. */
+  comp_code = invert_tree_comparison (comp_code, HONOR_NANS (cmp0));
+
+  if (comp_code == ERROR_MARK)
+return NULL;
+
+  cond = build2_loc (loc,
+comp_code, boolean_type_node,
+cmp0, cmp1);
+  gimple_match_op op1 (gimple_match_cond::UNCOND,
+  COND_EXPR, type, cond, arg1, arg0);
+
+  if (op1.resimplify (early_p ? NULL : seq, follow_all_ssa_edges))
+{
+  /* Early we want only to allow some generated tree codes. */
+  if (!early_p
+ || op1.code.is_tree_code ()
+ || phiopt_early_allow ((tree_code)op1.code))
+   {
+ result = maybe_push_res_to_seq (, seq);
+ if (result)
+   return result;
+   }
+}
 
   return NULL;
 }
-- 
2.27.0



Re: [PATCH] rs6000: Add MMA __builtin_vsx_lxvp and __builtin_vsx_stxvp built-ins

2021-07-04 Thread Bill Schmidt via Gcc-patches

Hi Peter,

On 7/1/21 2:48 PM, Peter Bergner via Gcc-patches wrote:

gcc/
* config/rs6000/rs6000-builtin.def (BU_MMA_PAIR_LD, BU_MMA_PAIR_ST):
New macros.
(__builtin_vsx_lxvp, __builtin_vsx_stxvp): New built-ins.
* config/rs6000/rs6000-call.c (rs6000_gimple_fold_mma_builtin): Expand
lxvp and stxvp built-ins.
(mma_init_builtins): Handle lxvp and stxvp built-ins.
(builtin_function_type): Likewise.
* doc/extend.texi (__builtin_vsx_lxvp, __builtin_mma_stxvp): Document.

gcc/testsuite/
* gcc.target/powerpc/mma-builtin-7.c: New test.
* gcc.target/powerpc/mma-builtin-8.c: New test.


diff --git a/gcc/config/rs6000/rs6000-builtin.def 
b/gcc/config/rs6000/rs6000-builtin.def
index d7ce4de421e..6270444ef70 100644
--- a/gcc/config/rs6000/rs6000-builtin.def
+++ b/gcc/config/rs6000/rs6000-builtin.def
@@ -484,6 +484,25 @@
 | RS6000_BTC_SENARY),  \
CODE_FOR_ ## ICODE) /* ICODE */

+#define BU_MMA_PAIR_LD(ENUM, NAME, ATTR)   \
+  RS6000_BUILTIN_M (VSX_BUILTIN_ ## ENUM,  /* ENUM */  \
+   "__builtin_vsx_" NAME,/* NAME */  \
+   RS6000_BTM_MMA, /* MASK */  \
+   (RS6000_BTC_ ## ATTR/* ATTR */  \
+| RS6000_BTC_BINARY\
+| RS6000_BTC_GIMPLE),  \
+   CODE_FOR_nothing)   /* ICODE */
+
+#define BU_MMA_PAIR_ST(ENUM, NAME, ATTR)   \
+  RS6000_BUILTIN_M (VSX_BUILTIN_ ## ENUM,  /* ENUM */  \
+   "__builtin_vsx_" NAME,/* NAME */  \
+   RS6000_BTM_MMA, /* MASK */  \
+   (RS6000_BTC_ ## ATTR/* ATTR */  \
+| RS6000_BTC_TERNARY   \
+| RS6000_BTC_VOID  \
+| RS6000_BTC_GIMPLE),  \
+   CODE_FOR_nothing)   /* ICODE */
+
  /* ISA 2.05 (power6) convenience macros. */
  /* For functions that depend on the CMPB instruction */
  #define BU_P6_2(ENUM, NAME, ATTR, ICODE)  \
@@ -3253,6 +3272,9 @@ BU_SPECIAL_X (RS6000_BUILTIN_CFSTRING, 
"__builtin_cfstring", RS6000_BTM_ALWAYS,
  BU_P10V_VSX_1 (XVCVBF16SPN,"xvcvbf16spn",   MISC, vsx_xvcvbf16spn)
  BU_P10V_VSX_1 (XVCVSPBF16,"xvcvspbf16", MISC, vsx_xvcvspbf16)

+BU_MMA_PAIR_LD (LXVP,  "lxvp",   MISC)
+BU_MMA_PAIR_ST (STXVP, "stxvp",  PAIR)
+
  BU_MMA_1 (XXMFACC,"xxmfacc",QUAD, mma_xxmfacc)
  BU_MMA_1 (XXMTACC,"xxmtacc",QUAD, mma_xxmtacc)
  BU_MMA_1 (XXSETACCZ,  "xxsetaccz",  MISC, mma_xxsetaccz)
diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c
index b67789845a5..6115e3b34d9 100644
--- a/gcc/config/rs6000/rs6000-call.c
+++ b/gcc/config/rs6000/rs6000-call.c
@@ -11913,6 +11913,32 @@ rs6000_gimple_fold_mma_builtin (gimple_stmt_iterator 
*gsi)
gsi_replace_with_seq (gsi, new_seq, true);
return true;
  }
+  else if (fncode == VSX_BUILTIN_LXVP)
+{
+  push_gimplify_context (true);
+  tree offset = gimple_call_arg (stmt, 0);
+  tree ptr = gimple_call_arg (stmt, 1);
+  tree lhs = gimple_call_lhs (stmt);
+  tree mem = build_simple_mem_ref (build2 (POINTER_PLUS_EXPR,
+  TREE_TYPE (ptr), ptr, offset));
+  gimplify_assign (lhs, mem, _seq);
+  pop_gimplify_context (NULL);
+  gsi_replace_with_seq (gsi, new_seq, true);
+  return true;
+}
+  else if (fncode == VSX_BUILTIN_STXVP)
+{
+  push_gimplify_context (true);
+  tree src = gimple_call_arg (stmt, 0);
+  tree offset = gimple_call_arg (stmt, 1);
+  tree ptr = gimple_call_arg (stmt, 2);
+  tree mem = build_simple_mem_ref (build2 (POINTER_PLUS_EXPR,
+  TREE_TYPE (ptr), ptr, offset));
+  gimplify_assign (mem, src, _seq);
+  pop_gimplify_context (NULL);
+  gsi_replace_with_seq (gsi, new_seq, true);
+  return true;
+}

/* Convert this built-in into an internal version that uses pass-by-value
   arguments.  The internal built-in follows immediately after this one.  */
@@ -14264,11 +14290,14 @@ mma_init_builtins (void)
if (gimple_func)
{
  gcc_assert (icode == CODE_FOR_nothing);
- op[nopnds++] = void_type_node;
  /* Some MMA built-ins that are expanded into gimple are converted
 into internal MMA built-ins that are expanded into rtl.
 The internal built-in follows immediately after this 

[patch, fortran] Fix PR 100227, write with implied DO loop

2021-07-04 Thread Thomas Koenig via Gcc-patches

Hello world,

after a bit of an absence, I am now back, at least for some regression
fixing (and for reviewing patches, if that is called for).

So, here's a regression fix to start with.

OK for trunk and affected branches (down to 9)?

Best regards

Thomas

Do not replace variable op variable in I/O implied DO loop replacement.

This PR came about because index expressions of the form k+k in
implied DO loops in I/O statements were considered for replacement
by array slices.

Fixed by only doing the transformation if the expression is of the
type expr OP contastant.

gcc/fortran/ChangeLog:

PR fortran/100227
* frontend-passes.c (traverse_io_block): Adjust test for
when a variable is eligible for the transformation to
array slice.

gcc/testsuite/ChangeLog:

PR fortran/100227
* gfortran.dg/implied_do_io_7.f90: New test.
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 72a4e0410b1..996dcc2e547 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -1299,8 +1299,8 @@ traverse_io_block (gfc_code *code, bool *has_reached, gfc_code *prev)
 		std::swap (start->value.op.op1, start->value.op.op2);
 	  gcc_fallthrough ();
 	case INTRINSIC_MINUS:
-	  if ((start->value.op.op1->expr_type!= EXPR_VARIABLE
-		   && start->value.op.op2->expr_type != EXPR_CONSTANT)
+	  if (start->value.op.op1->expr_type!= EXPR_VARIABLE
+		  || start->value.op.op2->expr_type != EXPR_CONSTANT
 		  || start->value.op.op1->ref)
 		return false;
 	  if (!stack_top || !stack_top->iter
diff --git a/gcc/testsuite/gfortran.dg/implied_do_io_7.f90 b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90
new file mode 100644
index 000..63927aafea9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90
@@ -0,0 +1,16 @@
+! { dg-do run }
+! PR 100227 - this was falsely optimized, leading to nonsense  results.
+! Original test case by "Mathieu".
+
+program p
+  implicit none
+  integer, parameter :: nbmode = 3
+  integer :: k
+  real:: mass(nbmode*2)
+  character (len=80) :: line
+  do k = 1, nbmode*2
+ mass(k) = k
+  end do
+  write (unit=line,fmt='(*(F6.2))') (mass(k+k), k=1,nbmode)
+  if (line /= '  2.00  4.00  6.00') stop 1
+end program


Re: [PATCH] rs6000: Add MMA __builtin_vsx_lxvp and __builtin_vsx_stxvp built-ins

2021-07-04 Thread Bill Schmidt via Gcc-patches



On 7/3/21 10:56 AM, Segher Boessenkool wrote:

On Fri, Jul 02, 2021 at 01:32:45PM -0500, Peter Bergner wrote:

On 7/1/21 2:48 PM, Peter Bergner wrote:

On 7/1/21 1:01 PM, Segher Boessenkool wrote:

The patch is okay for trunk.

Below is the updated patch which is bootstrapping now.  I'll commit it
if it shows no regressions.

Testing was clean so I pushed it to trunk.




For the backports it is okay if Bill has looked at this patch as well.

Bill has not seen the patch.  I'm not sure when/if he'll get a chance
to either.

Since Bill won't have a chance to look at this, ok for the backport
after a couple of days on trunk?  Bill's builtin rewrite is only targeted
for trunk, so it doesn't affect the backport at all.

Okay.  Thanks!


I will take a look hopefully today.  Mostly looks good but I want to 
check a couple of things before signing off.


Bill




Segher


Re: Commit: Update libiberty sources

2021-07-04 Thread H.J. Lu via Gcc-patches
On Sun, Jul 4, 2021 at 5:56 AM Alan Modra  wrote:
>
> On Sat, Jul 03, 2021 at 01:56:22PM +0100, Nick Clifton via Binutils wrote:
> > Hi Guys,
> >
> >   I am applying the attached file to synchronize our libiberty sources
> >   with gcc.
>
> This lost commit 50ad1254d503, "GCC: Pass --plugin to AR and RANLIB"
> by the look of it.  HJ, should this have been applied to gcc?
>

My patch is needed to build binutils with LTO.  I submitted a patch for GCC:

https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574405.html

-- 
H.J.


[PATCH] Sync with binutils: GCC: Pass --plugin to AR and RANLIB

2021-07-04 Thread H.J. Lu via Gcc-patches
Sync with binutils for building binutils with LTO:

>From 50ad1254d5030d0804cbf89c758359ae202e8d55 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" 
Date: Sat, 9 Jan 2021 06:43:11 -0800
Subject: [PATCH] GCC: Pass --plugin to AR and RANLIB

Detect GCC LTO plugin.  Pass --plugin to AR and RANLIB to support LTO
build.

* Makefile.tpl (AR): Add @AR_PLUGIN_OPTION@
(RANLIB): Add @RANLIB_PLUGIN_OPTION@.
* configure.ac: Include config/gcc-plugin.m4.
AC_SUBST AR_PLUGIN_OPTION and RANLIB_PLUGIN_OPTION.
* libtool.m4 (_LT_CMD_OLD_ARCHIVE): Pass --plugin to AR and
RANLIB if possible.
* Makefile.in: Regenerated.
* configure: Likewise.

config/

* gcc-plugin.m4 (GCC_PLUGIN_OPTION): New.

libiberty/

* Makefile.in (AR): Add @AR_PLUGIN_OPTION@
(RANLIB): Add @RANLIB_PLUGIN_OPTION@.
(configure_deps): Depend on ../config/gcc-plugin.m4.
* configure.ac: AC_SUBST AR_PLUGIN_OPTION and
RANLIB_PLUGIN_OPTION.
* aclocal.m4: Regenerated.
* configure: Likewise.

zlib/

* configure: Regenerated.
---
 Makefile.in|  5 ++--
 Makefile.tpl   |  5 ++--
 config/gcc-plugin.m4   | 28 +++
 configure  | 39 ++
 configure.ac   | 15 ++
 libiberty/Makefile.in  |  5 ++--
 libiberty/aclocal.m4   |  1 +
 libiberty/configure| 63 --
 libiberty/configure.ac | 12 
 libtool.m4 | 25 -
 zlib/configure | 29 +--
 11 files changed, 197 insertions(+), 30 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index ab883f69115..a72a288cda6 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -401,7 +401,7 @@ MAKEINFOFLAGS = --split-size=500
 # -
 
 AS = @AS@
-AR = @AR@
+AR = @AR@ @AR_PLUGIN_OPTION@
 AR_FLAGS = rc
 CC = @CC@
 CXX = @CXX@
@@ -411,7 +411,7 @@ LIPO = @LIPO@
 NM = @NM@
 OBJDUMP = @OBJDUMP@
 OTOOL = @OTOOL@
-RANLIB = @RANLIB@
+RANLIB = @RANLIB@ @RANLIB_PLUGIN_OPTION@
 READELF = @READELF@
 STRIP = @STRIP@
 WINDRES = @WINDRES@
@@ -61403,6 +61403,7 @@ AUTOCONF = autoconf
 $(srcdir)/configure: @MAINT@ $(srcdir)/configure.ac $(srcdir)/config/acx.m4 \
$(srcdir)/config/override.m4 $(srcdir)/config/proginstall.m4 \
$(srcdir)/config/elf.m4 $(srcdir)/config/isl.m4 \
+   $(srcdir)/config/gcc-plugin.m4 \
$(srcdir)/libtool.m4 $(srcdir)/ltoptions.m4 $(srcdir)/ltsugar.m4 \
$(srcdir)/ltversion.m4 $(srcdir)/lt~obsolete.m4
cd $(srcdir) && $(AUTOCONF)
diff --git a/Makefile.tpl b/Makefile.tpl
index 6e0337fb48f..ae139c8914e 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -404,7 +404,7 @@ MAKEINFOFLAGS = --split-size=500
 # -
 
 AS = @AS@
-AR = @AR@
+AR = @AR@ @AR_PLUGIN_OPTION@
 AR_FLAGS = rc
 CC = @CC@
 CXX = @CXX@
@@ -414,7 +414,7 @@ LIPO = @LIPO@
 NM = @NM@
 OBJDUMP = @OBJDUMP@
 OTOOL = @OTOOL@
-RANLIB = @RANLIB@
+RANLIB = @RANLIB@ @RANLIB_PLUGIN_OPTION@
 READELF = @READELF@
 STRIP = @STRIP@
 WINDRES = @WINDRES@
@@ -2007,6 +2007,7 @@ AUTOCONF = autoconf
 $(srcdir)/configure: @MAINT@ $(srcdir)/configure.ac $(srcdir)/config/acx.m4 \
$(srcdir)/config/override.m4 $(srcdir)/config/proginstall.m4 \
$(srcdir)/config/elf.m4 $(srcdir)/config/isl.m4 \
+   $(srcdir)/config/gcc-plugin.m4 \
$(srcdir)/libtool.m4 $(srcdir)/ltoptions.m4 $(srcdir)/ltsugar.m4 \
$(srcdir)/ltversion.m4 $(srcdir)/lt~obsolete.m4
cd $(srcdir) && $(AUTOCONF)
diff --git a/config/gcc-plugin.m4 b/config/gcc-plugin.m4
index 8f278719118..c5b72e9a13d 100644
--- a/config/gcc-plugin.m4
+++ b/config/gcc-plugin.m4
@@ -124,3 +124,31 @@ AC_DEFUN([GCC_ENABLE_PLUGINS],
  fi
fi
 ])
+
+dnl
+dnl
+dnl GCC_PLUGIN_OPTION
+dnl(SHELL-CODE_HANDLER)
+dnl
+AC_DEFUN([GCC_PLUGIN_OPTION],[dnl
+AC_MSG_CHECKING([for -plugin option])
+
+plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll"
+plugin_option=
+for plugin in $plugin_names; do
+  plugin_so=`${CC} ${CFLAGS} --print-prog-name $plugin`
+  if test x$plugin_so = x$plugin; then
+plugin_so=`${CC} ${CFLAGS} --print-file-name $plugin`
+  fi
+  if test x$plugin_so != x$plugin; then
+plugin_option="--plugin $plugin_so"
+break
+  fi
+done
+if test -n "$plugin_option"; then
+  $1="$plugin_option"
+  AC_MSG_RESULT($plugin_option)
+else
+  AC_MSG_RESULT([no])
+fi
+])
diff --git a/configure b/configure
index 1224fc4039e..6d2fc6eb5b4 100755
--- a/configure
+++ b/configure
@@ -618,6 +618,8 @@ GFORTRAN_FOR_TARGET
 GCC_FOR_TARGET
 CXX_FOR_TARGET
 CC_FOR_TARGET
+RANLIB_PLUGIN_OPTION
+AR_PLUGIN_OPTION
 READELF
 OTOOL
 OBJDUMP
@@ -12434,6 +12436,43 @@ fi
 
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -plugin option" >&5
+$as_echo_n "checking for -plugin option... " >&6; }
+
+plugin_names="liblto_plugin.so liblto_plugin-0.dll cyglto_plugin-0.dll"
+plugin_option=

[PATCH] mh-mingw: Set __USE_MINGW_ACCESS in missed C++ flags variables (gcc-10)

2021-07-04 Thread Tomas Kalibera via Gcc-patches
This is exactly what was done already in gcc-11 and trunk by 
89e95ad2e7679322b2f5ee9070ff2721d5ca1d6d but it would be great to apply 
also to gcc-10. It is needed for the driver (compiled by C++) to find 
cc1, cc1plus, etc. More details in 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101238



commit 89e95ad2e7679322b2f5ee9070ff2721d5ca1d6d
Author: Martin Storsjö 
Date:   Fri Apr 9 14:46:36 2021 +0300

    mh-mingw: Set __USE_MINGW_ACCESS in missed C++ flags variables

    This is similar to what was done in
    eea4e2ff0a3f5e7f37df204c070cc5d9ef339e6e (where it was added to
    STAGE*_CXXFLAGS), but this adds the flag to the CXXFLAGS and
    BOOT_CXXFLAGS variables too (as it's already added to CFLAGS and
    BOOT_CFLAGS).

    2021-04-09  Martin Storsjö  

    config/ChangeLog:
    * mh-mingw: Set __USE_MINGW_ACCESS in missed C++ flags
    variables

Thanks
Tomas

diff -Nru gcc-10.2.0-orig/config/mh-mingw gcc-10.2.0-patched/config/mh-mingw
--- gcc-10.2.0-orig/config/mh-mingw	2020-07-23 02:35:16.916379838 -0400
+++ gcc-10.2.0-patched/config/mh-mingw	2021-07-04 03:36:49.987025066 -0400
@@ -1,7 +1,9 @@
 # Add -D__USE_MINGW_ACCESS to enable the built compiler to work on Windows
 # Vista (see PR33281 for details).
 BOOT_CFLAGS += -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format
+BOOT_CXXFLAGS += -D__USE_MINGW_ACCESS -Wno-pedantic-ms-format
 CFLAGS += -D__USE_MINGW_ACCESS
+CXXFLAGS += -D__USE_MINGW_ACCESS
 STAGE1_CXXFLAGS += -D__USE_MINGW_ACCESS
 STAGE2_CXXFLAGS += -D__USE_MINGW_ACCESS
 STAGE3_CXXFLAGS += -D__USE_MINGW_ACCESS