Avoid excess precision issues that lead to generating host-compiler-specific code.
authorChris Lattner <sabre@nondot.org>
Sat, 9 Apr 2011 06:57:13 +0000 (06:57 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 9 Apr 2011 06:57:13 +0000 (06:57 +0000)
Switch lowering probably shouldn't be using FP for this.  This resolves PR9581.

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

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

index f751bb708e7ad59876b32036df42078126bc4640..8fb881b2700f3a5e054773a3c2ad7e94be924b06 100644 (file)
@@ -2019,9 +2019,13 @@ bool SelectionDAGBuilder::handleBTSplitSwitchCase(CaseRec& CR,
     APInt Range = ComputeRange(LEnd, RBegin);
     assert((Range - 2ULL).isNonNegative() &&
            "Invalid case distance");
-    double LDensity = (double)LSize.roundToDouble() /
+    // Use volatile double here to avoid excess precision issues on some hosts,
+    // e.g. that use 80-bit X87 registers.
+    volatile double LDensity =
+       (double)LSize.roundToDouble() /
                            (LEnd - First + 1ULL).roundToDouble();
-    double RDensity = (double)RSize.roundToDouble() /
+    volatile double RDensity =
+      (double)RSize.roundToDouble() /
                            (Last - RBegin + 1ULL).roundToDouble();
     double Metric = Range.logBase2()*(LDensity+RDensity);
     // Should always split in some non-trivial place