Refix CodeGen/Generic/switch-lower.ll. In contrast to my previous patch,
authorChris Lattner <sabre@nondot.org>
Wed, 14 Feb 2007 07:18:16 +0000 (07:18 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 14 Feb 2007 07:18:16 +0000 (07:18 +0000)
this doesn't miscompile lots of programs :)

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

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index e72d88c73401c5780712f0120374dfc5a118cb70..0192c287cd163e91f4128d643b2564f3e9f7a3a7 100644 (file)
@@ -1205,8 +1205,8 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
   if ((TLI.isOperationLegal(ISD::BR_JT, MVT::Other) ||
        TLI.isOperationLegal(ISD::BRIND, MVT::Other)) &&
       Cases.size() > 5) {
-    uint64_t First =cast<ConstantInt>(Cases.front().first)->getZExtValue();
-    uint64_t Last  = cast<ConstantInt>(Cases.back().first)->getZExtValue();
+    uint64_t First =cast<ConstantInt>(Cases.front().first)->getSExtValue();
+    uint64_t Last  = cast<ConstantInt>(Cases.back().first)->getSExtValue();
     double Density = (double)Cases.size() / (double)((Last - First) + 1ULL);
     
     if (Density >= 0.3125) {
@@ -1255,7 +1255,7 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
       std::vector<MachineBasicBlock*> DestBBs;
       uint64_t TEI = First;
       for (CaseItr ii = Cases.begin(), ee = Cases.end(); ii != ee; ++TEI)
-        if (cast<ConstantInt>(ii->first)->getZExtValue() == TEI) {
+        if (cast<ConstantInt>(ii->first)->getSExtValue() == TEI) {
           DestBBs.push_back(ii->second);
           ++ii;
         } else {
@@ -1363,8 +1363,8 @@ void SelectionDAGLowering::visitSwitch(SwitchInst &I) {
       // Create a CaseBlock record representing a conditional branch to
       // the LHS node if the value being switched on SV is less than C. 
       // Otherwise, branch to LHS.
-      ISD::CondCode CC =  ISD::SETLT;
-      SelectionDAGISel::CaseBlock CB(CC, SV, C, TrueBB, FalseBB, CR.CaseBB);
+      SelectionDAGISel::CaseBlock CB(ISD::SETLT, SV, C, TrueBB, FalseBB,
+                                     CR.CaseBB);
 
       if (CR.CaseBB == CurMBB)
         visitSwitchCase(CB);