[PATCH] D15718: Recognize pattern for ctpop in instcombine

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 19:59:46 PST 2016

hfinkel added a subscriber: hfinkel.

Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:1060
@@ +1059,3 @@
+// where xn is the candidate for ctpop(V).
+static Value *matchCtpopW(BinaryOperator *BI, unsigned BW) {
+  auto matchStep = [] (Value *V, unsigned S, APInt M, bool ShiftAlone)
I think it would be better if the comment above matchCtpopW explained what matchCtpopW does, and a comment above optimizeToCtpop explained what optimizeToCtpop does. The:

  // ... If BW is less than the bit-width of the type of V, then
  // BI == ctpop(V) if the bits of V beyond BW are zero.

is a bit confusing here because it is describing behavior implemented in a different function.

Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:1158
@@ +1157,3 @@
+  unsigned TW = Ty->getBitWidth(), BW = 2*SH;
+  if (BW < TW) {
+    // BW is the bit width of the expression whose population count is
Instead of checking for known zero bits, why not transform this into a ctpop(v & mask)? If the upper bits are known to be zero, then the mask will go away in the next instcombine iteration regardless.



More information about the llvm-commits mailing list