CalcSpillWeights: Hack to prevent x87 nonsense
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 21 Apr 2014 17:57:01 +0000 (17:57 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 21 Apr 2014 17:57:01 +0000 (17:57 +0000)
This gross hack forces `hweight` into memory, preventing hidden
precision from making `1 > 1` occasionally equal `true`.

<rdar://problem/14292693>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206765 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CalcSpillWeights.cpp

index e4d5fa80ca3ae2a8ccb718b81c18c97817ff4e07..2654f42d2c6545f68dbee978dbc939744e9e8516 100644 (file)
@@ -149,7 +149,11 @@ VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &li) {
     unsigned hint = copyHint(mi, li.reg, tri, mri);
     if (!hint)
       continue;
-    float hweight = Hint[hint] += weight;
+    // Force hweight onto the stack so that x86 doesn't add hidden precision,
+    // making the comparison incorrectly pass (i.e., 1 > 1 == true??).
+    //
+    // FIXME: we probably shouldn't use floats at all.
+    volatile float hweight = Hint[hint] += weight;
     if (TargetRegisterInfo::isPhysicalRegister(hint)) {
       if (hweight > bestPhys && mri.isAllocatable(hint))
         bestPhys = hweight, hintPhys = hint;