[llvm] [SDAG] Use shifts if ISD::MUL is illegal when lowering ISD::CTPOP (PR #86505)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 01:45:24 PDT 2024


================
@@ -6354,12 +6354,21 @@ LegalizerHelper::lowerBitCount(MachineInstr &MI) {
     // 8 bits can hold CTPOP result of 128 bit int or smaller. Mul with this
     // bitmask will set 8 msb in ResTmp to sum of all B8Counts in 8 bit blocks.
     auto MulMask = B.buildConstant(Ty, APInt::getSplat(Size, APInt(8, 0x01)));
-    auto ResTmp = B.buildMul(Ty, B8Count, MulMask);
 
     // Shift count result from 8 high bits to low bits.
     auto C_SizeM8 = B.buildConstant(Ty, Size - 8);
-    B.buildLShr(MI.getOperand(0).getReg(), ResTmp, C_SizeM8);
-
+    if (isSupported({TargetOpcode::G_MUL, {Ty, Ty}})) {
----------------
arsenm wrote:

Ideally we would have separate implementations in separate helper functions, but that's already broken as-is. I think this is fine but I think lowerBitCount could use future refactors to break it up. There's no real reason all the unrelated count functions are handled in this same place 

https://github.com/llvm/llvm-project/pull/86505


More information about the llvm-commits mailing list