This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] ((A + B) + C) + A --> (A << 1) + (B + C)
AbandonedPublic

Authored by Chenbing.Zheng on May 8 2022, 7:46 PM.

Details

Summary

This patch deal with 3 add sequences, which include the same op
in firse add and third add:
((A + B) + C) + A --> (A << 1) + (B + C)
((A + B) + C) + B --> (B << 1) + (A + C)

Diff Detail

Event Timeline

Chenbing.Zheng created this revision.May 8 2022, 7:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 8 2022, 7:46 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Chenbing.Zheng requested review of this revision.May 8 2022, 7:46 PM

What's the motiviation for this patch? I notice we already get the shift+add pattern: https://clang.godbolt.org/z/58c6e9jbj

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
1356

Slightly tidier to minimise CreateAdd calls?

Value *ADD = Builder.CreateAdd(RHS == A ? B : A, C, "reass.add")

Chenbing.Zheng abandoned this revision.May 9 2022, 1:38 AM

What's the motiviation for this patch? I notice we already get the shift+add pattern: https://clang.godbolt.org/z/58c6e9jbj

I just notice the 'todo' left in add.ll. According to what you describe, we already have pattern to implement it, so I will abandant this patch.

spatel added a comment.May 9 2022, 4:44 AM

What's the motiviation for this patch? I notice we already get the shift+add pattern: https://clang.godbolt.org/z/58c6e9jbj

I just notice the 'todo' left in add.ll. According to what you describe, we already have pattern to implement it, so I will abandant this patch.

This is another example where -reassociate can handle the problem more generally. It recognizes the common operand and forms a multiply. If we do not have a real benchmark or application that shows a problem for this kind of pattern, then it would be fine to replace that "TODO" comment with an explanation like:

; "-reassociate" can optimize this even if "-instcombine" does not.