[PATCH] D159464: [InstCombine] Fold comparison of adding two zero extended booleans

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 09:51:57 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:2946
+        Op1->getType()->isIntOrIntVectorTy(1)) {
+      Value *Cond = Builder.getFalse();
+      // Case 1: sext i1 Op0 + zext i1 Op1 == 0 --> !(xor i1 Op0, Op1)
----------------
You can hoist this for all checks.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:2956
+      return replaceInstUsesWith(Cmp, Cond);
+    }
+    return nullptr;
----------------
Think would be a bit cleaner to do the following:

```
if(ICmp.IsEquality() && match(X, m_ZExtOrSExt(Op0)) && match(Y, m_ZExtOrSExt(Op1)) && Op0->getType->isI1() && Op1 ->getType()->isI1()) {
 if(match(X, m_Zext()) && match(Y, m_Zext()) {
...
}
if(match(X, m_SExt()) && match(Y, m_SExt()) {
...
}
if(match(X, m_ZExt()) && match(Y, m_Sext()) {
   swap(X, Y);
}
if(match(X, m_Sext() && match(Y, m_Zext()) {
....
}
}
```



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159464/new/

https://reviews.llvm.org/D159464



More information about the llvm-commits mailing list