[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
Tue Apr 14 19:35:51 PDT 2020


Carrot added a comment.

Thank you for the example.

The alloca type is declared as you described:

%union.U = type { %"struct.U::A" }
%"struct.U::A" = type { i64, i32 }

Some related instructions

  %x = alloca %union.U, align 8
  ...
  %b2 = bitcast %union.U* %x to %"struct.U::B"*
  %agg.tmp.sroa.0.0..sroa_idx = getelementptr inbounds %"struct.U::B", %"struct.U::B"* %b2, i64 0, i32 1
  %agg.tmp.sroa.0.0..sroa_cast = bitcast %struct.C* %agg.tmp.sroa.0.0..sroa_idx to i64*
  %agg.tmp.sroa.0.0.copyload = load i64, i64* %agg.tmp.sroa.0.0..sroa_cast, align 4, !tbaa.struct !8

My patch doesn't split the last load instruction, because the 64bit load offset doesn't match a field in %union.U, to be conservative function isSplittableType returns false.

But if I change the definition of struct A to

struct D {

  int d1; 
  int d2; 

};

  struct A { 
    struct D m1; 
    int m2; 
  } a;

Then it works as you described.

So for union types the alloca type is totally useless.

I will seek the road in SROA slices as you suggested in https://reviews.llvm.org/D68414#1965055.

Thanks a lot!


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

https://reviews.llvm.org/D68414





More information about the llvm-commits mailing list