Index: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -7835,7 +7835,16 @@ DAG.getNode(ISD::CTLZ, dl, VT, Tmp)); } - return DAG.getNode(ISD::CTPOP, dl, VT, Tmp); + // Emit table lookup by reverting to original IR + // table[((unsigned)((x & -x) * 0x077CB531U)) >> 27] + SDValue Neg = DAG.getNode(ISD::SUB, dl, VT, DAG.getConstant(0, dl, VT), Op); + SDValue Lookup = DAG.getNode( + ISD::SRL, dl, VT, + DAG.getNode(ISD::MUL, dl, VT, DAG.getNode(ISD::AND, dl, VT, Op, Neg), + DAG.getConstant(0x077CB531U, dl, VT)), + DAG.getConstant(27, dl, VT)); + + return Lookup; } SDValue TargetLowering::expandABS(SDNode *N, SelectionDAG &DAG,