[PATCH] D137157: InstCombine] fold mul with decremented "shl -1" factor (2nd try)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 06:33:21 PDT 2022


spatel created this revision.
spatel added reviewers: nikic, glandium, chapuni, jrtc27, fmayer, mstorsjo.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is a hopefully corrected version of:
bc886e9b587b <https://reviews.llvm.org/rGbc886e9b587b9d009f49b12eaaa9ebc1c71905a1>

I thought the patch was obvious enough to not require pre-commit review the first time, but I made a copy-paste error that created an "add" instead of the intended "sub". The regression tests showed the bug, but I overlooked that too (embarrassing).

So this time, I'm posting for review in case someone (or bots) would like to apply the patch and confirm that the previous errors (there were several independent reports) are no longer there. As I said in a comment on issue #58717 <https://github.com/llvm/llvm-project/issues/58717>, the bug reports confirm that the pattern does occur in many real-world applications, so hopefully, eliminating the multiply results in better code.

I added one more regression test in this version of the test, and here's an Alive2 proof to show that exact example:
https://alive2.llvm.org/ce/z/dge7VC

Original commit message:

This is a sibling to:
6064e92b0a84 <https://reviews.llvm.org/rG6064e92b0a84b6d52b25ab1e6da90e74c76c6eb0>
...but we canonicalize the shl+add to shl+xor,
so the pattern is different than I expected:
https://alive2.llvm.org/ce/z/8CX16e

I have not found any patterns that are safe
to propagate no-wrap, so that is not included
here.


https://reviews.llvm.org/D137157

Files:
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  llvm/test/Transforms/InstCombine/mul.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137157.472271.patch
Type: text/x-patch
Size: 4917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221101/3ccfdccb/attachment.bin>


More information about the llvm-commits mailing list