Skip to content

rsz: Stop buffer removal and rebuffering from undoing each other - #12398

Open
jhkim-pii wants to merge 11 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:rsz-buffer-move-touched-buffers-merge
Open

jhkim-pii wants to merge 11 commits into
The-OpenROAD-Project:masterfrom
The-OpenROAD-Project-staging:rsz-buffer-move-touched-buffers-merge

Conversation

@jhkim-pii

@jhkim-pii jhkim-pii commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • BufferCandidate::apply() now reports the buffers that rebuffering inserted in touched_instances, so buffer removal can no longer undo them ("it was from rebuffering") and the remove/re-insert loop on one net is gone.
  • QoR is neutral on average across three benchmarks (Fmax mean -0.05% to +0.08%), with large gains on designs that hit the loop (up to +2.29% Fmax and a 5.9x faster GRT-stage repair).

Symptom

  • In LEGACY setup repair, buffer removal deletes the buffers that rebuffering just inserted, and rebuffering inserts them again, so one endpoint loops without progress until it hits the stuck limit and is rolled back.
  • Master on asap7/aes-block (ORFS CI, CTS stage): Every 10 iterations remove 5 buffers and insert 5 buffers while nothing else changes, and iteration 156 rolls the endpoint back.
   Iter   | Removed | Resized | Inserted | Cloned |  Pin  |   Area   |    WNS   |    TNS     |  Viol
          | Buffers |  Gates  | Buffers  |  Gates | Swaps |          |          |            | Endpts
     110* |       4 |      26 |       18 |      0 |     6 |    +0.0% |  -50.392 |    -2517.9 |    114
     120* |       9 |      26 |       23 |      0 |     6 |    +0.0% |  -50.392 |    -2517.9 |    114
     130* |      14 |      26 |       28 |      0 |     6 |    +0.0% |  -50.392 |    -2517.9 |    114
     140* |      19 |      26 |       33 |      0 |     6 |    +0.0% |  -50.392 |    -2517.9 |    114
     150* |      24 |      26 |       38 |      0 |     6 |    +0.0% |  -50.392 |    -2517.9 |    114
     156* |       2 |      26 |       16 |      0 |     6 |    +0.0% |  -50.392 |    -2517.9 |    114
  • Worst case (secure PDK design 1): The CTS-stage repair stops improving WNS at iteration 65 of 1,500 and keeps only 1 inserted buffer and 35 resized gates, so WNS improves by 14% instead of 41% with this PR.

Changes

Item Before After
Rebuffer::rebufferPin() Returns only the number of inserted buffers Also returns the inserted buffers through an optional out-parameter
BufferCandidate::apply() touched_instances = {driver} touched_instances = {driver, inserted buffers}
Removal of a rebuffered buffer Allowed Blocked for the rest of the repair_timing call ("it was from rebuffering")
BUILD move/BufferCandidate.hh in srcs In the test-visible hdrs
flowchart LR
  B["BufferMove on driver U1<br/>inserts rb1, rb2"] --> T{"touched_instances"}
  T -->|"Before: U1 only"| R1["UnbufferMove removes rb1<br/>(guard does not match)"]
  R1 -->|"next pass"| B
  T -->|"After: U1, rb1, rb2"| R2["UnbufferMove skips rb1, rb2<br/>(it was from rebuffering)"]
Loading

Impact

Benchmark Designs changed Fmax mean (better / worse) TNS better / worse FEP Area Power repair_timing runtime
ORFS CI, public PDKs (60 designs) 7 -0.05% (2 / 4) 3 / 4 31123 → 31139 +0.04% +0.04% 2208 → 1684 s
ORFS CI, secure PDKs (20 runs) 4 +0.08% (3 / 1) 4 / 0 14551 → 14465 0.00% -0.02% Machine drift only
Post-CTS benchmark (34 designs) 9 +0.05% (4 / 1) 4 / 4 16614 → 16305 -0.08% -0.10% 2706 → 2767 s (noise)
  • Area and power are the mean change per design, where positive means larger.
  • The loop is gone: Master shows the remove/re-insert pattern in 9 of 160 ORFS CI repair logs (7 designs), and this PR shows it in none.
  • Largest gains: Secure PDK design 1 gains 2.29% Fmax, asap7/bp2 in the post-CTS benchmark gains 1.47%, and the GRT-stage repair_timing of nangate45/mempool_group drops from 584 s to 99 s with better TNS.
  • Largest losses: Four runs lose more than 0.5% Fmax, ihp-sg13g2/aes (-1.54%, +0.88% area), ihp-sg13g2/jpeg (-1.22%), secure PDK design 4 (-1.22%), and gf180/aes (-0.54%, +1.69% area).
  • In the two aes runs, the CTS-stage repair inserts 33% to 56% more buffers than master for the same WNS.
  • ORFS follow-up: The ihp-sg13g2/jpeg run exceeds two ORFS CI rule limits (finish TNS -2.75 vs -1.92 ns, antenna diodes 126 vs 100), so the ORFS update that picks up this PR needs new rules for it.

Related

Details

Mechanism

How the loop forms

  • UnbufferMove asks MoveCommitter::hasBlockingBufferRemovalMove() before it removes a buffer, and one of its rules is "it was from rebuffering", which checks hasMoves(kBuffer, buffer).
  • BufferCandidate::apply() reported only the driver in touched_instances, so a buffer that rebuffering inserted never matched this rule.
  • Removal and rebuffering then undo each other on one net until the endpoint is declared stuck and rolled back:
pass k     BufferMove(U1)    inserts rb1, rb2      touched = {U1}
pass k+1   UnbufferMove(rb1) removes rb1           guard: hasMoves(kBuffer, rb1) = false
pass k+2   BufferMove(U1)    inserts rb3
pass k+3   UnbufferMove(rb3) removes rb3
...        50 non-improving passes -> endpoint stuck -> restore the best checkpoint
  • With this PR, touched_instances holds U1, rb1, and rb2, so hasMoves(kBuffer, rb1) is true and removal skips rb1 for the rest of the repair_timing call.

Why the simple version

Test Undo once Never undo (this PR)
repair_fanout7_multi -1.259 / +78.6% -1.141 / +53.5%
repair_fanout8 -1.308 / +96.5% -1.332 / +80.8%
repair_fanout8_multi -1.344 / +85.2% -1.332 / +81.3%
repair_setup4_sequence -0.303 / +15.1% -0.358 / +16.9%
repair_setup_path4 (asap7, ps) -1.017 / +1.2% -2.584 / +1.3%
  • Since the results are mixed, this PR keeps the simpler rule, which needs no extra committer state.

Other users of the touched instances

  • CloneGenerator skips a driver with a pending buffer move, so the new buffers are not cloned until the move is committed.
  • RebufferMtGenerator skips a driver that already has a buffer move, which only matters when a PARALLEL_EVAL phase runs after a LEGACY phase in the same repair_timing call.

Experiments

Setup

  • Before is OpenROAD master 4b24103b4c, and After is this PR (e1a83b42b7), which adds only the changes of this PR on top of it.
  • All runs use the default repair_timing phases (LEGACY LAST_GASP CRIT_VT_SWAP).
  • ORFS CI: The same ORFS master commit with only the OpenROAD submodule changed, on 62 public-PDK designs and 20 secure-PDK runs.
  • The cva6 (asap7) and ariane133 (nangate45) runs fail macro placement (MPL-0048) in both builds before any timing repair, so 60 public-PDK designs are compared.
  • Post-CTS benchmark: Standalone repair_timing on 34 saved post-CTS databases (29 public-PDK, 5 secure-PDK designs), where runtime counts the repair_timing command only.
  • Secure-PDK designs are numbered (design 1 to 5), and their timing is shown as relative change only.
  • Fmax uses the shortest real clock period, Fmax = 1 / (period - min(WNS, 0)).
  • A log shows the loop when at least two consecutive progress rows add the same number of removed and inserted buffers while the resized count and WNS stay the same.

ORFS CI, public PDKs (changed designs, finish stage)

Design WNS (ns) TNS (ns) FEP Fmax Area Power
asap7/aes-block -0.00750 → -0.00779 -0.0164 → -0.0151 6 → 4 -0.06% +0.03% 0.00%
gf180/aes -0.679 → -0.699 -97.9 → -98.1 198 → 198 -0.54% +1.69% +1.54%
ihp-sg13g2/aes -0.499 → -0.538 -70.2 → -73.8 259 → 259 -1.54% +0.88% +1.17%
ihp-sg13g2/i2c-gpio-expander -1.136 → -1.127 -1.78 → -1.77 2 → 2 +0.09% +0.09% -0.12%
ihp-sg13g2/jpeg -0.098 → -0.149 -1.12 → -2.75 32 → 64 -1.22% +0.07% +0.02%
nangate45/mempool_group -2.160 → -2.160 -11744 → -11557 8696 → 8696 0.00% +0.13% +0.04%
nangate45/swerv_wrapper -0.259 → -0.256 -266.3 → -268.4 1756 → 1742 +0.16% -0.34% 0.00%

ORFS CI, secure PDKs (changed runs, finish stage)

Design WNS TNS FEP Fmax Area Power
Design 1 54% better 28% better 501 → 519 +2.29% +0.08% -0.02%
Design 2 10% better 24% better 45 → 33 +0.17% +0.01% +0.01%
Design 3 16% better 49% better 127 → 39 +0.38% -0.05% -0.35%
Design 4 2.2% worse 1.2% better 272 → 268 -1.22% -0.03% +0.05%

Post-CTS benchmark (changed designs)

Design WNS (ns) TNS (ns) FEP Fmax Area Power
asap7/bp2 -0.0721 → -0.0612 -22.95 → -23.79 1491 → 1821 +1.47% -0.01% -0.01%
nangate45/xiangshan_l2 -0.0060 → -0.0009 -0.017 → -0.002 4 → 2 +0.26% 0.00% +0.01%
nangate45/aes -0.0383 → -0.0383 -3.27 → -3.87 152 → 156 0.00% -2.86% -3.62%
asap7/aes -0.0155 → -0.0155 -0.718 → -0.696 116 → 110 0.00% 0.00% +0.14%
ihp-sg13g2/aes -0.0253 → -0.0253 -0.125 → -0.177 10 → 13 0.00% -0.08% -0.09%
ihp-sg13g2/gcd -0.0666 → -0.0666 -0.131 → -0.138 3 → 4 0.00% +0.13% +0.08%
Design 5 0.2% worse 36% better 3437 → 2798 -0.02% +0.10% -0.02%
  • asap7/rocket_gemmini and nangate45/bp2 change area or power by less than 0.01%.

Runtime

  • ORFS CI, public PDKs: repair_timing in the CTS and GRT stages takes 2208 → 1684 s in total, where nangate45/mempool_group alone goes 829 → 332 s and the rest (1379 → 1352 s, -2%) matches the drift of unchanged designs (0.94x to 1.00x).
  • ORFS CI, secure PDKs: Unchanged runs took 1.20x longer in the After build (machine drift), and changed runs moved by the same ratio (1.22x), so no runtime change is visible.
  • Post-CTS benchmark: 2706 → 2767 s (+2.3%, geomean speedup 1.00x), while designs with identical QoR vary by up to 29%, so this is noise.

Testing

  • bazelisk test //openroad/rsz/test/...: 331/331 pass, including the new TestResizer.BufferMoveMarksInsertedBuffers, which fails without the fix.
  • The 14 changed golden tests pass on the current master as is, so the changes come from this PR.
  • Golden changes against the current master (final WNS / area; ns except repair_setup_path4 in ps):
Test master This PR
clone_flat, repair_fanout7 -1.213 / +47.0% -1.204 / +48.3%
repair_fanout7_multi -1.259 / +83.2% -1.141 / +53.5%
repair_fanout7_skip_pin_swap -1.212 / +47.1% -1.204 / +71.0%
repair_fanout8 -1.370 / +71.1% -1.332 / +80.8%
repair_fanout8_multi -1.342 / +75.2% -1.332 / +81.3%
repair_setup_path4 (asap7) -1.017 / +1.2% -2.584 / +1.3%
repair_setup_path11 -0.072 / +5.4% -0.072 / +7.5%
repair_setup_path16 -5.906 / +7.9% -5.899 / +8.5%
repair_setup_path19 -1.505 / +11.7% -1.496 / +13.4%
  • repair_setup4_sequence and repair_setup_path1, 17, and 18 keep their QoR and change only the iteration count, and clone_flat_out.vok follows clone_flat.
  • The rule also blocks removals that would help, since repair_setup_path4 keeps two rebuffered buffers in series on its critical path.

Merge with master

  • Master renamed src/ to openroad/, so the Rebuffer.hh and TestResizer.cc changes were ported by hand.
  • The second master merge conflicted only in five goldens, which were resolved by rerunning the tests, and the source changes of this PR are unchanged.

maliberty and others added 10 commits September 26, 2026 21:55
BufferCandidate::apply() reported only the driver as touched, so
MoveCommitter never recorded the buffers that rebuffering inserted.
MoveCommitter::hasBlockingBufferRemovalMove() checks for kBuffer moves on
the buffer instance itself, so its "it was from rebuffering" guard never
matched them, and UnbufferMove could remove a buffer that BufferMove had
just inserted in the same repair session.

Rebuffer now remembers the buffers inserted by the last rebufferPin()
call, and BufferCandidate adds them to the touched instances.

Found on a large design with more frequent buffer removal, where the
missing guard produced remove/re-insert loops on the same net for 50
passes until the endpoint was rolled back.

Adds TestResizer.BufferMoveMarksInsertedBuffers (fails without the fix)
and updates goldens of tests whose repair_timing results change because
removal can no longer undo BufferMove's buffers.

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
Blocking removal of every BufferMove-inserted buffer stopped the
remove/re-insert loop but also blocked removals that were a net win,
e.g. repair_setup4_sequence lost WNS and gained 11% area.

Removal may now take out one buffer that rebuffering inserted on a
driver.  After that, every buffer rebuffering inserted on that driver,
earlier or later, is kept, which still breaks the loop.

BufferCandidate reports its inserted buffers in a new
MoveResult::inserted_buffers field instead of touched_instances, and
MoveCommitter tracks the driver of each.  Locking only buffers
reinserted after the removal let siblings from the first buffer tree
keep feeding the cycle and grew repair_fanout8 area to +77%.

repair_setup4_sequence and repair_setup_gcd goldens return to master's.

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
…ouched-buffers

Signed-off-by: Matt Liberty <mliberty@precisioninno.com>

# Conflicts:
#	src/rsz/test/cpp/TestResizer.cc
#	src/rsz/test/repair_fanout7_multi.ok
#	src/rsz/test/repair_fanout8_multi.ok
Resolve the conflicts with master, which renamed src/ to openroad/:
- Port the Rebuffer.hh and TestResizer.cc changes of this branch to
  openroad/rsz, where git did not detect the rename.
- BUILD: keep master's test-visible hdrs, which already list
  src/Rebuffer.hh, and move src/move/BufferCandidate.hh there.
- Rebuffer.cc: master moved the top-port check at the start of
  rebufferPin() into makeBufferedNet(), and the merge put the
  last_inserted_buffers_ reset there with it.  Move the reset back to the
  start of rebufferPin().
- Goldens keep master's version here; a later commit refreshes them.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
recordRebufferInteraction() took the driver of every accepted buffer
move from touched_instances.front().  The StubBufferMoveCandidate of
master's TestResizerMt returns a buffer move without touched instances,
so TestResizerMt.RepairSetupProfilerNestedCommitThenOuterUndo aborted on
the libc++ hardening check of front().

Only BufferMove reports inserted buffers, so return early when a buffer
move reports none.  Buffer moves without them, such as RebufferMt and the
test stub, are not recorded.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Buffer removal may now undo a driver's rebuffering only once, which
changes these logs on current master (final WNS, area, last iteration):

  test                          master                  this branch
  clone_flat, repair_fanout7    -1.213, +47.0%, 1500    -1.213, +48.0%, 1300
  repair_fanout7_multi          -1.259, +83.2%, 1800    -1.259, +78.6%, 1400
  repair_fanout7_skip_pin_swap  -1.212, +47.1%, 1400    -1.212, +74.3%, 1300
  repair_fanout8                -1.370, +71.1%, 1300    -1.308, +96.5%, 1300
  repair_fanout8_multi          -1.342, +75.2%, 1400    -1.344, +85.2%, 1200
  repair_setup4_sequence        -0.358, +16.9%, 316     -0.303, +15.1%, 36
  repair_setup_path16           -5.842, +8.6%, 1200     -5.795, +8.8%, 1400
  repair_setup_path19           -1.520, +11.5%, 1175    -1.510, +12.5%, 323

repair_setup_path1, 11, 17, and 18 change only the iteration count.
clone_flat_out.vok follows clone_flat.  All of these tests pass on master
as is.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Go back to the first version of this change: BufferCandidate::apply()
reports the buffers of the last rebufferPin() call in touched_instances,
so MoveCommitter::hasBlockingBufferRemovalMove() keeps all of them with
"it was from rebuffering" for the rest of the repair_timing call.  This
drops the per-driver "undo once" bookkeeping (MoveResult::inserted_buffers,
the rebuffer driver map in MoveCommitter, and its empty-move guard).

The simple rule needs no extra committer state.  On the rsz goldens it is
better than "undo once" on the fanout tests and worse where removing a
rebuffered buffer helps: repair_setup_path4 keeps two rebuffered buffers
in series on its critical path.

Replace the two committer tests with TestResizer.BufferMoveMarksInsertedBuffers
and refresh the goldens of the 15 tests whose repair_timing results change.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
Resolve the conflicts with master in five rsz goldens that both sides
changed (repair_setup6_multi and repair_setup_path1, 11, 16, and 19):
keep master's version here; the next commit refreshes the ones this
branch changes.  The source changes of this branch merge cleanly and are
unchanged.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
On current master, blocking the removal of rebuffered buffers changes
these logs (final WNS, TNS, area):

  test                  master                   this branch
  repair_setup_path11   -0.072, -0.5, +5.4%      -0.072, -0.7, +7.5%
  repair_setup_path16   -5.906, -1842.4, +7.9%   -5.899, -1840.1, +8.5%
  repair_setup_path19   -1.505, -49.6, +11.7%    -1.496, -48.4, +13.4%

repair_setup_path1 changes only its last iteration, and
repair_setup6_multi now matches master.  All five tests pass on master
as is.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@jhkim-pii jhkim-pii self-assigned this Nov 20, 2026
@jhkim-pii
jhkim-pii marked this pull request as ready for review November 20, 2026 06:01
@jhkim-pii
jhkim-pii requested a review from a team as a code owner November 20, 2026 06:01
@jhkim-pii
jhkim-pii requested a review from minjukim55 November 20, 2026 06:01

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures that buffers inserted during setup rebuffering (BufferMove) are correctly tracked and reported as touched instances. Specifically, the Rebuffer class now records the buffers inserted during the most recent rebufferPin call, and BufferCandidate::apply appends these inserted buffers to the list of touched instances returned in MoveResult. This prevents conflict guards, such as MoveCommitter::hasBlockingBufferRemovalMove(), from mistakenly undoing these newly inserted buffers. A new C++ unit test has been added to verify this behavior, and several timing regression test outputs have been updated accordingly. No review comments were provided for evaluation.

@jhkim-pii

jhkim-pii commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@maliberty Could you please review this?

  • Resolved the rebuffer & buffer removal loop in a simpler way (just add new buffers into touched_instances). Outcome is similar.

@minjukim55

Copy link
Copy Markdown
Member

AI-assisted review via review-bot (Model: Gemini 4 Neon, fact-checked against base commit)

Clean root-cause fix — propagating inserted buffers through touched_instances cleanly breaks the remove/re-insert loop. A few points before merge:

  1. Rebuffer::last_inserted_buffers_ accumulates across non-rebufferPin() callers

    • Issue: exportBufferTree() (Rebuffer.cc:2900) always appends to last_inserted_buffers_, while only rebufferPin() (Rebuffer.cc:3721) clears it. fullyRebuffer() (Rebuffer.cc:3322) and applyRebufferTreePlan() (Rebuffer.cc:3715, called by RebufferMtCandidate and DelayEstimatorReporter, which immediately undoes its ECO) accumulate raw sta::Instance* pointers indefinitely on session-lived Resizer::rebuffer_, leaving dangling pointers and breaking lastInsertedBuffers()'s contract.
    • Suggestion: Replace the member with an optional out-parameter std::vector<sta::Instance*>* inserted_buffers = nullptr on exportBufferTree(), rebufferPin(), and applyRebufferTreePlan().
  2. Symmetry with RebufferMtCandidate::apply()

    • Issue: UnbufferMtGenerator::isApplicable() (UnbufferMtGenerator.cc:352-359) checks the same kBuffer guard, but RebufferMtCandidate::apply() (RebufferMtCandidate.cc:162) still returns only {driver_inst} in touched_instances, leaving its buffers unprotected from UnbufferMt.
    • Suggestion: Thread the same inserted_buffers out-parameter through applyRebufferTreePlan() into RebufferMtCandidate::apply() (or note as a follow-up if keeping PARALLEL_EVAL unchanged here).
  3. QoR check on regressing ORFS designs

    • Issue: "Never undo" vs. "undo once" (rsz: report BufferMove-inserted buffers as touched #11536) was compared on 5 small rsz tests, while full ORFS runs regress ihp-sg13g2/aes (-1.54% Fmax, +33–56% buffers) and exceed two ihp-sg13g2/jpeg CI rules (TNS -2.75 vs -1.92 ns, antenna diodes 126 vs 100).
    • Suggestion: Worth checking whether "undo once" avoids the ihp-sg13g2/jpeg CI breaches and aes buffer growth before relaxing ORFS CI limits.
  4. Test nit (TestResizer.cc:765)

    • Issue: ASSERT_GT(result.touched_instances.size(), 1) doesn't verify that all move_count inserted buffers plus the driver at index 0 are recorded.
    • Suggestion: Check ASSERT_EQ(result.touched_instances.size(), static_cast<size_t>(result.move_count) + 1) and touched_instances.front().

@jhkim-pii

Copy link
Copy Markdown
Contributor Author
  1. Good suggestion.
  2. PARALLEL_EVAL does not suffer from the insert/remove buffer issue. I'll check the suggested change later.
  3. Not taken. Some test cases experience QoR change.
  4. Taken.

Rebuffer kept the buffers of the last rebufferPin() call in
last_inserted_buffers_, but exportBufferTree() also appended to it for
fullyRebuffer() and applyRebufferTreePlan(), and only rebufferPin()
cleared it.  The vector could hold buffers of other callers, including
instances that were deleted later.

Replace the member and lastInsertedBuffers() with an optional
inserted_buffers out-parameter on rebufferPin() and exportBufferTree().
BufferCandidate::apply() passes a local vector, so it gets exactly the
buffers of its own call, and the other callers pass nothing.

BufferMoveMarksInsertedBuffers now checks that touched_instances holds
the driver first and exactly move_count buffers after it.

No behavior change: the rsz tests pass 331/331 with unchanged goldens.

Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
@github-actions github-actions Bot added size/M and removed size/S labels Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants