@@ -3035,6 +3035,12 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
30353035
30363036 // Stores should be in the same basic block
30373037 // The load should not be in the middle of the stores
3038+ // Note:
3039+ // If the load is in a different basic block with the stores, we can still
3040+ // do the tree structured merge. This is because we do not have the
3041+ // store->load forwarding here. The merged vector will be stored back to
3042+ // NewAI and the new load will load from NewAI. The forwarding will be
3043+ // handled later when we try to promote NewAI.
30383044 BasicBlock *LoadBB = TheLoad->getParent ();
30393045 BasicBlock *StoreBB = StoreInfos[0 ].Store ->getParent ();
30403046
@@ -3067,8 +3073,8 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
30673073
30683074 LLVM_DEBUG (dbgs () << " Rewrite stores into shufflevectors:\n " );
30693075 while (VecElements.size () > 1 ) {
3070- uint64_t NumElts = VecElements.size ();
3071- for (uint64_t i = 0 ; i < NumElts / 2 ; i++ ) {
3076+ const auto NumElts = VecElements.size ();
3077+ for ([[maybe_unused]] const auto _ : llvm::seq ( NumElts / 2 ) ) {
30723078 Value *V0 = VecElements.front ();
30733079 VecElements.pop ();
30743080 Value *V1 = VecElements.front ();
@@ -5268,9 +5274,7 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52685274 PHIUsers, SelectUsers);
52695275 bool Promotable = true ;
52705276 // Check whether we can have tree-structured merge.
5271- std::optional<SmallVector<Value *, 4 >> DeletedValues =
5272- Rewriter.rewriteTreeStructuredMerge (P);
5273- if (DeletedValues) {
5277+ if (auto DeletedValues = Rewriter.rewriteTreeStructuredMerge (P)) {
52745278 NumUses += DeletedValues->size () + 1 ;
52755279 for (Value *V : *DeletedValues)
52765280 DeadInsts.push_back (V);
0 commit comments