[PATCH] D89978: Fix SROA with a PHI mergig values from a same block

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 26 08:23:01 PDT 2020


lebedev.ri added a reviewer: lebedev.ri.
lebedev.ri added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/SROA.cpp:3535-3537
+        llvm::any_of(PHI->blocks(), [&VisitedBlocks](BasicBlock *B)
+          { return !VisitedBlocks.insert(B).second; }))
       return false;
----------------
Am i correctly reading that this is preventing the fold if PHI has the same incoming BB more than once?


================
Comment at: llvm/lib/Transforms/Scalar/SROA.cpp:3544-3557
     SmallVector<Value *, 4> Index(GEPI.idx_begin(), GEPI.idx_end());
     bool IsInBounds = GEPI.isInBounds();
     IRBuilderTy PHIBuilder(GEPI.getParent()->getFirstNonPHI());
     PHINode *NewPN = PHIBuilder.CreatePHI(GEPI.getType(),
                                           PHI->getNumIncomingValues(),
                                           PHI->getName() + ".sroa.phi");
     for (unsigned I = 0, E = PHI->getNumIncomingValues(); I != E; ++I) {
----------------
Can't you instead simply cache GEP's, i.e. have a `map<basicblock, NewVal>`,
and perform this GEP creation only if there is no previous gep for that incoming bb in the map?


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

https://reviews.llvm.org/D89978



More information about the llvm-commits mailing list