[llvm-commits] cttz optimisation

Chris Lattner clattner at apple.com
Mon Jan 4 21:18:59 PST 2010


On Jan 4, 2010, at 8:35 PM, Alastair Lynn wrote:

> Hello-
> 
> The attached patch catches cases where cttz's value is constant.

Nice transformation, some nitpicks:


+    APInt Mask(BitWidth, 0);
+    Mask.set(TrailingZeros);
+    Mask = Mask - 1;

Please use APInt::getLowBitsSet

+    if ((Mask & KnownZero) == Mask) {
+      return ReplaceInstUsesWith(CI, ConstantInt::get(IT,
+                                 APInt(BitWidth, TrailingZeros)));
+    }

No need for the braces.

Please add a comment explaining the intuition, something like "If all bits before the first known one are known to be zero, then we can evaluate this symbolically.

Please apply with these changes, thanks Alastair!  Want to do a similar patch for ctlz?

-Chris



More information about the llvm-commits mailing list