enhance the previous optimization to work with fcmp in addition
to icmp.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92412 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 1fcc64e..05da044 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -6180,7 +6180,7 @@
         if (Instruction *NV = FoldFCmp_IntToFP_Cst(I, LHSI, RHSC))
           return NV;
         break;
-      case Instruction::Select:
+      case Instruction::Select: {
         // If either operand of the select is a constant, we can fold the
         // comparison into the select arms, which will cause one to be
         // constant folded and the select turned into a bitwise or.
@@ -6205,6 +6205,20 @@
           return SelectInst::Create(LHSI->getOperand(0), Op1, Op2);
         break;
       }
+    case Instruction::Load:
+      if (GetElementPtrInst *GEP =
+          dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) {
+        if (GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0)))
+          if (GV->isConstant() && GV->hasDefinitiveInitializer() &&
+              !cast<LoadInst>(LHSI)->isVolatile())
+            if (Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV, I))
+              return Res;
+            //errs() << "NOT HANDLED: " << *GV << "\n";
+            //errs() << "\t" << *GEP << "\n";
+            //errs() << "\t " << I << "\n\n\n";
+      }
+      break;
+    }
   }
 
   return Changed ? &I : 0;
@@ -6586,13 +6600,16 @@
 
       case Instruction::Load:
         if (GetElementPtrInst *GEP =
-              dyn_cast<GetElementPtrInst>(LHSI->getOperand(0)))
+              dyn_cast<GetElementPtrInst>(LHSI->getOperand(0))) {
           if (GlobalVariable *GV = dyn_cast<GlobalVariable>(GEP->getOperand(0)))
             if (GV->isConstant() && GV->hasDefinitiveInitializer() &&
-                !cast<LoadInst>(LHSI)->isVolatile()) {
+                !cast<LoadInst>(LHSI)->isVolatile())
               if (Instruction *Res = FoldCmpLoadFromIndexedGlobal(GEP, GV, I))
                 return Res;
-            }
+          //errs() << "NOT HANDLED: " << *GV << "\n";
+          //errs() << "\t" << *GEP << "\n";
+          //errs() << "\t " << I << "\n\n\n";
+        }
         break;
       }
   }