[PATCH] D14590: [SimplifyLibCalls] Constant folding for fls, flsl, flsll

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 15 12:44:22 PST 2016

davide added inline comments.

Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1558
+    return B.getInt32(CI->getType()->getBitWidth() -
+                      CI->getValue().countLeadingZeros());
+  }
efriedma wrote:
> Maybe we should just unconditionally lower fls() to llvm.ctlz()?
Hmm, yeah. I decided to do what `ffs` already does.
Try to constant fold, and if the argument is not a constant, lower to
`(x != 0) ? (i32)(sizeInBits(x) - llvm.ctlz()) : 0`
Is this what you had in mind, or you wanted to remove the constant folding part completely?


More information about the llvm-commits mailing list