[PATCH] D125332: [ValueTracking] Added support to deduce PHI Nodes values being a power of 2
William Junda Huang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 10 12:51:54 PDT 2022
huangjd created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
huangjd requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Add Value Tracking support to deduce induction variable being a power of 2, allowing urem optimizations
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125332
Files:
llvm/lib/Analysis/ValueTracking.cpp
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -2132,12 +2132,18 @@
if (const PHINode *PN = dyn_cast<PHINode>(V)) {
Query RecQ = Q;
- // Recursively check all incoming values
+ // Recursively check all incoming values. Limit recursion to 2 levels, so
+ // that search complexity is limited to number of operands^2.
+ unsigned NewDepth = std::max(Depth, MaxAnalysisRecursionDepth - 1);
return llvm::all_of(PN->operands(), [&](const Use &U) {
+ // Value is power of 2 if it is coming from PHI node itself by induction.
if (U.get() == PN)
return true;
+
+ // Change the context instruction to the incoming block where it is
+ // evaluated.
RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
- return isKnownToBeAPowerOfTwo(U.get(), OrZero, Depth, RecQ);
+ return isKnownToBeAPowerOfTwo(U.get(), OrZero, NewDepth, RecQ);
});
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125332.428470.patch
Type: text/x-patch
Size: 1058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220510/fdfa436e/attachment.bin>
More information about the llvm-commits
mailing list