[PATCH] D94712: Do not traverse ConstantData use-list in LookInterchange

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 17:36:42 PST 2021


dexonsmith added a reviewer: fhahn.
dexonsmith added a subscriber: fhahn.
dexonsmith added a comment.

@fhahn, can you help with the review here? This is one of only a few instances of walking the use-list of `ConstantData`. The broader context is an old RFC that @willir is working with me on:
https://lists.llvm.org/pipermail/llvm-dev/2016-September/105157.html

(I know the motivation and context, but I'm not the right person to review functional changes to this pass.)



================
Comment at: llvm/lib/Transforms/Scalar/LoopInterchange.cpp:663-669
 static PHINode *findInnerReductionPhi(Loop *L, Value *V) {
-  for (Value *User : V->users()) {
-    if (PHINode *PHI = dyn_cast<PHINode>(User)) {
-      if (PHI->getNumIncomingValues() == 1)
-        continue;
-      RecurrenceDescriptor RD;
-      if (RecurrenceDescriptor::isReductionPHI(PHI, L, RD))
-        return PHI;
-      return nullptr;
-    }
+  for (PHINode &PHI : L->getHeader()->phis()) {
+    if (PHI.getNumIncomingValues() == 1 ||
+        !llvm::is_contained(PHI.incoming_values(), V))
+      continue;
+    RecurrenceDescriptor RD;
+    return RecurrenceDescriptor::isReductionPHI(&PHI, L, RD) ? &PHI : nullptr;
----------------
It looks like sometimes `findInnerReductionPhi` is running on ConstantData, which can come from another function (or module), and will eventually lose its use-lists (no one should walk the use-list of `i1 0`; usually anything they learn from that will be wrong).
- @willir's current patch changes the order of iteration. I think we'll need to check compile-time if we do this.
- Another option would be to return `nullptr` on `isa<ConstantData>()`, if it's correct.
- If that's correct, should this return `nullptr` on `isa<Constant>()` more generally?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94712/new/

https://reviews.llvm.org/D94712



More information about the llvm-commits mailing list