[llvm] [InstCombine] Make `takeLog2` usable throughout InstCombine; NFC (PR #122498)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 10 12:10:01 PST 2025


================
@@ -195,6 +195,18 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
                                                 PatternMatch::m_Value()));
   }
 
+  // Take the exact integer log2 of the value. If DoFold is true, create the
+  // actual instructions, otherwise return a non-null dummy value. Return
+  // nullptr on failure. Note, if DoFold is true the caller must ensure that
+  // takeLog2 will succeed, otherwise it may create stray instructions.
+  Value *takeLog2(Value *Op, unsigned Depth, bool AssumeNonZero, bool DoFold);
+
+  Value *tryGetLog2(Value *Op, bool AssumeNonZero) {
+    if (takeLog2(Op, /*Depth=*/0, AssumeNonZero, /*DoFold=*/false))
+      return takeLog2(Op, /*Depth=*/0, AssumeNonZero, /*DoFold=*/true);
+    return nullptr;
+  }
----------------
nikic wrote:

Move these to InstCombineInternal.h instead.

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


More information about the llvm-commits mailing list