[llvm] [ValueTracking] Analyze `Select` in `isKnownNonEqual`. (PR #68427)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 8 10:01:54 PDT 2023


================
@@ -3112,6 +3112,39 @@ static bool isNonEqualPHIs(const PHINode *PN1, const PHINode *PN2,
   return true;
 }
 
+static bool isNonEqualSelect(const Value *V1, const Value *V2, unsigned Depth,
+                             const SimplifyQuery &Q) {
+  const SelectInst *SI1 = dyn_cast<SelectInst>(V1);
+  if (!SI1)
+    return false;
+
+  if (const SelectInst *SI2 = dyn_cast<SelectInst>(V2)) {
+    const Value *TVal1 = nullptr;
+    const Value *TVal2 = nullptr;
+    const Value *FVal1 = nullptr;
+    const Value *FVal2 = nullptr;
+    const Value *Cond1 = SI1->getCondition();
+    const Value *Cond2 = SI2->getCondition();
+    if (Cond1 == Cond2) {
+      TVal1 = SI1->getTrueValue();
+      TVal2 = SI2->getTrueValue();
+      FVal1 = SI1->getFalseValue();
+      FVal2 = SI2->getFalseValue();
+    }
+    if (match(Cond1, m_Not(m_Specific(Cond2)))) {
----------------
goldsteinn wrote:

I don't this is the way to do it (likewise Cond1 == Cond2).
I think something like:

```
Pred1 = Cond1->Pred;
Pred2 = Cond2->Pred;
X1 = Cond1->Op0;
Y1 = Cond1->Op1;
X2 = Cond2->Op0;
Y2 = Cond2->Op1;
if(X1 == Y2) {
   Pred2 = getSwappedPred(Pred2);
   swap(X2, Y2);
}
if(X1 == X2 && Y1 == Y2) {
   if(Pred1 == Pred2) {
       // Cond1 == Cond2 case
   }
   if(Pred1 == getInverse(Pred2) {
      // Cond1 == ~Cond2 case.
    } 
}
```

Otherwise you are fighting canonicalizations of `not(icmp)`. 

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


More information about the llvm-commits mailing list