[PATCH] D101720: [InstCombine] generalize select + select/and/or folding using implied conditions

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 2 04:19:55 PDT 2021


aqjune created this revision.
aqjune added reviewers: nikic, spatel, lebedev.ri.
Herald added a subscriber: hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch optimizes the remaining possible cases in D101191 <https://reviews.llvm.org/D101191> by generalizing isImpliedCondition()-based
foldings.

Assume that there is `op a, (select b, _, _)` where op is one of `and i1`, `or i1` or their select forms.

We can do the following optimization based on the result of `isImpliedCondition(a, b)`:

If a = true implies…

- b = true:
  - select a, (select b, A, B), false => select a, A, false : https://alive2.llvm.org/ce/z/WCnZYh
  - and a, (select b, A, B) => select a, A, false : https://alive2.llvm.org/ce/z/uZhcMG
- b = false:
  - select a, (select b, A, B), false => select a, B, false : https://alive2.llvm.org/ce/z/c2hJpV
  - and a, (select b, A, B) => select a, B, false : https://alive2.llvm.org/ce/z/5ggwMM

If a = false implies…

- b = true:
  - select a, true, (select b, A, B) => select a, true, A : https://alive2.llvm.org/ce/z/tidKvH
  - or a, (select b, A, B) =>  select a, true, A : https://alive2.llvm.org/ce/z/cC-uyb
- b = false:
  - select a, true, (select b, A, B) => select a, true, B : https://alive2.llvm.org/ce/z/ZXpJq9
  - or a, (select b, A, B) => select a, true, B : https://alive2.llvm.org/ce/z/hnDrJj


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101720

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
  llvm/lib/Transforms/InstCombine/InstCombineInternal.h
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/select-safe-impliedcond-transforms.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101720.342232.patch
Type: text/x-patch
Size: 11991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210502/15d90422/attachment.bin>


More information about the llvm-commits mailing list