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)
Details
Details
Diff Detail
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Unit Tests
Event Timeline
Comment Actions
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") |
Comment Actions
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.
Comment Actions
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.
Slightly tidier to minimise CreateAdd calls?
Value *ADD = Builder.CreateAdd(RHS == A ? B : A, C, "reass.add")