diff --git a/0320-if-split-fix-bugs.patch b/0320-if-split-fix-bugs.patch new file mode 100644 index 0000000000000000000000000000000000000000..c8b97ebe5ceb0eded7073abb31d029dcfc1cffc4 --- /dev/null +++ b/0320-if-split-fix-bugs.patch @@ -0,0 +1,105 @@ +From 7636e8782aa0dac322c22631c4cd0b60c0eb1842 Mon Sep 17 00:00:00 2001 +From: Zinin Ivan WX1305386 +Date: Tue, 3 Dec 2024 16:02:15 +0300 +Subject: [PATCH] Fix bugs + +Added check if then_bb got single succ in process_complex_cond() + +Made processing of cases when then_bb is pred of EXIT and got +return statement inside. Splitting of edge from EXIT pred to +EXIT deletes return statement, and duplication of then_bb will +got no return statement too. So in such cases we need to build +return statement in merge_bb by ourselves. +--- + gcc/gimple-if-split.cc | 35 +++++++++++++++++++++++++++++++++-- + 1 file changed, 33 insertions(+), 2 deletions(-) + +diff --git a/gcc/gimple-if-split.cc b/gcc/gimple-if-split.cc +index 3446204ea..351515435 100644 +--- a/gcc/gimple-if-split.cc ++++ b/gcc/gimple-if-split.cc +@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see + #include "tree-cfg.h" + #include "bitmap.h" + #include "cfganal.h" ++#include "cfgloop.h" + + /* Perform splitting if-then-else patterns, whose complex OR condition in + cond-bb contains comparison of some variable with constant and then-bb got +@@ -255,6 +256,7 @@ process_complex_cond (basic_block cond_bb, basic_block then_bb, + cond_parts_defs defs; + + if (!can_duplicate_block_p (then_bb) ++ || !single_succ_p (then_bb) + || !necessary_complex_cond_p (cond, then_bb, &defs)) + return; + +@@ -345,14 +347,39 @@ static basic_block + make_two_separate_calls (basic_block outer_cond_bb, basic_block inner_cond_bb, + basic_block then_bb) + { +- if (!can_duplicate_block_p (then_bb) || EDGE_COUNT (then_bb->succs) != 1) ++ if (!can_duplicate_block_p (then_bb) || !single_succ_p (then_bb)) + return NULL; + + edge outer_then_e = find_edge (outer_cond_bb, then_bb); + + /* Making duplication of then_bb. */ + basic_block then_bb_dom = get_immediate_dominator (CDI_DOMINATORS, then_bb); ++ ++ /* Saving ret_value and then_bb succ edge flags, if then_bb is pred of ++ * EXIT_BLOCK and has return statement inside. */ ++ tree ret_val; ++ int then_bb_succ_edge_flags; ++ if (single_succ (then_bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)) ++ { ++ gcc_assert (gimple_code (last_stmt (then_bb)) == GIMPLE_RETURN); ++ ret_val = gimple_return_retval (as_a(last_stmt (then_bb))); ++ ++ then_bb_succ_edge_flags = single_succ_edge (then_bb)->flags; ++ } ++ + basic_block merge_bb = split_edge (single_succ_edge (then_bb)); ++ ++ /* Building return statement in merge_bb and setting merge_bb succ edge flags, ++ * if now merge_bb is pred of EXIT_BLOCK. */ ++ if (single_succ (merge_bb) == EXIT_BLOCK_PTR_FOR_FN (cfun)) ++ { ++ gimple* ret = gimple_build_return (ret_val); ++ gimple_stmt_iterator gsi = gsi_last_bb (merge_bb); ++ gsi_insert_after (&gsi, ret, GSI_NEW_STMT); ++ ++ single_succ_edge (merge_bb)->flags = then_bb_succ_edge_flags; ++ } ++ + basic_block then_bb1 = duplicate_block (then_bb, outer_then_e, outer_cond_bb); + edge outer_then1_e = find_edge (outer_cond_bb, then_bb1); + +@@ -372,6 +399,9 @@ make_two_separate_calls (basic_block outer_cond_bb, basic_block inner_cond_bb, + set_immediate_dominator (CDI_POST_DOMINATORS, merge_bb, + single_succ (merge_bb)); + ++ if (get_immediate_dominator (CDI_POST_DOMINATORS, outer_cond_bb) == then_bb) ++ set_immediate_dominator (CDI_POST_DOMINATORS, outer_cond_bb, merge_bb); ++ + return then_bb1; + } + +@@ -548,6 +578,7 @@ pass_if_split::execute (function *fun) + + checking_verify_ssa (true, true); + checking_verify_flow_info (); ++ checking_verify_loop_structure (); + checking_verify_dominators (CDI_DOMINATORS); + checking_verify_dominators (CDI_POST_DOMINATORS); + +@@ -564,4 +595,4 @@ gimple_opt_pass * + make_pass_if_split (gcc::context *ctxt) + { + return new pass_if_split (ctxt); +-} +\ No newline at end of file ++} +-- +2.33.0 + diff --git a/gcc.spec b/gcc.spec index a9ed52e8a68ad6fd399136dbe2e8900dadf7ad70..35104d29a382f8951451b87c519dc23865d51242 100644 --- a/gcc.spec +++ b/gcc.spec @@ -2,7 +2,7 @@ %global gcc_major 12 # Note, gcc_release must be integer, if you want to add suffixes to # %%{release}, append them after %%{gcc_release} on Release: line. -%global gcc_release 55 +%global gcc_release 56 %global _unpackaged_files_terminate_build 0 %global _performance_build 1 @@ -425,6 +425,7 @@ Patch316: 0316-Use-ai-ability-to-guide-optimization.patch Patch317: 0317-Bugfix-set-default-value-when-tune_native-is-NULL.patch Patch318: 0318-add-flag-flto-try.patch Patch319: 0319-CSPGO-fix-bugs-when-using-cspgo.patch +Patch320: 0320-if-split-fix-bugs.patch # Part 1001-1999 %ifarch sw_64 @@ -1530,6 +1531,7 @@ not stable, so plugins must be rebuilt any time GCC is updated. %patch -P317 -p1 %patch -P318 -p1 %patch -P319 -p1 +%patch -P320 -p1 %ifarch sw_64 %patch -P1001 -p1 @@ -4152,6 +4154,12 @@ end %doc rpm.doc/changelogs/libcc1/ChangeLog* %changelog +* Sat Dec 07 2024 huzife <634763349@qq.com> - 12.3.1-56 +- Type:Bugfix +- ID:NA +- SUG:NA +- DESC: Fix bugs for if-split. + * Wed Dec 04 2024 liyancheng <412998149@qq.com> - 12.3.1-55 - Type:Bugfix - ID:NA