[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 --- Comment #12 from Drea Pinski --- (In reply to Uroš Bizjak from comment #11) > (In reply to Drea Pinski from comment #10) > > But the reality here we are still paper overing the real issue. > > Which is pr 123070. > > > > *** This bug has been marked as a duplicate of bug 123070 *** > > Perhaps the original RTX sequence is not optimal, but please add > -fno-reorder-blocks -fno-reorder-blocks-and-partition to compile flags, you > will see that there are *no* cprop optimization opportunities. > > So, what pass_reorder_blocks creates definitely opens some cprop > optimization opportunities, as demonstrated in Comment #8. There are a bunch of other bug reports containing this. I can't find them right now though.
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 --- Comment #11 from Uroš Bizjak --- (In reply to Drea Pinski from comment #10) > But the reality here we are still paper overing the real issue. > Which is pr 123070. > > *** This bug has been marked as a duplicate of bug 123070 *** Perhaps the original RTX sequence is not optimal, but please add -fno-reorder-blocks -fno-reorder-blocks-and-partition to compile flags, you will see that there are *no* cprop optimization opportunities. So, what pass_reorder_blocks creates definitely opens some cprop optimization opportunities, as demonstrated in Comment #8.
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 Drea Pinski changed: What|Removed |Added Status|WAITING |RESOLVED Resolution|--- |DUPLICATE --- Comment #10 from Drea Pinski --- But the reality here we are still paper overing the real issue. Which is pr 123070. *** This bug has been marked as a duplicate of bug 123070 ***
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901
Drea Pinski changed:
What|Removed |Added
CC||pinskia at gcc dot gnu.org
--- Comment #9 from Drea Pinski ---
(In reply to Uroš Bizjak from comment #8)
> FTR: Adding *another* pass_cprop_hardreg after pass_reorder_blocks with:
>
> --cut here--
> diff --git a/gcc/passes.def b/gcc/passes.def
> index cdddb87302f..b5c6e99974b 100644
> --- a/gcc/passes.def
> +++ b/gcc/passes.def
> @@ -543,6 +543,7 @@ along with GCC; see the file COPYING3. If not see
> NEXT_PASS (pass_cprop_hardreg);
> NEXT_PASS (pass_fast_rtl_dce);
> NEXT_PASS (pass_reorder_blocks);
> + NEXT_PASS (pass_cprop_hardreg);
> NEXT_PASS (pass_leaf_regs);
> NEXT_PASS (pass_split_before_sched2);
> NEXT_PASS (pass_sched2);
> diff --git a/gcc/regcprop.cc b/gcc/regcprop.cc
> index 2a9956353cc..806dc944b97 100644
> --- a/gcc/regcprop.cc
> +++ b/gcc/regcprop.cc
> @@ -1358,6 +1358,7 @@ public:
>{}
>
>/* opt_pass methods: */
> + opt_pass *clone () override { return new pass_cprop_hardreg (m_ctxt); }
>bool gate (function *) final override
> {
>return (optimize > 0 && (flag_cprop_registers));
> --cut here--
>
> also shows some code size improvements with x86_64 default linux kernel:
>
> $ size *.o
>textdata bss dec hex filename
> 293785314929075 744820 35052426216db8a vmlinux-add.o
> 293827514929075 744820 35056646216ec06 vmlinux-baseline.o
> 293844594929075 744820 35058354216f2b2 vmlinux-moved.o
>
> where vmlinux-baseline.o is compiled with vanilla GCC, vmlinux-add.o is
> compiled with additional pass_cprop_hardreg after pass_reorder_blocks, and
> vmlinux-moved.o is compiled with pass_cprop_hardreg moved from its current
> position to after pass_reorder_blocks.
>
> The code size changes are:
>
> vmlinux-moved.o: +1708 bytes
> vmlinux-add.o : -4220 bytes
>
> So, it looks there is some benefit by adding another pass_cprop_hardreg
> after pass_reorder_blocks.
Maybe only enabling this pass at -O2+ and not for -Os (because bb reorder for
-Os should not be duplicating the bb).
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901
Uroš Bizjak changed:
What|Removed |Added
Status|RESOLVED|WAITING
Resolution|WONTFIX |---
--- Comment #8 from Uroš Bizjak ---
FTR: Adding *another* pass_cprop_hardreg after pass_reorder_blocks with:
--cut here--
diff --git a/gcc/passes.def b/gcc/passes.def
index cdddb87302f..b5c6e99974b 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -543,6 +543,7 @@ along with GCC; see the file COPYING3. If not see
NEXT_PASS (pass_cprop_hardreg);
NEXT_PASS (pass_fast_rtl_dce);
NEXT_PASS (pass_reorder_blocks);
+ NEXT_PASS (pass_cprop_hardreg);
NEXT_PASS (pass_leaf_regs);
NEXT_PASS (pass_split_before_sched2);
NEXT_PASS (pass_sched2);
diff --git a/gcc/regcprop.cc b/gcc/regcprop.cc
index 2a9956353cc..806dc944b97 100644
--- a/gcc/regcprop.cc
+++ b/gcc/regcprop.cc
@@ -1358,6 +1358,7 @@ public:
{}
/* opt_pass methods: */
+ opt_pass *clone () override { return new pass_cprop_hardreg (m_ctxt); }
bool gate (function *) final override
{
return (optimize > 0 && (flag_cprop_registers));
--cut here--
also shows some code size improvements with x86_64 default linux kernel:
$ size *.o
textdata bss dec hex filename
293785314929075 744820 35052426216db8a vmlinux-add.o
293827514929075 744820 35056646216ec06 vmlinux-baseline.o
293844594929075 744820 35058354216f2b2 vmlinux-moved.o
where vmlinux-baseline.o is compiled with vanilla GCC, vmlinux-add.o is
compiled with additional pass_cprop_hardreg after pass_reorder_blocks, and
vmlinux-moved.o is compiled with pass_cprop_hardreg moved from its current
position to after pass_reorder_blocks.
The code size changes are:
vmlinux-moved.o: +1708 bytes
vmlinux-add.o : -4220 bytes
So, it looks there is some benefit by adding another pass_cprop_hardreg after
pass_reorder_blocks.
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901
Uroš Bizjak changed:
What|Removed |Added
Resolution|--- |WONTFIX
Status|ASSIGNED|RESOLVED
--- Comment #7 from Uroš Bizjak ---
OTOH, late_combine after peephole2 will combine back instructions that are
split on purpose, e.g:
;; Don't compare memory with zero, load and use a test instead.
(define_peephole2
[(set (match_operand 0 "flags_reg_operand")
(match_operator 1 "compare_operator"
[(match_operand:SI 2 "memory_operand")
(const_int 0)]))
(match_scratch:SI 3 "r")]
"optimize_insn_for_speed_p () && ix86_match_ccmode (insn, CCNOmode)"
[(set (match_dup 3) (match_dup 2))
(set (match_dup 0) (match_op_dup 1 [(match_dup 3) (const_int 0)]))])
1084: dx:SI=[`a']
1085: flags:CCZ=cmp(dx:SI,0)
REG_DEAD dx:SI
47: pc={(flags:CCZ==0)?L591:pc}
REG_BR_PROB 16566481
rescanning insn with uid = 1085.
verify found no changes in insn with uid = 1085.
deleting insn with uid = 1084.
1085: flags:CCZ=cmp([`a'],0)
47: pc={(flags:CCZ==0)?L591:pc}
REG_BR_PROB 16566481
so the idea of having late_combine after peephole2 is not that great after all.
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 Uroš Bizjak changed: What|Removed |Added Ever confirmed|0 |1 Last reconfirmed||2026-04-17 Assignee|unassigned at gcc dot gnu.org |ubizjak at gmail dot com Target Milestone|--- |17.0 Status|UNCONFIRMED |ASSIGNED --- Comment #6 from Uroš Bizjak --- Based on the above observations, I plan to propose the following patch for gcc-17: --cut here-- diff --git a/gcc/passes.def b/gcc/passes.def index cdddb87302f..a04414bbe31 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -543,6 +543,7 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_cprop_hardreg); NEXT_PASS (pass_fast_rtl_dce); NEXT_PASS (pass_reorder_blocks); + NEXT_PASS (pass_late_combine); NEXT_PASS (pass_leaf_regs); NEXT_PASS (pass_split_before_sched2); NEXT_PASS (pass_sched2); --cut here--
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 --- Comment #5 from Uroš Bizjak --- (In reply to Drea Pinski from comment #4) > You have to add a clone method to cprop_hardreg. After that it should just > work :). Cutting some corners and just moving pass_cprop_hardreg after pass_reorder_blocks: diff --git a/gcc/passes.def b/gcc/passes.def index cdddb87302f..673bf3ebe46 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -540,9 +540,9 @@ along with GCC; see the file COPYING3. If not see NEXT_PASS (pass_dep_fusion); NEXT_PASS (pass_regrename); NEXT_PASS (pass_fold_mem_offsets); - NEXT_PASS (pass_cprop_hardreg); NEXT_PASS (pass_fast_rtl_dce); NEXT_PASS (pass_reorder_blocks); + NEXT_PASS (pass_cprop_hardreg); NEXT_PASS (pass_leaf_regs); NEXT_PASS (pass_split_before_sched2); NEXT_PASS (pass_sched2); results in: .L4: - movl%eax, %ecx cmpl%esi, (%eax) jne .L11 - movl%ecx, %eax popl%ebx But the pass *does not* perform the trivial propagation of %ecx to %eax in the final BB. The change even slightly regresses linux code size: $ size *.o textdata bss dec hex filename 294341694932443 754228 35120840217e6c8 vmlinux-cprop.o 294155164932443 754228 351021872179deb vmlinux-new.o 294323514932443 754228 35119022217dfae vmlinux-old.o
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 --- Comment #4 from Drea Pinski --- (In reply to Uroš Bizjak from comment #3) > FYI: putting another pass_cprop_hardreg after pass_reorder_blocks fails > self-test with: > > cc1: internal compiler error: pass cprop_hardreg does not support cloning > 0x226f97d internal_error(char const*, ...) >../../git/gcc/gcc/diagnostic-global-context.cc:787 > 0xce6a79 opt_pass::clone() >../../git/gcc/gcc/passes.cc:90 > 0xcf8a86 gcc::pass_manager::pass_manager(gcc::context*) >./pass-instances.def:554 > 0xe3a7d7 general_init >../../git/gcc/gcc/toplev.cc:1164 You have to add a clone method to cprop_hardreg. After that it should just work :).
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 --- Comment #3 from Uroš Bizjak --- FYI: putting another pass_cprop_hardreg after pass_reorder_blocks fails self-test with: cc1: internal compiler error: pass cprop_hardreg does not support cloning 0x226f97d internal_error(char const*, ...) ../../git/gcc/gcc/diagnostic-global-context.cc:787 0xce6a79 opt_pass::clone() ../../git/gcc/gcc/passes.cc:90 0xcf8a86 gcc::pass_manager::pass_manager(gcc::context*) ./pass-instances.def:554 0xe3a7d7 general_init ../../git/gcc/gcc/toplev.cc:1164
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901
--- Comment #2 from Uroš Bizjak ---
> Did you check other places to schedule the pass?
I was interested to exercise opportunities, exposed by bbro pass (as
mentioned in [1]), so the natural place to put the new pass is after
bbro pass:
On x86_32, IRA zeroes %ecx, which is later copied to %eax in the
terminal basic block:
12: NOTE_INSN_BASIC_BLOCK 3
7: cx:SI=0
REG_EQUAL 0
45: pc=L36
...
36: L36:
39: NOTE_INSN_BASIC_BLOCK 7
37: ax:SI=cx:SI
38: use ax:SI
This sequence is reordered in bbro pass to:
28: L28:
12: NOTE_INSN_BASIC_BLOCK 7
69: {cx:SI=0;clobber flags:CC;}
REG_UNUSED flags:CC
71: ax:SI=cx:SI
REG_DEAD cx:SI
72: use ax:SI
73: NOTE_INSN_EPILOGUE_BEG
74: bx:SI=[sp:SI++]
REG_CFA_ADJUST_CFA sp:SI=sp:SI+0x4
REG_CFA_RESTORE bx:SI
75: si:SI=[sp:SI++]
REG_CFA_ADJUST_CFA sp:SI=sp:SI+0x4
REG_CFA_RESTORE si:SI
76: simple_return
When - fno-reorder-blocks -fno-reorder-blocks-and-partition options are added
to compile options, the newly added pass_late_combine does nothing. So, there
indeed are new opportunities only when BB reorders blocks (duplicates paths?).
[1] https://gcc.gnu.org/pipermail/gcc-patches/2026-April/713048.html
[Bug rtl-optimization/124901] Add pass_late_combine after pass_reorder_blocks
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124901 --- Comment #1 from Uroš Bizjak --- > Did you try moving the existing postreload late_combine later? While moving the pass results in the same code for the above trivial testcase, it regressed linux code size considerably: $size *.o textdata bss dec hex filename 294838804932443 754228 35170551218a8f7 vmlinux-moved.o 294155164932443 754228 351021872179deb vmlinux-new.o 294323514932443 754228 35119022217dfae vmlinux-old.o The postreload late_combine pass apparently frees some registers, so follow-up passes can use them. This is not the case when the pass is simply moved to the new location. The instructions are still combined when the pass is moved after bbro pass, but used registers are "dead" for the preceding optimization passes.
