diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 8267a364261..cb21be7b762 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -119,6 +119,16 @@ Init *BitRecTy::convertValue(TypedInit *VI) { if (auto *BitsTy = dyn_cast(Ty)) // Accept only bits<1> expression. return BitsTy->getNumBits() == 1 ? VI : nullptr; + // Ternary !if can be converted to bit, but only if both sides are + // convertible to a bit. + if (TernOpInit *TOI = dyn_cast(VI)) { + if (TOI->getOpcode() != TernOpInit::TernaryOp::IF) + return nullptr; + if (!TOI->getMHS()->convertInitializerTo(BitRecTy::get()) || + !TOI->getRHS()->convertInitializerTo(BitRecTy::get())) + return nullptr; + return TOI; + } return nullptr; } diff --git a/test/TableGen/ifbit.td b/test/TableGen/ifbit.td index 88f575e9acf..18797cac110 100644 --- a/test/TableGen/ifbit.td +++ b/test/TableGen/ifbit.td @@ -5,6 +5,8 @@ class A { int a = !if(b, 5, 6); + bit c = !if(b, 0, 1); + bits<1> d = !if(b, 0, 1); } def X : A<0>;