Fix constant folding relational operators with undef operands.
authorChris Lattner <sabre@nondot.org>
Sun, 17 Oct 2004 04:01:51 +0000 (04:01 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 17 Oct 2004 04:01:51 +0000 (04:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17077 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp

index 2e8ed54ec64e04ffa917d2c5d4afb36561cd053b..b56366ea6635e5148e315b54c722e645a1b8678d 100644 (file)
@@ -830,7 +830,9 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
   // If we successfully folded the expression, return it now.
   if (C) return C;
 
-  if (SetCondInst::isRelational(Opcode))
+  if (SetCondInst::isRelational(Opcode)) {
+    if (isa<UndefValue>(V1) || isa<UndefValue>(V2))
+      return UndefValue::get(Type::BoolTy);
     switch (evaluateRelation(V1, V2)) {
     default: assert(0 && "Unknown relational!");
     case Instruction::BinaryOpsEnd:
@@ -871,17 +873,12 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
       if (Opcode == Instruction::SetNE) return ConstantBool::True;
       break;
     }
+  }
 
   if (isa<UndefValue>(V1) || isa<UndefValue>(V2)) {
     switch (Opcode) {
     case Instruction::Add:
     case Instruction::Sub:
-    case Instruction::SetEQ:
-    case Instruction::SetNE:
-    case Instruction::SetLT:
-    case Instruction::SetLE:
-    case Instruction::SetGT:
-    case Instruction::SetGE:
     case Instruction::Xor:
       return UndefValue::get(V1->getType());