[PATCH] D44147: [InstCombine] Fold add/sub over phi node
Hiroshi Inoue via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 6 06:21:42 PST 2018
inouehrs created this revision.
inouehrs added reviewers: spatel, craig.topper, scanon, hfinkel, efriedma, kbarton, nemanjai.
Herald added subscribers: javed.absar, sanjoy.
This patch adds FoldPHIUserOpIntoPred, which finds a phi node that is
1. used by only one add/sub instruction and
2. all its incoming values are ConstantInt or add/sub instruction used only by this phi node.
For such Phi nodes, we can eliminate add/sub instruction after the phi node by changing immediates of previous add/sub instructions.
Example of redundant add instruction to be optimized:
BB1:
%add = add i64 %a, 5 # -> immediate will be changed to 6
br label %BB3
BB2:
%sub = sub i64 %b, 3 # -> immediate will be changed to 2
br label %BB3
BB3:
%phi = phi i64 [ %add, %BB1 ], [ %sub, %BB2 ]
%rc = add i64 %phi, 1 # -> will be removed
Additionally, if only one incoming value to the phi node does not meet above conditions, we can move the add/sub instruction to avoid partially redundant computation.
This optimization happens about 19k times (4k for full redundant cases and others for partially redundant cases) while building LLVM/Clang.
I am going to add similar optimization for logical operations as well as add/sub as a separate patch later.
https://reviews.llvm.org/D44147
Files:
lib/Transforms/InstCombine/InstCombineInternal.h
lib/Transforms/InstCombine/InstCombinePHI.cpp
test/Analysis/ValueTracking/non-negative-phi-bits.ll
test/Transforms/IndVarSimplify/rewrite-loop-exit-value.ll
test/Transforms/InstCombine/stacksaverestore.ll
test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll
test/Transforms/LoopVectorize/X86/masked_load_store.ll
test/Transforms/SLPVectorizer/AArch64/gather-reduce.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44147.137177.patch
Type: text/x-patch
Size: 19882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180306/bf869df5/attachment.bin>
More information about the llvm-commits
mailing list