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

Jun Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 11 22:12:06 PDT 2023


junaire marked 2 inline comments as done.
junaire added a comment.

In D150378#4335986 <https://reviews.llvm.org/D150378#4335986>, @nikic wrote:

> The handling for this should be inside simplifyWithOpReplaced().

I updated the patch. The transform I wrote is based on my understanding of the code and I'm not super confident that's what you meant. Educate me please if it's wrong, thanks!



================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:4578
+
+    // select((X == Y) ? 0 : X - Y) --> X - Y
+    if (match(TrueVal, m_Zero()) &&
----------------
goldstein.w.n wrote:
> 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.
NE will always be canonicalized to EQ in Line 4476, so we don't have to do that.


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