[PATCH] D150378: [Instsimplfy] X == Y ? 0 : X - Y --> X - Y

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 09:55:36 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4578
+
+    // select((X == Y) ? 0 : X - Y) --> X - Y
+    if (match(TrueVal, m_Zero()) &&
----------------
While you're at it, can you also do `select (X != Y ? X - Y : 0)`? Something like:
```
if(CMPEQ || CMPNE) {
Value * MatchZero, *MatchSub;
if(CMPEQ) {
  MatchZero = TrueVal;
  MatchSub = FalseVal;
}
else {
  MatchZero = FalseVal;
  MatchSub = TrueVal;
}

// Your current code using MatchZero/MatchSub.
}
```

You will have to move out of the current branch.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4584
+        match(FalseVal, m_Sub(m_Specific(CmpRHS), m_Specific(CmpLHS))))
+      return FalseVal;
   }
----------------
can you put this all in nested `if (match(TrueVal, m_Zero)) { // check RHS-LHS and LHS-RHS }`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150378



More information about the llvm-commits mailing list