All, As the SetCondInst instruction has been replaced with the new FCmpInst and ICmpInst instrucitons in LLVM, the attached patch compensates for this in llvm-gcc. Since the Apple developers are unlikely to commit this for over a week, if you're working over the holidays you'll need to apply this manually to your llvm-gcc tree.
Thanks, Reid.
Index: gcc/llvm-convert.cpp =================================================================== --- gcc/llvm-convert.cpp (revision 235) +++ gcc/llvm-convert.cpp (working copy) @@ -544,23 +544,37 @@ case TRUTH_NOT_EXPR: Result = EmitTRUTH_NOT_EXPR(exp); break; // Binary Operators - case LT_EXPR: Result = EmitCompare(exp, Instruction::SetLT, 0); break; - case LE_EXPR: Result = EmitCompare(exp, Instruction::SetLE, 0); break; - case GT_EXPR: Result = EmitCompare(exp, Instruction::SetGT, 0); break; - case GE_EXPR: Result = EmitCompare(exp, Instruction::SetGE, 0); break; - case EQ_EXPR: Result = EmitCompare(exp, Instruction::SetEQ, 0); break; - case NE_EXPR: Result = EmitCompare(exp, Instruction::SetNE, 0); break; - case UNORDERED_EXPR: Result = EmitCompare(exp, 0, 1); break; // not a typo - case ORDERED_EXPR: Result = EmitCompare(exp, 0, 1); break; // not a typo - case UNLT_EXPR: Result = EmitCompare(exp, Instruction::SetLT, 1); break; - case UNLE_EXPR: Result = EmitCompare(exp, Instruction::SetLE, 1); break; - case UNGT_EXPR: Result = EmitCompare(exp, Instruction::SetGT, 1); break; - case UNGE_EXPR: Result = EmitCompare(exp, Instruction::SetGE, 1); break; - case UNEQ_EXPR: Result = EmitCompare(exp, Instruction::SetEQ, 1); break; - case LTGT_EXPR: Result = EmitCompare(exp, Instruction::SetNE, 1); break; - case PLUS_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Add);break; - case MINUS_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Sub);break; - case MULT_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Mul);break; + case LT_EXPR: + Result = EmitCompare(exp, ICmpInst::ICMP_ULT, ICmpInst::ICMP_SLT, + FCmpInst::FCMP_OLT); break; + case LE_EXPR: + Result = EmitCompare(exp, ICmpInst::ICMP_ULE, ICmpInst::ICMP_SLE, + FCmpInst::FCMP_OLE); break; + case GT_EXPR: + Result = EmitCompare(exp, ICmpInst::ICMP_UGT, ICmpInst::ICMP_SGT, + FCmpInst::FCMP_OGT); break; + case GE_EXPR: + Result = EmitCompare(exp, ICmpInst::ICMP_UGE, ICmpInst::ICMP_SGE, + FCmpInst::FCMP_OGE); break; + case EQ_EXPR: + Result = EmitCompare(exp, ICmpInst::ICMP_EQ, ICmpInst::ICMP_EQ, + FCmpInst::FCMP_OEQ); break; + case NE_EXPR: + Result = EmitCompare(exp, ICmpInst::ICMP_NE, ICmpInst::ICMP_NE, + FCmpInst::FCMP_ONE); break; + case UNORDERED_EXPR: + Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_UNO); break; + case ORDERED_EXPR: + Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_ORD); break; + case UNLT_EXPR: Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_ULT); break; + case UNLE_EXPR: Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_ULE); break; + case UNGT_EXPR: Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_UGT); break; + case UNGE_EXPR: Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_UGE); break; + case UNEQ_EXPR: Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_UEQ); break; + case LTGT_EXPR: Result = EmitCompare(exp, 0, 0, FCmpInst::FCMP_UNE); break; + case PLUS_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Add);break; + case MINUS_EXPR:Result = EmitBinOp(exp, DestLoc, Instruction::Sub);break; + case MULT_EXPR: Result = EmitBinOp(exp, DestLoc, Instruction::Mul);break; case TRUNC_DIV_EXPR: if (TYPE_UNSIGNED(TREE_TYPE(exp))) Result = EmitBinOp(exp, DestLoc, Instruction::UDiv); @@ -596,8 +610,14 @@ case LROTATE_EXPR: Result = EmitRotateOp(exp, Instruction::Shl, Instruction::LShr); break; - case MIN_EXPR: Result = EmitMinMaxExpr(exp, Instruction::SetLE); break; - case MAX_EXPR: Result = EmitMinMaxExpr(exp, Instruction::SetGE); break; + case MIN_EXPR: + Result = EmitMinMaxExpr(exp, ICmpInst::ICMP_ULE, ICmpInst::ICMP_SLE, + FCmpInst::FCMP_OLE); + break; + case MAX_EXPR: + Result = EmitMinMaxExpr(exp, ICmpInst::ICMP_UGE, ICmpInst::ICMP_SGE, + FCmpInst::FCMP_OGE); + break; case CONSTRUCTOR: Result = EmitCONSTRUCTOR(exp, DestLoc); break; // Complex Math Expressions. @@ -1353,8 +1373,8 @@ Value *Cond = Emit(COND_EXPR_COND(exp), 0); // If its not already a bool, insert a comparison against zero to make it so. if (Cond->getType() != Type::BoolTy) - Cond = new SetCondInst(Instruction::SetNE, Cond, - Constant::getNullValue(Cond->getType()), "toBool", + Cond = new ICmpInst(ICmpInst::ICMP_NE, Cond, + Constant::getNullValue(Cond->getType()), "toBool", CurBB); tree Then = COND_EXPR_THEN(exp); tree Else = COND_EXPR_ELSE(exp); @@ -2323,8 +2343,9 @@ Value *Op = Emit(TREE_OPERAND(exp, 0), 0); if (!Op->getType()->isFloatingPoint()) { Instruction *OpN = BinaryOperator::createNeg(Op, Op->getName()+"neg",CurBB); - Value *Cmp = new SetCondInst(Instruction::SetGE, Op, OpN->getOperand(0), - "abscond", CurBB); + ICmpInst::Predicate pred = TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp,0))) ? + ICmpInst::ICMP_UGE : ICmpInst::ICMP_SGE; + Value *Cmp = new ICmpInst(pred, Op, OpN->getOperand(0), "abscond", CurBB); return new SelectInst(Cmp, Op, OpN, "abs", CurBB); } else { // Turn FP abs into fabs/fabsf. @@ -2341,8 +2362,8 @@ Value *TreeToLLVM::EmitTRUTH_NOT_EXPR(tree exp) { Value *V = Emit(TREE_OPERAND(exp, 0), 0); if (V->getType() != Type::BoolTy) - V = new SetCondInst(Instruction::SetNE, V, - Constant::getNullValue(V->getType()), "toBool", CurBB); + V = new ICmpInst(ICmpInst::ICMP_NE, V, + Constant::getNullValue(V->getType()), "toBool", CurBB); V = BinaryOperator::createNot(V, V->getName()+"not", CurBB); return CastToUIntType(V, ConvertType(TREE_TYPE(exp))); } @@ -2351,25 +2372,43 @@ /// comparison to use. isUnord is true if this is a floating point comparison /// that should also be true if either operand is a NaN. Note that Opc can be /// set to zero for special cases. -Value *TreeToLLVM::EmitCompare(tree exp, unsigned Opc, bool isUnord) { - if (TREE_CODE(TREE_TYPE(TREE_OPERAND(exp, 0))) == COMPLEX_TYPE) +Value *TreeToLLVM::EmitCompare(tree exp, unsigned UIOpc, unsigned SIOpc, + unsigned FPPred) { + // Get the type of the operands + tree Op0Ty = TREE_TYPE(TREE_OPERAND(exp,0)); + + // Deal with complex types + if (TREE_CODE(Op0Ty) == COMPLEX_TYPE) return EmitComplexBinOp(exp, 0); // Complex ==/!= - - // Comparison of struct is not allowed, so this is safe. + + // Get the compare operands, in the right type. Comparison of struct is not + // allowed, so this is safe as we already handled complex (struct) type. Value *LHS = Emit(TREE_OPERAND(exp, 0), 0); Value *RHS = Emit(TREE_OPERAND(exp, 1), 0); bool LHSIsSigned = !TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp, 0))); bool RHSIsSigned = !TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp, 1))); RHS = CastToAnyType(RHS, RHSIsSigned, LHS->getType(), LHSIsSigned); - assert(LHS->getType() == RHS->getType() && "Binop type equality failure!"); - + + // Handle the integer/pointer cases + if (!FLOAT_TYPE_P(Op0Ty)) { + // Determine which predicate to use based on signedness + ICmpInst::Predicate pred = + ICmpInst::Predicate(TYPE_UNSIGNED(Op0Ty) ? UIOpc : SIOpc); + + // Get the compare instructions + Value *Result = new ICmpInst(pred, LHS, RHS, "tmp", CurBB); + + // The GCC type is probably an int, not a bool. + return CastToUIntType(Result, ConvertType(TREE_TYPE(exp))); + } + + // Handle floating point comparisons, if we get here. Value *Result = 0; - if (Opc) - Result = new SetCondInst((Instruction::BinaryOps)Opc, LHS, RHS, "tmp", - CurBB); + if (FPPred) + Result = new FCmpInst(FCmpInst::Predicate(FPPred), LHS, RHS, "tmp", CurBB); - if (isUnord) { + if (CmpInst::isUnordered(FCmpInst::Predicate(FPPred))) { static Function *IsUnordF = 0, *IsUnordD = 0; Function *&Callee = LHS->getType() == Type::FloatTy ? IsUnordF : IsUnordD; const char *Name = LHS->getType() == Type::FloatTy ? @@ -2480,12 +2519,10 @@ // This is a truth operation like the strict &&,||,^^. Convert to bool as // a test against zero - LHS = new SetCondInst(Instruction::SetNE, LHS, - Constant::getNullValue(LHS->getType()), - "toBool", CurBB); - RHS = new SetCondInst(Instruction::SetNE, RHS, - Constant::getNullValue(RHS->getType()), - "toBool", CurBB); + LHS = new ICmpInst(ICmpInst::ICMP_NE, LHS, + Constant::getNullValue(LHS->getType()), "toBool", CurBB); + RHS = new ICmpInst(ICmpInst::ICMP_NE, RHS, + Constant::getNullValue(RHS->getType()), "toBool", CurBB); Value *Res = BinaryOperator::create((Instruction::BinaryOps)Opc, LHS, RHS, "tmp", CurBB); @@ -2523,7 +2560,8 @@ return CastToUIntType(Merge, ConvertType(TREE_TYPE(exp))); } -Value *TreeToLLVM::EmitMinMaxExpr(tree exp, unsigned CmpOpc) { +Value *TreeToLLVM::EmitMinMaxExpr(tree exp, unsigned UIPred, unsigned SIPred, + unsigned FPPred) { Value *LHS = Emit(TREE_OPERAND(exp, 0), 0); Value *RHS = Emit(TREE_OPERAND(exp, 1), 0); @@ -2541,9 +2579,15 @@ opcode = CastInst::getCastOpcode(LHS, LHSIsSigned, Ty, TyIsSigned); RHS = CastToType(opcode, RHS, Ty); - Value *Pred = new SetCondInst((Instruction::BinaryOps)CmpOpc, LHS, RHS, - "tmp", CurBB); - return new SelectInst(Pred, LHS, RHS, + Value *Compare; + if (LHS->getType()->isFloatingPoint()) + Compare = new FCmpInst(FCmpInst::Predicate(FPPred), LHS, RHS, "tmp", CurBB); + else if TYPE_UNSIGNED(TREE_TYPE(TREE_OPERAND(exp, 0))) + Compare = new ICmpInst(ICmpInst::Predicate(UIPred), LHS, RHS, "tmp", CurBB); + else + Compare = new ICmpInst(ICmpInst::Predicate(SIPred), LHS, RHS, "tmp", CurBB); + + return new SelectInst(Compare, LHS, RHS, TREE_CODE(exp) == MAX_EXPR ? "max" : "min", CurBB); } @@ -3226,9 +3270,14 @@ Result = BinaryOperator::createAdd(Result, ConstantInt::get(Type::IntTy, 1), "tmp", CurBB); - Value *Cond = BinaryOperator::createSetEQ(Amt, - Constant::getNullValue(Amt->getType()), - "tmp", CurBB); + Value *Cond; + if (Amt->getType()->isFloatingPoint()) + Cond = new FCmpInst(FCmpInst::FCMP_OEQ, Amt, + Constant::getNullValue(Amt->getType()), "tmp", CurBB); + else + Cond = new ICmpInst(ICmpInst::ICMP_EQ, Amt, + Constant::getNullValue(Amt->getType()), "tmp", CurBB); + Result = new SelectInst(Cond, Constant::getNullValue(Type::IntTy), Result, "tmp", CurBB); return true; @@ -3777,12 +3826,12 @@ break; } case EQ_EXPR: // (a+ib) == (c+id) = (a == c) & (b == d) - DSTr = BinaryOperator::createSetEQ(LHSr, RHSr, "tmpr", CurBB); - DSTi = BinaryOperator::createSetEQ(LHSi, RHSi, "tmpi", CurBB); + DSTr = new FCmpInst(FCmpInst::FCMP_OEQ, LHSr, RHSr, "tmpr", CurBB); + DSTi = new FCmpInst(FCmpInst::FCMP_OEQ, LHSi, RHSi, "tmpi", CurBB); return BinaryOperator::createAnd(DSTr, DSTi, "tmp", CurBB); case NE_EXPR: // (a+ib) != (c+id) = (a != c) | (b != d) - DSTr = BinaryOperator::createSetNE(LHSr, RHSr, "tmpr", CurBB); - DSTi = BinaryOperator::createSetNE(LHSi, RHSi, "tmpi", CurBB); + DSTr = new FCmpInst(FCmpInst::FCMP_ONE, LHSr, RHSr, "tmpr", CurBB); + DSTi = new FCmpInst(FCmpInst::FCMP_ONE, LHSi, RHSi, "tmpi", CurBB); return BinaryOperator::createOr(DSTr, DSTi, "tmp", CurBB); } Index: gcc/llvm-internal.h =================================================================== --- gcc/llvm-internal.h (revision 235) +++ gcc/llvm-internal.h (working copy) @@ -398,13 +398,15 @@ Value *EmitABS_EXPR(tree_node *exp); Value *EmitBIT_NOT_EXPR(tree_node *exp); Value *EmitTRUTH_NOT_EXPR(tree_node *exp); - Value *EmitCompare(tree_node *exp, unsigned Opc, bool isUnordered); + Value *EmitCompare(tree_node *exp, unsigned UIPred, unsigned SIPred, + unsigned FPOpc); Value *EmitBinOp(tree_node *exp, Value *DestLoc, unsigned Opc); Value *EmitPtrBinOp(tree_node *exp, unsigned Opc); Value *EmitTruthOp(tree_node *exp, unsigned Opc); Value *EmitShiftOp(tree_node *exp, Value *DestLoc, unsigned Opc); Value *EmitRotateOp(tree_node *exp, unsigned Opc1, unsigned Opc2); - Value *EmitMinMaxExpr(tree_node *exp, unsigned Opc); + Value *EmitMinMaxExpr(tree_node *exp, unsigned UIPred, unsigned SIPred, + unsigned Opc); // Inline Assembly and Register Variables. Value *EmitASM_EXPR(tree_node *exp);
_______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits