[llvm] [InstCombine] Improve `(icmp pred (and X, Y), ...)` fold. (PR #66787)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 06:28:17 PST 2023


================
@@ -233,56 +233,116 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
                                                 PatternMatch::m_Value()));
   }
 
-  /// Return true if the specified value is free to invert (apply ~ to).
-  /// This happens in cases where the ~ can be eliminated.  If WillInvertAllUses
-  /// is true, work under the assumption that the caller intends to remove all
-  /// uses of V and only keep uses of ~V.
-  ///
-  /// See also: canFreelyInvertAllUsersOf()
-  static bool isFreeToInvert(Value *V, bool WillInvertAllUses,
-                             unsigned Depth = 0) {
+  /// Return nonnull value if V is free to invert (with condition) regarding
+  /// WillInvertAllUses.
+  /// If Builder is nonnull, it will return a simplified ~V
+  /// If builder is null, it will return an arbitrary nonnull value (not
+  /// dereferenceable).
+  static Value *getFreeInverted(Value *V, bool WillInvertAllUses,
+                                BuilderTy *Builder, unsigned Depth = 0) {
+    static Value *const kNonNull = reinterpret_cast<Value *>(uintptr_t(1));
----------------
nikic wrote:

`k` prefix is not typical LLVM style...

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


More information about the llvm-commits mailing list