Fix a crasher bug in my constant folding rewrite
authorChris Lattner <sabre@nondot.org>
Sun, 1 Feb 2004 01:23:19 +0000 (01:23 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 1 Feb 2004 01:23:19 +0000 (01:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11044 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 094ec373f1050b54ceda19e4fd948c5527557edf..28d671b898c9715f7711fc7068478778da3caebe 100644 (file)
@@ -625,11 +625,18 @@ static Instruction::BinaryOps evaluateRelation(const Constant *V1,
     // If the first operand is simple, swap operands.
     assert((isa<ConstantPointerRef>(V2) || isa<ConstantExpr>(V2)) &&
            "Simple cases should have been handled by caller!");
-    return SetCondInst::getSwappedCondition(evaluateRelation(V2, V1));
+    Instruction::BinaryOps SwappedRelation = evaluateRelation(V2, V1);
+    if (SwappedRelation != Instruction::BinaryOpsEnd)
+      return SetCondInst::getSwappedCondition(SwappedRelation);
 
   } else if (const ConstantPointerRef *CPR1 = dyn_cast<ConstantPointerRef>(V1)){
-    if (isa<ConstantExpr>(V2))   // Swap as necessary.
-      return SetCondInst::getSwappedCondition(evaluateRelation(V2, V1));
+    if (isa<ConstantExpr>(V2)) {  // Swap as necessary.
+    Instruction::BinaryOps SwappedRelation = evaluateRelation(V2, V1);
+    if (SwappedRelation != Instruction::BinaryOpsEnd)
+      return SetCondInst::getSwappedCondition(SwappedRelation);
+    else
+      return Instruction::BinaryOpsEnd;
+    }
 
     // Now we know that the RHS is a ConstantPointerRef or simple constant,
     // which (since the types must match) means that it's a ConstantPointerNull.