Index: lib/CodeGen/MIRParser/MILexer.h =================================================================== --- lib/CodeGen/MIRParser/MILexer.h +++ lib/CodeGen/MIRParser/MILexer.h @@ -113,6 +113,8 @@ kw_successors, kw_floatpred, kw_intpred, + kw_true, + kw_false, // Named metadata keywords md_tbaa, Index: lib/CodeGen/MIRParser/MILexer.cpp =================================================================== --- lib/CodeGen/MIRParser/MILexer.cpp +++ lib/CodeGen/MIRParser/MILexer.cpp @@ -245,6 +245,8 @@ .Case("successors", MIToken::kw_successors) .Case("floatpred", MIToken::kw_floatpred) .Case("intpred", MIToken::kw_intpred) + .Case("true", MIToken::kw_true) + .Case("false", MIToken::kw_false) .Default(MIToken::Identifier); } Index: lib/CodeGen/MIRParser/MIParser.cpp =================================================================== --- lib/CodeGen/MIRParser/MIParser.cpp +++ lib/CodeGen/MIRParser/MIParser.cpp @@ -1373,11 +1373,26 @@ auto Loc = Token.location(); lex(); - if (Token.isNot(MIToken::IntegerLiteral)) - return error("expected an integer literal"); const Constant *C = nullptr; - if (parseIRConstant(Loc, C)) - return true; + + const Module *M = MF.getFunction().getParent(); + switch (Token.kind()) { + case MIToken::kw_true: + C = ConstantInt::getTrue(M->getContext()); + lex(); + break; + case MIToken::kw_false: + C = ConstantInt::getFalse(M->getContext()); + lex(); + break; + case MIToken::IntegerLiteral: + if (parseIRConstant(Loc, C)) + return true; + break; + default: + return error("expected an integer literal"); + } + Dest = MachineOperand::CreateCImm(cast(C)); return false; } @@ -1884,29 +1899,40 @@ if (expectAndConsume(MIToken::lparen)) return error("expected syntax intpred(whatever) or floatpred(whatever"); - if (Token.isNot(MIToken::Identifier)) - return error("whatever"); - CmpInst::Predicate Pred; + if (Token.is(MIToken::kw_true)) { + if (IsFloat) + Pred = CmpInst::FCMP_TRUE; + else + return error("invalid integer predicate"); + } else if (Token.is(MIToken::kw_false)) { + if (IsFloat) + Pred = CmpInst::FCMP_FALSE; + else + return error("invalid integer predicate"); + } else if (Token.isNot(MIToken::Identifier)) { + return error("expected a predicate"); + } + if (IsFloat) { - Pred = StringSwitch(Token.stringValue()) - .Case("false", CmpInst::FCMP_FALSE) - .Case("oeq", CmpInst::FCMP_OEQ) - .Case("ogt", CmpInst::FCMP_OGT) - .Case("oge", CmpInst::FCMP_OGE) - .Case("olt", CmpInst::FCMP_OLT) - .Case("ole", CmpInst::FCMP_OLE) - .Case("one", CmpInst::FCMP_ONE) - .Case("ord", CmpInst::FCMP_ORD) - .Case("uno", CmpInst::FCMP_UNO) - .Case("ueq", CmpInst::FCMP_UEQ) - .Case("ugt", CmpInst::FCMP_UGT) - .Case("uge", CmpInst::FCMP_UGE) - .Case("ult", CmpInst::FCMP_ULT) - .Case("ule", CmpInst::FCMP_ULE) - .Case("une", CmpInst::FCMP_UNE) - .Case("true", CmpInst::FCMP_TRUE) - .Default(CmpInst::BAD_FCMP_PREDICATE); + if (Pred != CmpInst::FCMP_TRUE && Pred != CmpInst::FCMP_FALSE) { + Pred = StringSwitch(Token.stringValue()) + .Case("oeq", CmpInst::FCMP_OEQ) + .Case("ogt", CmpInst::FCMP_OGT) + .Case("oge", CmpInst::FCMP_OGE) + .Case("olt", CmpInst::FCMP_OLT) + .Case("ole", CmpInst::FCMP_OLE) + .Case("one", CmpInst::FCMP_ONE) + .Case("ord", CmpInst::FCMP_ORD) + .Case("uno", CmpInst::FCMP_UNO) + .Case("ueq", CmpInst::FCMP_UEQ) + .Case("ugt", CmpInst::FCMP_UGT) + .Case("uge", CmpInst::FCMP_UGE) + .Case("ult", CmpInst::FCMP_ULT) + .Case("ule", CmpInst::FCMP_ULE) + .Case("une", CmpInst::FCMP_UNE) + .Default(CmpInst::BAD_FCMP_PREDICATE); + } if (!CmpInst::isFPPredicate(Pred)) return error("invalid floating-point predicate"); } else { Index: test/CodeGen/MIR/AArch64/parse-integer-true-false.mir =================================================================== --- /dev/null +++ test/CodeGen/MIR/AArch64/parse-integer-true-false.mir @@ -0,0 +1,11 @@ +# RUN: llc -mtriple=aarch64-- -run-pass none -o - %s | FileCheck %s +# Parse an i1 being a 'true' or 'false' +--- +name: i1_true_false +body: | + bb.0: + ; CHECK: %0:_(s1) = G_CONSTANT i1 true + ; CHECK: %1:_(s1) = G_CONSTANT i1 false + %0:_(s1) = G_CONSTANT i1 true + %1:_(s1) = G_CONSTANT i1 false +...