[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
Thu May 19 11:39:22 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd5c130f17e50: [ValueTracking] Added support to deduce PHI Nodes values being a power of 2 (authored by huangjd).
Changed prior to commit:
https://reviews.llvm.org/D125332?vs=430543&id=430758#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125332/new/
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
@@ -2128,6 +2128,25 @@
}
}
+ // A PHI node is power of two if all incoming values are power of two.
+ if (const PHINode *PN = dyn_cast<PHINode>(V)) {
+ Query RecQ = Q;
+
+ // 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, NewDepth, RecQ);
+ });
+ }
+
// An exact divide or right shift can only shift off zero bits, so the result
// is a power of two only if the first operand is a power of two and not
// copying a sign bit (sdiv int_min, 2).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125332.430758.patch
Type: text/x-patch
Size: 1232 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220519/71663fa4/attachment.bin>
More information about the llvm-commits
mailing list