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

Stanislav Mekhanoshin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 26 08:32:37 PDT 2020


rampitec 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;
----------------
lebedev.ri wrote:
> Am i correctly reading that this is preventing the fold if PHI has the same incoming BB more than once?
Right.


================
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) {
----------------
lebedev.ri wrote:
> 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?
I thought about it. but it seems to miss the target. It will not help SROA to eliminate an alloca as far as I understand, so there seems to be no reason to do it.


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

https://reviews.llvm.org/D89978



More information about the llvm-commits mailing list