mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
[SLSR] consider &B[S << i] as &B[(1 << i) * S]
Summary: This reduces handling &B[(1 << i) * s] to handling &B[i * S]. Test Plan: slsr-gep.ll Reviewers: meheff Subscribers: sanjoy, llvm-commits Differential Revision: http://reviews.llvm.org/D8837 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234180 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7d424d47d3
commit
10483b93ea
@ -353,8 +353,6 @@ void StraightLineStrengthReduce::factorArrayIndex(Value *ArrayIdx,
|
|||||||
ArrayIdx, ElementSize, GEP);
|
ArrayIdx, ElementSize, GEP);
|
||||||
Value *LHS = nullptr;
|
Value *LHS = nullptr;
|
||||||
ConstantInt *RHS = nullptr;
|
ConstantInt *RHS = nullptr;
|
||||||
// TODO: handle shl. e.g., we could treat (S << 2) as (S * 4).
|
|
||||||
//
|
|
||||||
// One alternative is matching the SCEV of ArrayIdx instead of ArrayIdx
|
// One alternative is matching the SCEV of ArrayIdx instead of ArrayIdx
|
||||||
// itself. This would allow us to handle the shl case for free. However,
|
// itself. This would allow us to handle the shl case for free. However,
|
||||||
// matching SCEVs has two issues:
|
// matching SCEVs has two issues:
|
||||||
@ -370,6 +368,13 @@ void StraightLineStrengthReduce::factorArrayIndex(Value *ArrayIdx,
|
|||||||
// SLSR is currently unsafe if i * S may overflow.
|
// SLSR is currently unsafe if i * S may overflow.
|
||||||
// GEP = Base + sext(LHS *nsw RHS) * ElementSize
|
// GEP = Base + sext(LHS *nsw RHS) * ElementSize
|
||||||
allocateCandidateAndFindBasisForGEP(Base, RHS, LHS, ElementSize, GEP);
|
allocateCandidateAndFindBasisForGEP(Base, RHS, LHS, ElementSize, GEP);
|
||||||
|
} else if (match(ArrayIdx, m_NSWShl(m_Value(LHS), m_ConstantInt(RHS)))) {
|
||||||
|
// GEP = Base + sext(LHS <<nsw RHS) * ElementSize
|
||||||
|
// = Base + sext(LHS *nsw (1 << RHS)) * ElementSize
|
||||||
|
APInt One(RHS->getBitWidth(), 1);
|
||||||
|
ConstantInt *PowerOf2 =
|
||||||
|
ConstantInt::get(RHS->getContext(), One << RHS->getValue());
|
||||||
|
allocateCandidateAndFindBasisForGEP(Base, PowerOf2, LHS, ElementSize, GEP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ define i32 @slsr_gep(i32* %input, i64 %s) {
|
|||||||
%v1 = load i32, i32* %p1
|
%v1 = load i32, i32* %p1
|
||||||
|
|
||||||
; v2 = input[s * 2];
|
; v2 = input[s * 2];
|
||||||
%s2 = mul nsw i64 %s, 2
|
%s2 = shl nsw i64 %s, 1
|
||||||
%p2 = getelementptr inbounds i32, i32* %input, i64 %s2
|
%p2 = getelementptr inbounds i32, i32* %input, i64 %s2
|
||||||
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s
|
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %s
|
||||||
%v2 = load i32, i32* %p2
|
%v2 = load i32, i32* %p2
|
||||||
@ -38,7 +38,7 @@ define i32 @slsr_gep_sext(i32* %input, i32 %s) {
|
|||||||
%v1 = load i32, i32* %p1
|
%v1 = load i32, i32* %p1
|
||||||
|
|
||||||
; v2 = input[(long)(s * 2)];
|
; v2 = input[(long)(s * 2)];
|
||||||
%s2 = mul nsw i32 %s, 2
|
%s2 = shl nsw i32 %s, 1
|
||||||
%t2 = sext i32 %s2 to i64
|
%t2 = sext i32 %s2 to i64
|
||||||
%p2 = getelementptr inbounds i32, i32* %input, i64 %t2
|
%p2 = getelementptr inbounds i32, i32* %input, i64 %t2
|
||||||
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t
|
; CHECK: %p2 = getelementptr inbounds i32, i32* %p1, i64 %t
|
||||||
@ -57,7 +57,7 @@ define i32 @slsr_gep_2d([10 x [5 x i32]]* %input, i64 %s, i64 %t) {
|
|||||||
%v0 = load i32, i32* %p0
|
%v0 = load i32, i32* %p0
|
||||||
|
|
||||||
; v1 = input[s * 2][t];
|
; v1 = input[s * 2][t];
|
||||||
%s2 = mul nsw i64 %s, 2
|
%s2 = shl nsw i64 %s, 1
|
||||||
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = mul i64 %s, 5
|
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = mul i64 %s, 5
|
||||||
%p1 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s2, i64 %t
|
%p1 = getelementptr inbounds [10 x [5 x i32]], [10 x [5 x i32]]* %input, i64 0, i64 %s2, i64 %t
|
||||||
; CHECK: %p1 = getelementptr inbounds i32, i32* %p0, i64 [[BUMP]]
|
; CHECK: %p1 = getelementptr inbounds i32, i32* %p0, i64 [[BUMP]]
|
||||||
@ -90,7 +90,7 @@ define i64 @slsr_gep_uglygep([10 x [5 x %struct.S]]* %input, i64 %s, i64 %t) {
|
|||||||
%v0 = load i64, i64* %p0
|
%v0 = load i64, i64* %p0
|
||||||
|
|
||||||
; v1 = input[s * 2][t].f1;
|
; v1 = input[s * 2][t].f1;
|
||||||
%s2 = mul nsw i64 %s, 2
|
%s2 = shl nsw i64 %s, 1
|
||||||
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = mul i64 %s, 60
|
; CHECK: [[BUMP:%[a-zA-Z0-9]+]] = mul i64 %s, 60
|
||||||
%p1 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s2, i64 %t, i32 0
|
%p1 = getelementptr inbounds [10 x [5 x %struct.S]], [10 x [5 x %struct.S]]* %input, i64 0, i64 %s2, i64 %t, i32 0
|
||||||
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
|
; CHECK: getelementptr inbounds i8, i8* %{{[0-9]+}}, i64 [[BUMP]]
|
||||||
@ -121,7 +121,7 @@ define i32 @slsr_out_of_bounds_gep(i32* %input, i32 %s) {
|
|||||||
%v1 = load i32, i32* %p1
|
%v1 = load i32, i32* %p1
|
||||||
|
|
||||||
; v2 = input[(long)(s * 2)];
|
; v2 = input[(long)(s * 2)];
|
||||||
%s2 = mul nsw i32 %s, 2
|
%s2 = shl nsw i32 %s, 1
|
||||||
%t2 = sext i32 %s2 to i64
|
%t2 = sext i32 %s2 to i64
|
||||||
%p2 = getelementptr i32, i32* %input, i64 %t2
|
%p2 = getelementptr i32, i32* %input, i64 %t2
|
||||||
; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t
|
; CHECK: %p2 = getelementptr i32, i32* %p1, i64 %t
|
||||||
|
Loading…
Reference in New Issue
Block a user