[PATCH] D99674: [InstCombine] Conditionally fold select i1 into and/or

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 31 10:37:46 PDT 2021


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

This patch fixes llvm.org/pr49688 by conditionally folding select i1 into and/or:

  select cond, cond2, false
  ->
  and cond, cond2

This is not safe if cond2 is poison whereas cond isn’t.

Unconditionally disabling this transformation affects later pipelines that depend on and/or i1s.
To minimize its impact, this patch conservatively checks whether cond2 is an instruction that
creates a poison or its operand creates a poison.
This approach is similar to what InstSimplify's SimplifyWithOpReplaced is doing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99674

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/and-fcmp.ll
  llvm/test/Transforms/InstCombine/onehot_merge.ll
  llvm/test/Transforms/InstCombine/pr49668.ll
  llvm/test/Transforms/InstCombine/signed-truncation-check.ll
  llvm/test/Transforms/InstCombine/widenable-conditions.ll
  llvm/test/Transforms/PhaseOrdering/unsigned-multiply-overflow-check.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99674.334483.patch
Type: text/x-patch
Size: 15650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210331/b2c4c6de/attachment.bin>


More information about the llvm-commits mailing list