Skip to content

Commit

Permalink
Fix llvm register allocator for native/cross build differences
Browse files Browse the repository at this point in the history
Work around an issue in LLVM's register allocator, which can cause
slightly different i386 object files, when produced by a native or cross
build of clang.

This adds another volatile qualifier to a float variable declaration in
the weightCalcHelper() function, which otherwise produces slightly
different float results on amd64 and i386 hosts. In turn, this can lead
to different (but equivalent) register choices, and thus non-identical
assembly code.

See llvm/llvm-project#99396 for more details.

Note this is a temporary fix, meant to merge in time for 13.4. As soon
as upstream has a permanent solution we will import that.

PR:		276961
Reported by:	cperciva
MFC after:	3 days

(cherry picked from commit 397c269)
  • Loading branch information
DimitryAndric committed Jul 24, 2024
1 parent 8e9992f commit 8d87e47
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/llvm-project/llvm/lib/CodeGen/CalcSpillWeights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
return -1.0f;
}

float Weight = 1.0f;
// FreeBSD customization: similar to the HWeight declaration below, add a
// volatile qualifier to avoid slightly different weight results on amd64
// and i386 hosts, and possibly choosing different registers in the register
// allocator. See <https://github.com/llvm/llvm-project/issues/99396> for
// more details.
volatile float Weight = 1.0f;
if (IsSpillable) {
// Get loop info for mi.
if (MI->getParent() != MBB) {
Expand Down

0 comments on commit 8d87e47

Please sign in to comment.