<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/CodeGen/BranchRelaxation.cpp, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[BranchRelaxation] Fix invalid branch generation in branch-relaxation (#162065)</title>
<updated>2025-10-15T16:31:50+00:00</updated>
<author>
<name>sc-clulzze</name>
<email>d.marakulin@syntacore.com</email>
</author>
<published>2025-10-15T16:31:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=ce60a03573a4d9f28dd6de42f61f0a3c4b0f2be9'/>
<id>ce60a03573a4d9f28dd6de42f61f0a3c4b0f2be9</id>
<content type='text'>
If we have MBB with only one successor which is accessable through both
conditional and unconditional branches (TBB == FBB), in
`fixupConditionalBranch` we will first replace FBB with NewMBB in
successors list - `MBB-&gt;replaceSuccessor(FBB, NewBB);`, and then create
branch to TBB - `insertBranch(MBB, &amp;NextBB, TBB, Cond);`, ending up with
two branches to different blocks, but only one successor.

Fixes: https://github.com/llvm/llvm-project/issues/162063</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If we have MBB with only one successor which is accessable through both
conditional and unconditional branches (TBB == FBB), in
`fixupConditionalBranch` we will first replace FBB with NewMBB in
successors list - `MBB-&gt;replaceSuccessor(FBB, NewBB);`, and then create
branch to TBB - `insertBranch(MBB, &amp;NextBB, TBB, Cond);`, ending up with
two branches to different blocks, but only one successor.

Fixes: https://github.com/llvm/llvm-project/issues/162063</pre>
</div>
</content>
</entry>
<entry>
<title>[CodeGen] Remove unused local variables (NFC) (#138441)</title>
<updated>2025-05-04T07:26:37+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2025-05-04T07:26:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=47f391fd0e1d9ae6a91e625cff5490dd89a8a17e'/>
<id>47f391fd0e1d9ae6a91e625cff5490dd89a8a17e</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[CodeGen][NPM] Port BranchRelaxation to NPM (#130067)</title>
<updated>2025-04-14T04:49:42+00:00</updated>
<author>
<name>Akshat Oke</name>
<email>Akshat.Oke@amd.com</email>
</author>
<published>2025-04-14T04:49:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b283ff7eb1d7558594063528af7a94cfe2390e98'/>
<id>b283ff7eb1d7558594063528af7a94cfe2390e98</id>
<content type='text'>
This completes the PreEmitPasses.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This completes the PreEmitPasses.</pre>
</div>
</content>
</entry>
<entry>
<title>[BranchRelaxation] Remove quadratic behavior in relaxation pass (#96250)</title>
<updated>2024-09-27T13:57:07+00:00</updated>
<author>
<name>Daniel Hoekwater</name>
<email>hoekwater@google.com</email>
</author>
<published>2024-09-27T13:57:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=22c8b1d853dfde925eb63c4907332c596048c631'/>
<id>22c8b1d853dfde925eb63c4907332c596048c631</id>
<content type='text'>
Currently, we recompute block offsets after each relaxation. This causes
the complexity to be O(n^2) in the number of instructions, inflating
compile
time.

If we instead recompute block offsets after each iteration of the outer
loop, the complexity is O(n). Recomputing offsets in the outer loop will
cause some out-of-range branches to be missed in the inner loop, but
they will be relaxed in the next iteration of the outer loop.

This change may introduce unnecessary relaxations for an architecture
where the relaxed branch is smaller than the unrelaxed branch, but AFAIK
there is no such architecture.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Currently, we recompute block offsets after each relaxation. This causes
the complexity to be O(n^2) in the number of instructions, inflating
compile
time.

If we instead recompute block offsets after each iteration of the outer
loop, the complexity is O(n). Recomputing offsets in the outer loop will
cause some out-of-range branches to be missed in the inner loop, but
they will be relaxed in the next iteration of the outer loop.

This change may introduce unnecessary relaxations for an architecture
where the relaxed branch is smaller than the unrelaxed branch, but AFAIK
there is no such architecture.</pre>
</div>
</content>
</entry>
<entry>
<title>[AArch64] [BranchRelaxation] Optimize for hot code size in AArch64 branch relaxation</title>
<updated>2023-09-06T20:44:40+00:00</updated>
<author>
<name>Daniel Hoekwater</name>
<email>hoekwater@google.com</email>
</author>
<published>2023-07-29T00:01:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=866ae69cfa73ce224944c64965d0426637e31517'/>
<id>866ae69cfa73ce224944c64965d0426637e31517</id>
<content type='text'>
On AArch64, it is safe to let the linker handle relaxation of
unconditional branches; in most cases, the destination is within range,
and the linker doesn't need to do anything. If the linker does insert
fixup code, it clobbers the x16 inter-procedural register, so x16 must
be available across the branch before linking. If x16 isn't available,
but some other register is, we can relax the branch either by spilling
x16 OR using the free register for a manually-inserted indirect branch.

This patch builds on D145211. While that patch is for correctness, this
one is for performance of the common case. As noted in
https://reviews.llvm.org/D145211#4537173, we can trust the linker to
relax cross-section unconditional branches across which x16 is
available.

Programs that use machine function splitting care most about the
performance of hot code at the expense of the performance of cold code,
so we prioritize minimizing hot code size.

Here's a breakdown of the cases:

   Hot -&gt; Cold [x16 is free across the branch]
     Do nothing; let the linker relax the branch.

   Cold -&gt; Hot [x16 is free across the branch]
     Do nothing; let the linker relax the branch.

   Hot -&gt; Cold [x16 used across the branch, but there is a free register]
     Spill x16; let the linker relax the branch.

     Spilling requires fewer instructions than manually inserting an
     indirect branch.

   Cold -&gt; Hot [x16 used across the branch, but there is a free register]
     Manually insert an indirect branch.

     Spilling would require adding a restore block in the hot section.

   Hot -&gt; Cold [No free regs]
     Spill x16; let the linker relax the branch.

   Cold -&gt; Hot [No free regs]
     Spill x16 and put the restore block at the end of the hot function; let the linker relax the branch.
     Ex:
       [Hot section]
       func.hot:
         ... hot code...
       func.restore:
         ... restore x16 ...
         B func.hot

       [Cold section]
         func.cold:
         ... spill x16 ...
         B func.restore

     Putting the restore block at the end of the function instead of
     just before the destination increases the cost of executing the
     store, but it avoids putting cold code in the middle of hot code.
     Since the restore is very rarely taken, this is a worthwhile
     tradeoff.

Differential Revision: https://reviews.llvm.org/D156767
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
On AArch64, it is safe to let the linker handle relaxation of
unconditional branches; in most cases, the destination is within range,
and the linker doesn't need to do anything. If the linker does insert
fixup code, it clobbers the x16 inter-procedural register, so x16 must
be available across the branch before linking. If x16 isn't available,
but some other register is, we can relax the branch either by spilling
x16 OR using the free register for a manually-inserted indirect branch.

This patch builds on D145211. While that patch is for correctness, this
one is for performance of the common case. As noted in
https://reviews.llvm.org/D145211#4537173, we can trust the linker to
relax cross-section unconditional branches across which x16 is
available.

Programs that use machine function splitting care most about the
performance of hot code at the expense of the performance of cold code,
so we prioritize minimizing hot code size.

Here's a breakdown of the cases:

   Hot -&gt; Cold [x16 is free across the branch]
     Do nothing; let the linker relax the branch.

   Cold -&gt; Hot [x16 is free across the branch]
     Do nothing; let the linker relax the branch.

   Hot -&gt; Cold [x16 used across the branch, but there is a free register]
     Spill x16; let the linker relax the branch.

     Spilling requires fewer instructions than manually inserting an
     indirect branch.

   Cold -&gt; Hot [x16 used across the branch, but there is a free register]
     Manually insert an indirect branch.

     Spilling would require adding a restore block in the hot section.

   Hot -&gt; Cold [No free regs]
     Spill x16; let the linker relax the branch.

   Cold -&gt; Hot [No free regs]
     Spill x16 and put the restore block at the end of the hot function; let the linker relax the branch.
     Ex:
       [Hot section]
       func.hot:
         ... hot code...
       func.restore:
         ... restore x16 ...
         B func.hot

       [Cold section]
         func.cold:
         ... spill x16 ...
         B func.restore

     Putting the restore block at the end of the function instead of
     just before the destination increases the cost of executing the
     store, but it avoids putting cold code in the middle of hot code.
     Since the restore is very rarely taken, this is a worthwhile
     tradeoff.

Differential Revision: https://reviews.llvm.org/D156767
</pre>
</div>
</content>
</entry>
<entry>
<title>Reland "[AArch64][CodeGen] Avoid inverting hot branches during relaxation""</title>
<updated>2023-08-21T17:29:47+00:00</updated>
<author>
<name>Daniel Hoekwater</name>
<email>hoekwater@google.com</email>
</author>
<published>2023-08-21T17:24:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=e223e4567722661f1b32aa052cd13d9f47b896d9'/>
<id>e223e4567722661f1b32aa052cd13d9f47b896d9</id>
<content type='text'>
This is a reland of 46d2d7599d9ed5e68fb53e910feb10d47ee2667b, which was
reverted because of breaking build
https://lab.llvm.org/buildbot/#/builders/21/builds/78779. However, this
buildbot is spuriously broken due to Flang::underscoring.f90 being
nondeterministic.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is a reland of 46d2d7599d9ed5e68fb53e910feb10d47ee2667b, which was
reverted because of breaking build
https://lab.llvm.org/buildbot/#/builders/21/builds/78779. However, this
buildbot is spuriously broken due to Flang::underscoring.f90 being
nondeterministic.
</pre>
</div>
</content>
</entry>
<entry>
<title>Revert "[AArch64][CodeGen] Avoid inverting hot branches during relaxation"</title>
<updated>2023-08-21T17:13:35+00:00</updated>
<author>
<name>Daniel Hoekwater</name>
<email>hoekwater@google.com</email>
</author>
<published>2023-08-21T17:13:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=0303137bfcf2e28fb2d9387b67f91b00ca6b42f5'/>
<id>0303137bfcf2e28fb2d9387b67f91b00ca6b42f5</id>
<content type='text'>
This reverts commit 46d2d7599d9ed5e68fb53e910feb10d47ee2667b.
Breaks build https://lab.llvm.org/buildbot/#/builders/21/builds/78779
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This reverts commit 46d2d7599d9ed5e68fb53e910feb10d47ee2667b.
Breaks build https://lab.llvm.org/buildbot/#/builders/21/builds/78779
</pre>
</div>
</content>
</entry>
<entry>
<title>[AArch64][CodeGen] Avoid inverting hot branches during relaxation</title>
<updated>2023-08-21T16:41:02+00:00</updated>
<author>
<name>Daniel Hoekwater</name>
<email>hoekwater@google.com</email>
</author>
<published>2023-08-01T23:55:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=46d2d7599d9ed5e68fb53e910feb10d47ee2667b'/>
<id>46d2d7599d9ed5e68fb53e910feb10d47ee2667b</id>
<content type='text'>
Current behavior for relaxing out-of-range conditional branches
is to invert the conditional and insert a fallthrough unconditional
branch to the original destination. This approach biases the branch
predictor in the wrong direction, which can degrading performance.

Machine function splitting introduces many rarely-taken cross-section
conditional branches, which are improperly relaxed. Avoid inverting
these branches; instead, retarget them to trampolines at the end of the
function. Doing so increases the runtime cost of jumping to cold code
but eliminates the misprediction cost of jumping to hot code.

Differential Revision: https://reviews.llvm.org/D156837
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Current behavior for relaxing out-of-range conditional branches
is to invert the conditional and insert a fallthrough unconditional
branch to the original destination. This approach biases the branch
predictor in the wrong direction, which can degrading performance.

Machine function splitting introduces many rarely-taken cross-section
conditional branches, which are improperly relaxed. Avoid inverting
these branches; instead, retarget them to trampolines at the end of the
function. Doing so increases the runtime cost of jumping to cold code
but eliminates the misprediction cost of jumping to hot code.

Differential Revision: https://reviews.llvm.org/D156837
</pre>
</div>
</content>
</entry>
<entry>
<title>[AArch64] Relax cross-section branches</title>
<updated>2023-08-16T01:43:07+00:00</updated>
<author>
<name>Daniel Hoekwater</name>
<email>hoekwater@google.com</email>
</author>
<published>2023-06-30T22:40:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=d7bca8e4942b97a6442425d5f741cb4665582446'/>
<id>d7bca8e4942b97a6442425d5f741cb4665582446</id>
<content type='text'>
Because the code layout is not known during compilation, the distance of
cross-section jumps is not knowable at compile-time. Because of this, we
should assume that any cross-sectional jumps are out of range. This
assumption is necessary for machine function splitting on AArch64, which
introduces cross-section branches in the middle of functions. The linker
relaxes out-of-range unconditional branches, but it clobbers X16 to do
so; it doesn't relax conditional branches, which must be manually
relaxed by the compiler.

Differential Revision: https://reviews.llvm.org/D145211
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Because the code layout is not known during compilation, the distance of
cross-section jumps is not knowable at compile-time. Because of this, we
should assume that any cross-sectional jumps are out of range. This
assumption is necessary for machine function splitting on AArch64, which
introduces cross-section branches in the middle of functions. The linker
relaxes out-of-range unconditional branches, but it clobbers X16 to do
so; it doesn't relax conditional branches, which must be manually
relaxed by the compiler.

Differential Revision: https://reviews.llvm.org/D145211
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix uninitialized pointer members in CodeGen</title>
<updated>2023-04-17T08:32:46+00:00</updated>
<author>
<name>Akshay Khadse</name>
<email>akshayskhadse@gmail.com</email>
</author>
<published>2023-04-17T08:16:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=8bf7f86d7966ff835967669fb6bf23897e20b71d'/>
<id>8bf7f86d7966ff835967669fb6bf23897e20b71d</id>
<content type='text'>
This change initializes the members TSI, LI, DT, PSI, and ORE pointer feilds of the SelectOptimize class to nullptr.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D148303
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This change initializes the members TSI, LI, DT, PSI, and ORE pointer feilds of the SelectOptimize class to nullptr.

Reviewed By: LuoYuanke

Differential Revision: https://reviews.llvm.org/D148303
</pre>
</div>
</content>
</entry>
</feed>
