[llvm] [InstCombine] Fold `select Cond, not X, X` into `Cond ^ X` (PR #93591)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 4 03:36:10 PDT 2024


================
@@ -3502,6 +3502,34 @@ static bool matchFMulByZeroIfResultEqZero(InstCombinerImpl &IC, Value *Cmp0,
   return false;
 }
 
+/// Return true iff:
+/// 1. X is poison implies Y is poison.
+/// 2. X is true implies Y is false.
+/// 3. X is false implies Y is true.
+/// Otherwise, return false.
+static bool isKnownInversion(Value *X, Value *Y) {
+  // Handle X = icmp pred V, C1, Y = icmp pred V, C2.
+  Value *V;
+  Constant *C1, *C2;
+  ICmpInst::Predicate Pred1, Pred2;
+  if (!match(X, m_ICmp(Pred1, m_Value(V), m_Constant(C1))) ||
+      !match(Y, m_ICmp(Pred2, m_Specific(V), m_Constant(C2))))
----------------
nikic wrote:

I think what @goldsteinn means is that you can replace the m_Constant with m_Value.

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


More information about the llvm-commits mailing list