Skip to content

Commit 1717d8d

Browse files
committed
improvement
1 parent 0c37e00 commit 1717d8d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/lib/Transforms/Scalar/SROA.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5235,12 +5235,6 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52355235
}
52365236
}
52375237

5238-
// If there are only intrinsic users, try to represent as a legal integer
5239-
// type because we are probably just copying data around and the integer can
5240-
// be promoted.
5241-
if (OnlyIntrinsicUsers && DL.isLegalInteger(P.size() * 8))
5242-
return {Type::getIntNTy(*C, P.size() * 8), false, nullptr};
5243-
52445238
// Can we find an appropriate subtype in the original allocated
52455239
// type?
52465240
if (Type *TypePartitionTy = getTypePartition(DL, AI.getAllocatedType(),
@@ -5263,6 +5257,13 @@ AllocaInst *SROA::rewritePartition(AllocaInst &AI, AllocaSlices &AS,
52635257
DL.getTypeAllocSize(LargestIntTy).getFixedValue() >= P.size() &&
52645258
isIntegerWideningViable(P, LargestIntTy, DL))
52655259
return {LargestIntTy, true, nullptr};
5260+
5261+
// If there are only intrinsic users, try to represent as a legal integer
5262+
// type because we are probably just copying data around and the integer can
5263+
// be promoted.
5264+
if (OnlyIntrinsicUsers && DL.isLegalInteger(P.size() * 8))
5265+
return {Type::getIntNTy(*C, P.size() * 8), isIntegerWideningViable(P, Type::getIntNTy(*C, P.size() * 8), DL), nullptr};
5266+
52665267
// Fallback to TypePartitionTy and we probably won't promote.
52675268
return {TypePartitionTy, false, nullptr};
52685269
}

llvm/test/Transforms/SROA/basictest.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ define i64 @test19(ptr %x) {
785785
; CHECK-NEXT: entry:
786786
; CHECK-NEXT: [[A_SROA_0_0_COPYLOAD:%.*]] = load i64, ptr [[X:%.*]], align 1
787787
; CHECK-NEXT: [[A_SROA_2_0_X_SROA_IDX:%.*]] = getelementptr inbounds i8, ptr [[X]], i64 8
788-
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load i64, ptr [[A_SROA_2_0_X_SROA_IDX]], align 1
788+
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load ptr, ptr [[A_SROA_2_0_X_SROA_IDX]], align 1
789789
; CHECK-NEXT: ret i64 [[A_SROA_0_0_COPYLOAD]]
790790
;
791791
entry:
@@ -809,7 +809,7 @@ define i64 @test19_addrspacecast(ptr %x) {
809809
; CHECK-NEXT: [[CAST1:%.*]] = addrspacecast ptr [[X:%.*]] to ptr addrspace(1)
810810
; CHECK-NEXT: [[A_SROA_0_0_COPYLOAD:%.*]] = load i64, ptr addrspace(1) [[CAST1]], align 1
811811
; CHECK-NEXT: [[A_SROA_2_0_CAST1_SROA_IDX:%.*]] = getelementptr inbounds i8, ptr addrspace(1) [[CAST1]], i16 8
812-
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load i64, ptr addrspace(1) [[A_SROA_2_0_CAST1_SROA_IDX]], align 1
812+
; CHECK-NEXT: [[A_SROA_2_0_COPYLOAD:%.*]] = load ptr, ptr addrspace(1) [[A_SROA_2_0_CAST1_SROA_IDX]], align 1
813813
; CHECK-NEXT: ret i64 [[A_SROA_0_0_COPYLOAD]]
814814
;
815815
entry:

0 commit comments

Comments
 (0)