[PATCH] D146928: [NaryReassociate] Transform expression (X << C1) + C2 to (X + C3) << C1,

Alex MacLean via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 26 16:46:08 PDT 2023


AlexM created this revision.
Herald added subscribers: mattd, gchakrabarti, asavonic, hiraditya.
Herald added a project: All.
AlexM edited the summary of this revision.
AlexM added reviewers: pavelkopyl, mkazantsev, ebrevnov.
Herald added a subscriber: StephenFan.
AlexM published this revision for review.
Herald added subscribers: llvm-commits, jholewinski.
Herald added a project: LLVM.

where C1 <https://reviews.llvm.org/C1>, C2 and C3 are integer constants, such that C2 = C3 << C1 <https://reviews.llvm.org/C1>.

Some transformations in Instruction Combining may block GVN later.
For example,

(X + const1) << 22 || (X + const1) >> 10

may become

(X << 22 + const2) || (X + const1) >> 10

which will disable the GVN on x + const1.

This patch implements reverse transformation of such expressions thus, unfolding a common code to be eliminated by either GVN or CSE. In the default compilation pipeline GVN/CSE are run several times: after Instruction Combining, but before NaryReassociate and after NaryReassociate. Therefore, with this patch we try both patterns for GVN/CSE.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146928

Files:
  llvm/include/llvm/Transforms/Scalar/NaryReassociate.h
  llvm/lib/Transforms/Scalar/NaryReassociate.cpp
  llvm/test/Transforms/NaryReassociate/NVPTX/const-shl.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146928.508449.patch
Type: text/x-patch
Size: 5716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230326/65aaafb0/attachment.bin>


More information about the llvm-commits mailing list