Re: [PATCH] gcc: add trigonometric pi-based functions as gcc builtins
Hi Jakub, Thank you for your suggestion. I actually learned from your earlier patch (https://gcc.gnu.org/cgit/gcc/commit?id=7f940822) and had already planned to update tree-call-cdce.cc when handling these builtins. Your guidance is much appreciated! Best regards, Yuao From: Jakub Jelinek Sent: Saturday, May 17, 2025 22:11 To: Yuao Ma Cc: gcc-patches@gcc.gnu.org ; fort...@gcc.gnu.org ; tbur...@baylibre.com ; j...@polyomino.org.uk Subject: Re: [PATCH] gcc: add trigonometric pi-based functions as gcc builtins On Wed, May 14, 2025 at 02:22:23PM +, Yuao Ma wrote: > If approved, I suggest committing this foundational change first. Constant > folding for these builtins will be addressed in subsequent patches. Note, not just constant folding is needed, but I think the builtins should be handled in tree-call-cdce.cc (can_test_argument_range, edom_only_function, get_no_error_domain). Jakub
Re: [to-be-committed][RISC-V] Avoid setting output object more than once in IOR/XOR synthesis
On 5/18/25 8:53 AM, Mark Wielaard wrote: Hi Jeff, On Thu, May 15, 2025 at 10:11:19PM -0600, Jeff Law wrote: This has been tested in my tester and is currently bootstrapping on my BPI. Waiting on data from the pre-commit tester before moving forward... It looks like the Sourceware p550 and spacemit-x60 builders do flag a bootstrap issue with this: https://builder.sourceware.org/buildbot/#/builders/337/builds/255 https://builder.sourceware.org/buildbot/#/builders/338/builds/228 ../../gcc/gcc/config/riscv/riscv.cc: In function ‘bool synthesize_ior_xor(rtx_code, rtx_def**)’: ../../gcc/gcc/config/riscv/riscv.cc:14422:18: error: ‘output’ may be used uninitialized [-Werror=maybe-uninitialized] 14422 | emit_move_insn (operands[0], output); | ~~~^ ../../gcc/gcc/config/riscv/riscv.cc:14393:7: note: ‘output’ was declared here 14393 | rtx output; | ^~ cc1plus: all warnings being treated as errors make[3]: *** [Makefile:2728: riscv.o] Error 1 make[3]: *** Waiting for unfinished jobs Arggh. Mine failed too (big surprise). I'll fix it up. The 24hr cycle time is quite annoying... jeff
Re: [PATCH] Partially lift restriction from loc_list_from_tree_1
> OK. Thanks. > Btw, can we try to add a "guality" for gnat.dg? Or are you making sure to > add coverage to the gdb testsuite? Yes, the GDB testsuite will get a testcase. -- Eric Botcazou
[COMMITTED] Regenerate cobol/lang.opt.urls
The Cobol frontend lang.opt got -M added, but lang.opt.urls wasn't regenerated. Fixes: 92b6485a75ca ("cobol: Eliminate exception "blob"; streamline some code generation.") gcc/cobol/ChangeLog: * lang.opt.urls: Regenerated. --- gcc/cobol/lang.opt.urls | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gcc/cobol/lang.opt.urls b/gcc/cobol/lang.opt.urls index 69f52973c025..78fc491fa67f 100644 --- a/gcc/cobol/lang.opt.urls +++ b/gcc/cobol/lang.opt.urls @@ -10,6 +10,9 @@ UrlSuffix(gcc/Preprocessor-Options.html#index-D-1) I UrlSuffix(gcc/Directory-Options.html#index-I) LangUrlSuffix_D(gdc/Directory-Options.html#index-I) +M +UrlSuffix(gcc/Preprocessor-Options.html#index-M) LangUrlSuffix_D(gdc/Code-Generation.html#index-M) + ffixed-form LangUrlSuffix_Fortran(gfortran/Fortran-Dialect-Options.html#index-ffixed-form) -- 2.49.0
Re: [PATCH] phiopt: Use mark_lhs_in_seq_for_dce instead of doing it inline
> Am 18.05.2025 um 08:26 schrieb Andrew Pinski : > > Right now phiopt has the same code as mark_lhs_in_seq_for_dce > inlined into match_simplify_replacement. Instead let's use the > function in gimple-fold that does the same thing. > > Bootstrapped and tested on x86_64-linux-gnu. Ok Richard > gcc/ChangeLog: > >* gimple-fold.cc (mark_lhs_in_seq_for_dce): Make >non-static. >* gimple-fold.h (mark_lhs_in_seq_for_dce): Declare. >* tree-ssa-phiopt.cc (match_simplify_replacement): Use >mark_lhs_in_seq_for_dce instead of manually looping. > > Signed-off-by: Andrew Pinski > --- > gcc/gimple-fold.cc | 2 +- > gcc/gimple-fold.h | 1 + > gcc/tree-ssa-phiopt.cc | 13 +++-- > 3 files changed, 5 insertions(+), 11 deletions(-) > > diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc > index b74fb8bb50c..0f437616d77 100644 > --- a/gcc/gimple-fold.cc > +++ b/gcc/gimple-fold.cc > @@ -6020,7 +6020,7 @@ has_use_on_stmt (tree name, gimple *stmt) > > /* Add the lhs of each statement of SEQ to DCE_WORKLIST. */ > > -static void > +void > mark_lhs_in_seq_for_dce (bitmap dce_worklist, gimple_seq seq) > { > if (!dce_worklist) > diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h > index afecbb8ceef..8b1e246b0c0 100644 > --- a/gcc/gimple-fold.h > +++ b/gcc/gimple-fold.h > @@ -264,6 +264,7 @@ gimple_build_round_up (gimple_seq *seq, tree type, tree > old_size, > > extern bool gimple_stmt_nonnegative_warnv_p (gimple *, bool *, int = 0); > extern bool gimple_stmt_integer_valued_real_p (gimple *, int = 0); > +extern void mark_lhs_in_seq_for_dce (bitmap, gimple_seq); > > /* In gimple-match.cc. */ > extern tree gimple_simplify (enum tree_code, tree, tree, > diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc > index 9724040fc3d..8c5908e5bff 100644 > --- a/gcc/tree-ssa-phiopt.cc > +++ b/gcc/tree-ssa-phiopt.cc > @@ -1001,16 +1001,9 @@ match_simplify_replacement (basic_block cond_bb, > basic_block middle_bb, > if (seq) > { > // Mark the lhs of the new statements maybe for dce > - gimple_stmt_iterator gsi1 = gsi_start (seq); > - for (; !gsi_end_p (gsi1); gsi_next (&gsi1)) > -{ > - gimple *stmt = gsi_stmt (gsi1); > - tree name = gimple_get_lhs (stmt); > - if (name && TREE_CODE (name) == SSA_NAME) > -bitmap_set_bit (exprs_maybe_dce, SSA_NAME_VERSION (name)); > -} > -gsi_insert_seq_before (&gsi, seq, GSI_CONTINUE_LINKING); > - } > + mark_lhs_in_seq_for_dce (exprs_maybe_dce, seq); > + gsi_insert_seq_before (&gsi, seq, GSI_CONTINUE_LINKING); > +} > > /* If there was a statement to move, move it to right before > the original conditional. */ > -- > 2.43.0 >
[to-be-committed][RISC-V] Avoid multiple assignments to output object
This is the next batch of changes to reduce multiple assignments to an output object. This time I'm focused on splitters in bitmanip.md. This doesn't convert every case. For example there is one case that is very clearly dependent on eliminating mvconst_internal and adjustment of a splitter for andn and until those things happen it would clearly be a QOI implementation regression. There are cases where we set a scratch register more than once. It may be possible to use an additional scratch. I haven't tried that yet. I've seen one failure to if-convert a sequence after this patch, but it should be resolved once the logical AND changes are merged. Otherwise I'm primarily seeing slight differences in register allocation and scheduling. Nothing concerning to me. This has run through my tester, but I obviously want to see how it behaves in the upstream CI system as that tests slightly different multilibs than mine (on purpose). Jeffgcc/ * config/riscv/bitmanip.md (various splits): Avoid writing the output more than once when trivially possible. diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md index c226c39f580..400fea30f91 100644 --- a/gcc/config/riscv/bitmanip.md +++ b/gcc/config/riscv/bitmanip.md @@ -68,23 +68,25 @@ (define_split [(set (match_operand:DI 0 "register_operand") (zero_extend:DI (plus:SI (ashift:SI (subreg:SI (match_operand:DI 1 "register_operand") 0) (match_operand:QI 2 "imm123_operand")) -(subreg:SI (match_operand:DI 3 "register_operand") 0] +(subreg:SI (match_operand:DI 3 "register_operand") 0 + (clobber (match_operand:DI 4 "register_operand"))] "TARGET_64BIT && TARGET_ZBA" - [(set (match_dup 0) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3))) - (set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 0) 0)))]) + [(set (match_dup 4) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3))) + (set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 4) 0)))]) (define_split [(set (match_operand:DI 0 "register_operand") (zero_extend:DI (plus:SI (subreg:SI (and:DI (ashift:DI (match_operand:DI 1 "register_operand") (match_operand:QI 2 "imm123_operand")) (match_operand:DI 3 "consecutive_bits_operand")) 0) -(subreg:SI (match_operand:DI 4 "register_operand") 0] +(subreg:SI (match_operand:DI 4 "register_operand") 0 + (clobber (match_operand:DI 5 "register_operand"))] "TARGET_64BIT && TARGET_ZBA && riscv_shamt_matches_mask_p (INTVAL (operands[2]), INTVAL (operands[3])) /* Ensure the mask includes all the bits in SImode. */ && ((INTVAL (operands[3]) & (HOST_WIDE_INT_1U << 31)) != 0)" - [(set (match_dup 0) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 4))) - (set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 0) 0)))]) + [(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 4))) + (set (match_dup 0) (zero_extend:DI (subreg:SI (match_dup 5) 0)))]) ; Make sure that an andi followed by a sh[123]add remains a two instruction ; sequence--and is not torn apart into slli, slri, add. @@ -195,13 +197,14 @@ (define_split (match_operand:QI 2 "imm123_operand")) (match_operand 3 "consecutive_bits32_operand")) (match_operand:DI 4 "register_operand")) -(match_operand 5 "immediate_operand")))] +(match_operand 5 "immediate_operand"))) + (clobber (match_operand:DI 6 "register_operand"))] "TARGET_64BIT && TARGET_ZBA" - [(set (match_dup 0) + [(set (match_dup 6) (plus:DI (and:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)) (match_dup 4))) - (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 5)))]) + (set (match_dup 0) (plus:DI (match_dup 6) (match_dup 5)))]) ;; ZBB extension. @@ -846,18 +849,19 @@ (define_insn "*bclri" (define_insn_and_split "*bclri_nottwobits" [(set (match_operand:X 0 "register_operand" "=r") (and:X (match_operand:X 1 "register_operand" "r") - (match_operand:X 2 "const_nottwobits_not_arith_operand" "i")))] + (match_operand:X 2 "const_nottwobits_not_arith_operand" "i"))) + (clobber (match_scratch:X 3 "=&r"))] "TARGET_ZBS && !paradoxical_subreg_p (operands[1])" "#" "&& reload_completed" - [(set (match_dup 0) (and:X (match_dup 1) (match_dup 3))) - (set (match_dup 0) (and:X (match_dup 0) (match_dup 4)))] + [(set (match_dup 3) (and:X (match_dup 1) (match_dup 4))) + (set (match_dup 0) (and:X (match_dup 3) (match_dup 5)))] { -
Re: [to-be-committed][RISC-V] Avoid setting output object more than once in IOR/XOR synthesis
Hi Jeff, On Thu, May 15, 2025 at 10:11:19PM -0600, Jeff Law wrote: > This has been tested in my tester and is currently bootstrapping on > my BPI. Waiting on data from the pre-commit tester before moving > forward... It looks like the Sourceware p550 and spacemit-x60 builders do flag a bootstrap issue with this: https://builder.sourceware.org/buildbot/#/builders/337/builds/255 https://builder.sourceware.org/buildbot/#/builders/338/builds/228 ../../gcc/gcc/config/riscv/riscv.cc: In function ‘bool synthesize_ior_xor(rtx_code, rtx_def**)’: ../../gcc/gcc/config/riscv/riscv.cc:14422:18: error: ‘output’ may be used uninitialized [-Werror=maybe-uninitialized] 14422 | emit_move_insn (operands[0], output); | ~~~^ ../../gcc/gcc/config/riscv/riscv.cc:14393:7: note: ‘output’ was declared here 14393 | rtx output; | ^~ cc1plus: all warnings being treated as errors make[3]: *** [Makefile:2728: riscv.o] Error 1 make[3]: *** Waiting for unfinished jobs > * config/riscv/riscv.cc (synthesize_ior_xor): Avoid writing > operands[0] more than once, use new pseudos instead. > > diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc > index d996965d095..b908c4684ac 100644 > --- a/gcc/config/riscv/riscv.cc > +++ b/gcc/config/riscv/riscv.cc > [...] > @@ -14378,6 +14394,7 @@ synthesize_ior_xor (rtx_code code, rtx operands[3]) >/* Synthesis is better than loading the constant. */ >ival = INTVAL (operands[2]); >rtx input = operands[1]; > + rtx output; > >/* Emit the [x]ori insn that sets the low 11 bits into > the proper state. */ Should output here be initialized to NULL_RTX? Thanks, Mark
[PATCH] cobol: Minor grammatical correction as the first issue.
Hi everyone, I started studying GCC and the new COBOL part when I noticed something that looked like a typing error. I thought it would make a good first issue to report, so here is my patch. Here is the patch From 4f7fd1e08151df26b37a5a1f2cbce2623f214361 Mon Sep 17 00:00:00 2001 From: pulk66-s Date: Sun, 18 May 2025 16:19:04 +0200 Subject: [PATCH] cobol: fix minor grammar in comments --- gcc/cobol/lexio.cc | 2 +- gcc/cobol/parse.y | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gcc/cobol/lexio.cc b/gcc/cobol/lexio.cc index 2db1af273e9..4f68bf65887 100644 --- a/gcc/cobol/lexio.cc +++ b/gcc/cobol/lexio.cc @@ -1455,7 +1455,7 @@ cdftext::lex_open( const char filename[] ) { int output = open_output(); - // Process any files supplied by the -include comamnd-line option. + // Process any files supplied by the -include command-line option. for( auto name : included_files ) { int input; if( -1 == (input = open(name, O_RDONLY)) ) { diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y index cb96c907361..1df9a9a63e9 100644 --- a/gcc/cobol/parse.y +++ b/gcc/cobol/parse.y @@ -5038,7 +5038,7 @@ accept: accept_body end_accept { switch( $accept_body.func ) { case accept_done_e: error_msg(@ec, "ON EXCEPTION valid only " - "with ENVIRONMENT or COMAMND-LINE(n)"); + "with ENVIRONMENT or COMMAND-LINE(n)"); break; case accept_command_line_e: if( $1.from->field == NULL ) { // take next command-line arg @@ -5050,7 +5050,7 @@ accept: accept_body end_accept { parser_move(*$1.into, *$1.from); if( $ec.on_error || $ec.not_error ) { error_msg(@ec, "ON EXCEPTION valid only " -"with ENVIRONMENT or COMAMND-LINE(n)"); +"with ENVIRONMENT or COMMAND-LINE(n)"); } } else { parser_accept_command_line(*$1.into, *$1.from, -- 2.45.2
[PATCH] match: Remove valueize_condition argument from gimple_extra template
After r15-4791-gb60031e8f9f8fe, the valueize_condition argument becomes unused. I didn't notice that as there was -Wno-unused option being added while compiling gimple-match-exports.cc. This removes that too as there are no unused warnings. gcc/ChangeLog: * Makefile.in (gimple-match-exports.o-warn): Remove. * gimple-match-exports.cc (gimple_extract): Remove valueize_condition argument. (gimple_extract_op): Update call to gimple_extract. (gimple_simplify): Likewise. Also remove valueize_condition lambda. Signed-off-by: Andrew Pinski --- gcc/Makefile.in | 1 - gcc/gimple-match-exports.cc | 44 + 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 72d132207c0..366364a23de 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -253,7 +253,6 @@ gengtype-lex.o-warn = -Wno-error libgcov-util.o-warn = -Wno-error libgcov-driver-tool.o-warn = -Wno-error libgcov-merge-tool.o-warn = -Wno-error -gimple-match-exports.o-warn = -Wno-unused dfp.o-warn = -Wno-strict-aliasing # All warnings have to be shut off in stage1 if the compiler used then diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc index b3acae21fa5..06f155427b3 100644 --- a/gcc/gimple-match-exports.cc +++ b/gcc/gimple-match-exports.cc @@ -720,16 +720,14 @@ gimple_simplify (combined_fn fn, tree type, describe STMT in RES_OP, returning true on success. Before recording an operand, call: - - VALUEIZE_CONDITION for a COND_EXPR condition - - VALUEIZE_OP for every other top-level operand + - VALUEIZE_OP for all top-level operand - Both routines take a tree argument and returns a tree. */ + This routine takes a tree argument and returns a tree. */ -template +template inline bool gimple_extract (gimple *stmt, gimple_match_op *res_op, - ValueizeOp valueize_op, - ValueizeCondition valueize_condition) + ValueizeOp valueize_op) { switch (gimple_code (stmt)) { @@ -858,7 +856,7 @@ bool gimple_extract_op (gimple *stmt, gimple_match_op *res_op) { auto nop = [](tree op) { return op; }; - return gimple_extract (stmt, res_op, nop, nop); + return gimple_extract (stmt, res_op, nop); } /* In some cases, the resulting RES_OP might contain just a @@ -895,38 +893,8 @@ gimple_simplify (gimple *stmt, gimple_match_op *res_op, gimple_seq *seq, { return do_valueize (op, top_valueize, valueized); }; - auto valueize_condition = [&](tree op) -> tree -{ - bool cond_valueized = false; - tree lhs = do_valueize (TREE_OPERAND (op, 0), top_valueize, - cond_valueized); - tree rhs = do_valueize (TREE_OPERAND (op, 1), top_valueize, - cond_valueized); - gimple_match_op res_op2 (res_op->cond, TREE_CODE (op), - TREE_TYPE (op), lhs, rhs); - if ((gimple_resimplify2 (seq, &res_op2, valueize) - || cond_valueized) - && res_op2.code.is_tree_code ()) - { - auto code = tree_code (res_op2.code); - if (TREE_CODE_CLASS (code) == tcc_comparison) - { - valueized = true; - return build2 (code, TREE_TYPE (op), -res_op2.ops[0], res_op2.ops[1]); - } - else if (code == SSA_NAME - || code == INTEGER_CST - || code == VECTOR_CST) - { - valueized = true; - return res_op2.ops[0]; - } - } - return valueize_op (op); -}; - if (!gimple_extract (stmt, res_op, valueize_op, valueize_condition)) + if (!gimple_extract (stmt, res_op, valueize_op)) return false; if (res_op->code.is_internal_fn ()) -- 2.43.0
[PATCH] match: Undo maybe_push_res_to_seq in some cases [PR120331]
While working on improving forwprop and removal of forward_propagate_into_gimple_cond/forward_propagate_into_comparison, I came cross a case where we end up with SSA_NAME in the resulting gimple_match_op and one statement in the sequence. This was the result of simplification of: ``` _3 = MIN_EXPR > 16 if (_3 > 16) ... ``` Which simplifies down to: (maxlen_2(D) > 16) & (264 > 16) into (maxlen_2(D) > 16) & 1 Which `maxlen_2(D) > 16` gets pushed onto the sequence and then the & 1 is removed via the match pattern: ``` /* x & ~0 -> x */ (simplify (bit_and @0 integer_all_onesp) (non_lvalue @0)) ``` So what this patch does is to undo the push extracting the new op from the pushed statement and remove the sequence as it is not used any more. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: PR tree-optimization/120331 * gimple-match-exports.cc (maybe_undo_push): New function. (gimple_simplify): Call maybe_undo_push if resimplify was successfull. Signed-off-by: Andrew Pinski --- gcc/gimple-match-exports.cc | 27 ++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc index ccba046a1d4..b3acae21fa5 100644 --- a/gcc/gimple-match-exports.cc +++ b/gcc/gimple-match-exports.cc @@ -861,6 +861,28 @@ gimple_extract_op (gimple *stmt, gimple_match_op *res_op) return gimple_extract (stmt, res_op, nop, nop); } +/* In some cases, the resulting RES_OP might contain just a + SSA_NAME and the sequence SEQ contains one statement, we can + possibile undo the push and change the match RES_OP into + what the statement is. */ +static void +maybe_undo_push (gimple_seq *seq, gimple_match_op *res_op) +{ + if (!seq || !gimple_seq_singleton_p (*seq)) +return; + if (res_op->code != SSA_NAME) +return; + gimple *stmt = gimple_seq_first_stmt (*seq); + if (gimple_get_lhs (stmt) != res_op->ops[0]) +return; + gimple_match_op new_op; + if (!gimple_extract_op (stmt, &new_op)) +return; + gimple_seq_discard (*seq); + *seq = NULL; + *res_op = new_op; +} + /* The main STMT based simplification entry. It is used by the fold_stmt and the fold_stmt_to_constant APIs. */ @@ -917,7 +939,10 @@ gimple_simplify (gimple *stmt, gimple_match_op *res_op, gimple_seq *seq, if (!res_op->reverse && res_op->num_ops && res_op->resimplify (seq, valueize)) -return true; +{ + maybe_undo_push (seq, res_op); + return true; +} return valueized; } -- 2.43.0