[PATCH] D68414: [SROA] Enhance AggLoadStoreRewriter to rewrite integer load/store if it covers multi fields in original aggregate

Guozhi Wei via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 8 16:52:06 PDT 2020


Carrot marked an inline comment as done.
Carrot added a comment.

The most complex part of this patch is avoiding "blindly rewriting", and most of the new data structures are used for this purpose.

Suppose we have following type definition and pointers

%inner = type { i32, i32 }
%outer = type { %inner, %inner }

%local = alloca %outer, align 8
%inner_ptr1 = getelementptr inbounds %outer, %outer* %local, i64 0, i32 0, i32 0
%inner_ptr2 = getelementptr inbounds %outer, %outer* %local, i64 0, i32 0, i32 1
%inner_ptr3 = getelementptr inbounds %outer, %outer* %local, i64 0, i32 1, i32 0
%ptr1 = bitcast i32* %inner_ptr1 to i64*
%ptr2 = bitcast i32* %inner_ptr2 to i64*
%ptr3 = bitcast i32* %inner_ptr3 to i64*

And then we use these pointers to load 64bit value.

%load1 = load i64, i64* %ptr1
%load2 = load i64, i64* %ptr2
%load3 = load i64, i64* %ptr3

load1 covers the first whole inner struct, load3 covers the second whole inner struct, these are very common in llvm, there are many such cases in llvm test cases, so they should not be split.
load2 covers the second part of the first inner struct and the first part of the second inner struct, this is very uncommon in llvm. And later when construct SROA slices, all load1, load2 and load3 forms a single slice, causes SROA failed to replace any field of the %local structure. Only split load2 earlier in AggLoadStoreRewriter, usual SROA slices can be formed later for load2 and load3 separately.



================
Comment at: llvm/lib/Transforms/Scalar/SROA.cpp:3586
 
-  bool visitPHINode(PHINode &PN) {
+  void visitPHINode(PHINode &PN) {
     enqueueUsers(PN);
----------------
efriedma wrote:
> Rearranging functions like this makes it harder to read the patch.
This is because the base class is changed from InstVisitor to PtrUseVisitor. These 2 classes have different return types for various visit functions. Fortunately they have similar semantics.


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

https://reviews.llvm.org/D68414





More information about the llvm-commits mailing list