[PATCH] D153963: [InstCombine] Fold binop of select and cast of select condition

Antonio Frighetto via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 13 09:20:03 PDT 2023


antoniofrighetto updated this revision to Diff 540068.
antoniofrighetto edited the summary of this revision.
antoniofrighetto added a comment.

@goldstein.w.n, added multiuse select and non-const sides tests (last three tests), proofs updated (https://alive2.llvm.org/ce/z/m_vGWd). Tests are on a dedicated commit.

It seems RHS ext & LHS sel operands are canonicalized as such in `SimplifyAssociativeOrCommutative` for `add`/`mul`. When the binop is a subtraction, being non-commutative, the semantic of the operation will change if the operands are swapped. I tried extending the helper to support swapped operands too (LHS ext & RHS sel), yet, the transformation appears to be correct only when the `select` has both const sides. With non-const sides, the transformation fails (proof: https://alive2.llvm.org/ce/z/BZU9cR). I don't believe we should introduce specialization in the helper for const-only subs.


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

https://reviews.llvm.org/D153963

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/binop-select-cast-of-select-cond.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153963.540068.patch
Type: text/x-patch
Size: 11218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230713/5315c7f4/attachment.bin>


More information about the llvm-commits mailing list