[PATCH] D71064: [InstCombine] Invert `add A, sext(B) --> sub A, zext(B)` canonicalization (to `sub A, zext B -> add A, sext B`)

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 06:24:11 PST 2019


lebedev.ri created this revision.
lebedev.ri added reviewers: spatel, efriedma.
lebedev.ri added a project: LLVM.
Herald added a subscriber: hiraditya.

D68408 <https://reviews.llvm.org/D68408> proposes to greatly improve our negation sinking abilities.
But in current canonicalization, we produce `sub A, zext(B)`,
which we will consider non-canonical and try to sink that negation,
undoing the existing canonicalization.
So unless we explicitly stop producing previous canonicalization,
we will have two conflicting folds, and will end up endlessly looping.

This inverts canonicalization, and adds back the obvious fold
that we'd miss:

- `sub [nsw] Op0, sext/zext (bool Y) -> add [nsw] Op0, zext/sext (bool Y)` https://rise4fun.com/Alive/xx4
- `sext(bool) + C -> bool ? C - 1 : C` https://rise4fun.com/Alive/fBl

It is obvious that `@ossfuzz_9880()` / `@lshr_out_of_range()`/`@ashr_out_of_range()` (oss-fuzz 4871)
are no longer folded as much, though it isn't obvious whether those failures are important?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71064

Files:
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/test/Transforms/InstCombine/add.ll
  llvm/test/Transforms/InstCombine/apint-shift.ll
  llvm/test/Transforms/InstCombine/logical-select.ll
  llvm/test/Transforms/InstCombine/select.ll
  llvm/test/Transforms/InstCombine/shift.ll
  llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71064.232330.patch
Type: text/x-patch
Size: 10283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191205/2246f8c4/attachment.bin>


More information about the llvm-commits mailing list