If there are some passes in LLVM do the opposite of the SROA(Scalar Replacement of Aggregates) pass

Hi LLVM developers,

We tried to find if there are some passes in LLVM do the opposite of the SROA(Scalar Replacement of Aggregates) pass, but did not find one. Do we have this kind of pass to bring back the structure type? Or this is done separately in any transformation passes?

Thanks,
Lin-Ya

Hi Lin-Ya,

maybe reg2mem is what you’re looking for?

Regards,
Victor.

Hi Victor and LLVM developers,

Thanks for your reply!:slight_smile: reg2mem transforms values back to pointers. But I would like to look for the pass or any functions provided in LLVM to get the disaggregate structs back to aggregate struct. My goal is to do the transformation to coalesce the accesses from the same struct together.

Below is an example to explain clearer what I am looking for. In the IR, I would like to have 2 load instructions that each loads a variable in the struct transform to one single load instruction that directly loads the struct.

If this makes sense and anyone knows whether there is related passes or functions exists. Thanks for helping!

-Lin-Ya

Exported from Notepad++
%struct.mystruct = type <{ i8, i16, i8 }> @llvm.global_ctors = appending global [0 x { i32, void (), i8 }] zeroinitializer define i32 @_Z3accP8mystructPcPs(%struct.mystruct* noalias nonnull %input, i8* noalias nonnull %a, i16* noalias nonnull %b) { entry: br label %for.inc for.inc: ; preds = %for.inc, %entry %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] %idxprom = sext i32 %i.03 to i64 %a11 = getelementptr inbounds %struct.mystruct, %struct.mystruct* %input, i64 %idxprom, i32 0 %0 = load i8, i8* %a11, align 4 %arrayidx3 = getelementptr inbounds i8, i8* %a, i64 %idxprom store i8 %0, i8* %arrayidx3, align 1 %b62 = getelementptr inbounds %struct.mystruct, %struct.mystruct* %input, i64 %idxprom, i32 1 %1 = load i16, i16* %b62, align 1 %arrayidx8 = getelementptr inbounds i16, i16* %b, i64 %idxprom store i16 %1, i16* %arrayidx8, align 2 %inc = add nsw i32 %i.03, 1 %cmp = icmp slt i32 %inc, 10 br i1 %cmp, label %for.inc, label %for.end for.end: ; preds = %for.inc ret i32 0 }

Hi Victor and LLVM developers,

(+ Reformat the example for web browser reader

Thanks for your reply!:slight_smile: reg2mem transforms values back to pointers. But I would like to look for the pass or any functions provided in LLVM to get the disaggregate structs back to aggregate struct. My goal is to do the transformation to coalesce the accesses from the same struct together.

Below is an example to explain clearer what I am looking for. In the IR, I would like to have 2 load instructions that each loads a variable in the struct transform to one single load instruction that directly loads the struct.

If this makes sense and anyone knows whether there is related passes or functions exists. Thanks for helping!

-Lin-Ya

%struct.mystruct = type <{ i8, i16, i8 }>

@llvm.global_ctors = appending global [0 x { i32, void (), i8 }] zeroinitializer

define i32 @_Z3accP8mystructPcPs(%struct.mystruct* noalias nonnull %input, i8* %a, i16* noalias nonnull %b) {
entry:
br label %for.inc

for.inc: ; preds = %for.inc, %entry
%i.03 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
%idxprom = sext i32 %i.03 to i64
%a11 = getelementptr inbounds %struct.mystruct, %struct.mystruct* %input, i64 %idxprom, i32 0
%0 = load i8, i8* %a11, align 4
%arrayidx3 = getelementptr inbounds i8, i8* %a, i64 %idxprom
store i8 %0, i8* %arrayidx3, align 1
%b62 = getelementptr inbounds %struct.mystruct, %struct.mystruct* %input, i64 %idxprom, i32 1
%1 = load i16, i16* %b62, align 1
%arrayidx8 = getelementptr inbounds i16, i16* %b, i64 %idxprom
store i16 %1, i16* %arrayidx8, align 2
%inc = add nsw i32 %i.03, 1
%cmp = icmp slt i32 %inc, 10
br i1 %cmp, label %for.inc, label %for.end

for.end: ; preds = %for.inc
ret i32 0
}

Lin-Ya Yu <yu810226@gmail.com> 於 2019年3月6日 週三 下午12:06寫道: