On Mon, May 17, 2021 at 2:18 PM Andrew Pinski <pins...@gmail.com> wrote: > > On Mon, May 17, 2021 at 9:41 AM Bernd Edlinger > <bernd.edlin...@hotmail.de> wrote: > > > > On 5/16/21 10:36 PM, apinski--- via Gcc-patches wrote: > > > From: Andrew Pinski <apin...@marvell.com> > > > > > > Instead of some of the more manual optimizations inside phi-opt, > > > it would be good idea to do a lot of the heavy lifting inside match > > > and simplify instead. In the process, this moves the three simple > > > A?CST1:CST2 (where CST1 or CST2 is zero) simplifications. > > > > > > OK? Boostrapped and tested on x86_64-linux-gnu with no regressions. > > > > > > Thanks, > > > Andrew Pinski > > > > > > gcc: > > > * match.pd (A?CST1:CST2): Add simplifcations for A?0:+-1, A?+-1:0, > > > A?POW2:0 and A?0:POW2. > > > --- > > > gcc/match.pd | 37 +++++++++++++++++++++++++++++++++++++ > > > 1 file changed, 37 insertions(+) > > > > > > diff --git a/gcc/match.pd b/gcc/match.pd > > > index 10503b97ab5..844f7dd5f87 100644 > > > --- a/gcc/match.pd > > > +++ b/gcc/match.pd > > > @@ -3711,6 +3711,43 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > > > (if (integer_all_onesp (@1) && integer_zerop (@2)) > > > @0)))) > > > > > > +/* A few simplifications of "a ? CST1 : CST2". */ > > > +/* NOTE: Only do this on gimple as the if-chain-to-switch > > > + optimization depends on the gimple to have if statements in it. */ > > > +#if GIMPLE > > > +(simplify > > > + (cond @0 INTEGER_CST@1 INTEGER_CST@2) > > > + (switch > > > + (if (integer_zerop (@2)) > > > + (switch > > > + /* a ? 1 : 0 -> a if 0 and 1 are integral types. */ > > > + (if (integer_onep (@1)) > > > + (convert (convert:boolean_type_node @0))) > > > + /* a ? -1 : 0 -> -a. */ > > > + (if (integer_all_onesp (@1)) > > > + (negate (convert (convert:boolean_type_node @0)))) > > > + /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */ > > > + (if (!POINTER_TYPE_P (type) && integer_pow2p (@1)) > > > + (with { > > > + tree shift = build_int_cst (integer_type_node, wi::exact_log2 > > > (wi::to_wide (@1))); > > > + } > > > + (lshift (convert (convert:boolean_type_node @0)) { shift; }))))) > > > + (if (integer_zerop (@1)) > > > + (switch > > > + /* a ? 0 : 1 -> !a. */ > > > + (if (integer_onep (@2)) > > > + (convert (bit_not:boolean_type_node (convert:boolean_type_node > > > @0)))) > > > + /* a ? -1 : 0 -> -(!a). */ > > > + (if (integer_all_onesp (@2)) > > > + (negate (convert (bit_not:boolean_type_node > > > (convert:boolean_type_node @0))))) > > > + /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ > > > + (if (!POINTER_TYPE_P (type) && integer_pow2p (@2)) > > > + (with { > > > + tree shift = build_int_cst (integer_type_node, wi::exact_log2 > > > (wi::to_wide (@2))); > > > + } > > > + (lshift (convert (bit_not:boolean_type_node > > > (convert:boolean_type_node @0))) { shift; }))))))) > > > +#endif > > > + > > > /* Simplification moved from fold_cond_expr_with_comparison. It may also > > > be extended. */ > > > /* This pattern implements two kinds simplification: > > > > > > > Hi Andrew, > > > > Sorry, but I don't know what is exactly wrong with this patch, > > but it seems to cause this, when I try to bootstrap it: > > Thanks for testing the patch out. I did not normally build with Ada > enabled so I did not see this. Anyways I will try to debug it and see > what is going wrong. I might have made a typo or something else is > broken from the IR change. I do know that normally COND_EXPR is not > normally generated so it could be anything. Plus it is definitely > stage 2 being miscompiled which is causing stage 3 to crash.
I think I figured out what is going on though it is a latent bug. See https://gcc.gnu.org/pipermail/gcc/2021-May/236077.html for the details. Thanks, Andrew > > Thanks, > Andrew Pinski > > > > > > > > /home/ed/gnu/gcc-build-2/./prev-gcc/xgcc > > -B/home/ed/gnu/gcc-build-2/./prev-gcc/ > > -B/home/ed/gnu/install/x86_64-pc-linux-gnu/bin/ > > -B/home/ed/gnu/install/x86_64-pc-linux-gnu/bin/ > > -B/home/ed/gnu/install/x86_64-pc-linux-gnu/lib/ -isystem > > /home/ed/gnu/install/x86_64-pc-linux-gnu/include -isystem > > /home/ed/gnu/install/x86_64-pc-linux-gnu/sys-include -fchecking=1 -c -g > > -O2 -fchecking=1 -gnatpg -gnata -W -Wall -nostdinc -I- -I. -Iada/generated > > -Iada -Iada/gcc-interface -I../../gcc-trunk-1/gcc/ada > > -I../../gcc-trunk-1/gcc/ada/gcc-interface -Iada/libgnat > > -I../../gcc-trunk-1/gcc/ada/libgnat > > ../../gcc-trunk-1/gcc/ada/libgnat/a-charac.ads -o ada/libgnat/a-charac.o > > /home/ed/gnu/gcc-build-2/./prev-gcc/xgcc > > -B/home/ed/gnu/gcc-build-2/./prev-gcc/ > > -B/home/ed/gnu/install/x86_64-pc-linux-gnu/bin/ > > -B/home/ed/gnu/install/x86_64-pc-linux-gnu/bin/ > > -B/home/ed/gnu/install/x86_64-pc-linux-gnu/lib/ -isystem > > /home/ed/gnu/install/x86_64-pc-linux-gnu/include -isystem > > /home/ed/gnu/install/x86_64-pc-linux-gnu/sys-include -fchecking=1 -c -g > > -O2 -fchecking=1 -gnatpg -gnata -W -Wall -nostdinc -I- -I. -Iada/generated > > -Iada -Iada/gcc-interface -I../../gcc-trunk-1/gcc/ada > > -I../../gcc-trunk-1/gcc/ada/gcc-interface -Iada/libgnat > > -I../../gcc-trunk-1/gcc/ada/libgnat > > ../../gcc-trunk-1/gcc/ada/libgnat/a-chlat1.ads -o ada/libgnat/a-chlat1.o > > +===========================GNAT BUG DETECTED==============================+ > > | 12.0.0 20210517 (experimental) (x86_64-pc-linux-gnu) Storage_Error stack > > overflow or erroneous memory access| > > | Error detected at a-charac.ads:16:12 | > > | Please submit a bug report; see https://gcc.gnu.org/bugs/ . | > > | Use a subject line meaningful to you and us to track the bug. | > > | Include the entire contents of this bug box in the report. | > > | Include the exact command that you entered. | > > | Also include sources listed below. | > > +==========================================================================+ > > > > Please include these source files with error report > > Note that list may not be accurate in some cases, > > so please double check that the problem can still > > be reproduced with the set of files listed. > > Consider also -gnatd.n switch (see debug.adb). > > > > ../../gcc-trunk-1/gcc/ada/gcc-interface/system.ads > > ../../gcc-trunk-1/gcc/ada/libgnat/a-charac.ads > > ../../gcc-trunk-1/gcc/ada/libgnat/ada.ads > > > > compilation abandoned > > echo timestamp > s-modes > > make[3]: *** [../../gcc-trunk-1/gcc/ada/gcc-interface/Make-lang.in:144: > > ada/libgnat/a-charac.o] Error 1 > > make[3]: *** Waiting for unfinished jobs.... > > +===========================GNAT BUG DETECTED==============================+ > > | 12.0.0 20210517 (experimental) (x86_64-pc-linux-gnu) Storage_Error stack > > overflow or erroneous memory access| > > | Error detected at a-chlat1.ads:18:23 | > > | Please submit a bug report; see https://gcc.gnu.org/bugs/ . | > > | Use a subject line meaningful to you and us to track the bug. | > > | Include the entire contents of this bug box in the report. | > > | Include the exact command that you entered. | > > | Also include sources listed below. | > > +==========================================================================+ > > > > Please include these source files with error report > > Note that list may not be accurate in some cases, > > so please double check that the problem can still > > be reproduced with the set of files listed. > > Consider also -gnatd.n switch (see debug.adb). > > > > ../../gcc-trunk-1/gcc/ada/gcc-interface/system.ads > > ../../gcc-trunk-1/gcc/ada/libgnat/a-chlat1.ads > > ../../gcc-trunk-1/gcc/ada/libgnat/a-charac.ads > > ../../gcc-trunk-1/gcc/ada/libgnat/ada.ads > > > > compilation abandoned > > make[3]: *** [../../gcc-trunk-1/gcc/ada/gcc-interface/Make-lang.in:144: > > ada/libgnat/a-chlat1.o] Error 1 > > rm gcov.pod gcov-dump.pod fsf-funding.pod gfdl.pod gpl.pod cpp.pod > > gccgo.pod gcc.pod gdc.pod gfortran.pod gcov-tool.pod lto-dump.pod > > make[3]: Leaving directory '/home/ed/gnu/gcc-build-2/gcc' > > make[2]: *** [Makefile:4854: all-stage3-gcc] Error 2 > > make[2]: Leaving directory '/home/ed/gnu/gcc-build-2' > > make[1]: *** [Makefile:32080: stage3-bubble] Error 2 > > make[1]: Leaving directory '/home/ed/gnu/gcc-build-2' > > make: *** [Makefile:1009: all] Error 2 > > > > > > Bernd.