summaryrefslogtreecommitdiff
path: root/devel/llvm18/files/patch-backport-freebsd-397c2693fa6
blob: f000829474ba6aba5579b977e0cbd6aab1f36f35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
commit 397c2693fa66508cb5e6b173650a1f3bc6c4dd4f
Author: Dimitry Andric <dim@FreeBSD.org>
Date:   Sun Jul 21 22:37:27 2024 +0200

    Fix llvm register allocator for native/cross build differences
    
    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 https://github.com/llvm/llvm-project/issues/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

diff --git llvm/lib/CodeGen/CalcSpillWeights.cpp llvm/lib/CodeGen/CalcSpillWeights.cpp
index f3cb7fa5af61..afde8d001f88 100644
--- llvm/lib/CodeGen/CalcSpillWeights.cpp
+++ llvm/lib/CodeGen/CalcSpillWeights.cpp
@@ -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) {