Skip to content

Commit

Permalink
Don't use floating point to do an integer's job.
Browse files Browse the repository at this point in the history
This code makes different decisions when compiled into x87 instructions
because of different rounding behavior.  That caused phase 2/3
miscompares on 32-bit Linux when the phase 1 compiler was built with gcc
(using x87), and the phase 2 compiler was built with clang (using SSE).

This fixes PR11200.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@143006 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
stoklund committed Oct 26, 2011
1 parent 73b5bb3 commit 7944391
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2034,14 +2034,17 @@ bool SelectionDAGBuilder::handleJTSwitchCase(CaseRec &CR,
return false;

APInt Range = ComputeRange(First, Last);
double Density = TSize.roundToDouble() / Range.roundToDouble();
if (Density < 0.4)
// The density is TSize / Range. Require at least 40%.
// It should not be possible for IntTSize to saturate for sane code, but make
// sure we handle Range saturation correctly.
uint64_t IntRange = Range.getLimitedValue(UINT64_MAX/10);
uint64_t IntTSize = TSize.getLimitedValue(UINT64_MAX/10);
if (IntTSize * 10 < IntRange * 4)
return false;

DEBUG(dbgs() << "Lowering jump table\n"
<< "First entry: " << First << ". Last entry: " << Last << '\n'
<< "Range: " << Range
<< ". Size: " << TSize << ". Density: " << Density << "\n\n");
<< "Range: " << Range << ". Size: " << TSize << ".\n\n");

// Get the MachineFunction which holds the current MBB. This is used when
// inserting any additional MBBs necessary to represent the switch.
Expand Down

0 comments on commit 7944391

Please sign in to comment.