[PATCH] D145890: [InstCombine] Generate better code for std::bit_floor from libstdc++
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 26 15:35:08 PDT 2023
goldstein.w.n added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:3296
+//
+// X == 0 ? 0 : (1 << (32 - ctlz(X >> 1)))
+//
----------------
'32' -> 'BitWidth'.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp:3304
+// replacing one of the select operands.
+static Instruction *foldBitFloor(SelectInst &SI,
+ InstCombiner::BuilderTy &Builder) {
----------------
I would prefer this as a more generic function for replacing `1 << (BitWidth - ctlz(X >> 1))` -> `(SignBit >> ctlz(X)` which we can do anytime we know `X` is non-zero: https://alive2.llvm.org/ce/z/PDxghx
Then use the helper for the select case, but then it can also be used with an `IsKnownNonZero` query.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D145890/new/
https://reviews.llvm.org/D145890
More information about the llvm-commits
mailing list