Skip to content

Commit 5709fc1

Browse files
committed
Remove constant special case
With the new expansion this would have to be more careful about a constant on multi-use GEP and non-constant on merged one-use GEPs. Just drop this heuristic for now.
1 parent b8ca1c6 commit 5709fc1

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,27 +2147,22 @@ CommonPointerBase CommonPointerBase::compute(Value *LHS, Value *RHS) {
21472147
}
21482148

21492149
bool CommonPointerBase::isExpensive() const {
2150-
bool SeenConst = false;
21512150
unsigned NumGEPs = 0;
2152-
auto ProcessGEPs = [&SeenConst, &NumGEPs](ArrayRef<GEPOperator *> GEPs) {
2151+
auto ProcessGEPs = [&NumGEPs](ArrayRef<GEPOperator *> GEPs) {
21532152
bool SeenMultiUse = false;
21542153
for (GEPOperator *GEP : GEPs) {
21552154
// Only count multi-use GEPs, excluding the first one. For the first one,
21562155
// we will directly reuse the offset. For one-use GEPs, their offset will
21572156
// be folded into a multi-use GEP.
21582157
if (!GEP->hasOneUse()) {
2159-
if (SeenMultiUse) {
2160-
bool IsConst = GEP->hasAllConstantIndices();
2161-
SeenConst |= IsConst;
2162-
NumGEPs += !IsConst;
2163-
}
2158+
if (SeenMultiUse)
2159+
++NumGEPs;
21642160
SeenMultiUse = true;
21652161
}
21662162
}
21672163
};
21682164
ProcessGEPs(LHSGEPs);
21692165
ProcessGEPs(RHSGEPs);
2170-
NumGEPs += SeenConst;
21712166
return NumGEPs > 2;
21722167
}
21732168

llvm/test/Transforms/InstCombine/icmp-gep.ll

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -932,21 +932,17 @@ define i1 @gep_multiple_multi_use_below_limit_extra_one_use_gep2(ptr %base, i64
932932
ret i1 %cmp
933933
}
934934

935-
define i1 @gep_multiple_multi_use_below_limit_consts(ptr %base, i64 %idx1, i64 %idx2) {
936-
; CHECK-LABEL: @gep_multiple_multi_use_below_limit_consts(
935+
define i1 @gep_multiple_multi_above_below_limit_consts(ptr %base, i64 %idx1, i64 %idx2) {
936+
; CHECK-LABEL: @gep_multiple_multi_above_below_limit_consts(
937937
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 16
938938
; CHECK-NEXT: call void @use(ptr [[GEP1]])
939-
; CHECK-NEXT: [[GEP4_IDX:%.*]] = shl i64 [[IDX2:%.*]], 2
940-
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[GEP1]], i64 [[GEP4_IDX]]
941-
; CHECK-NEXT: call void @use(ptr [[GEP4]])
942-
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP4]], i64 16
939+
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[GEP1]], i64 [[IDX1:%.*]]
940+
; CHECK-NEXT: call void @use(ptr [[GEP2]])
941+
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 16
943942
; CHECK-NEXT: call void @use(ptr [[GEP3]])
944-
; CHECK-NEXT: [[GEP4_IDX1:%.*]] = shl i64 [[IDX3:%.*]], 2
945-
; CHECK-NEXT: [[GEP5:%.*]] = getelementptr i8, ptr [[GEP3]], i64 [[GEP4_IDX1]]
946-
; CHECK-NEXT: call void @use(ptr [[GEP5]])
947-
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GEP4_IDX]], 32
948-
; CHECK-NEXT: [[TMP2:%.*]] = sub i64 0, [[GEP4_IDX1]]
949-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP1]], [[TMP2]]
943+
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i32, ptr [[GEP3]], i64 [[IDX2:%.*]]
944+
; CHECK-NEXT: call void @use(ptr [[GEP4]])
945+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP4]], [[BASE]]
950946
; CHECK-NEXT: ret i1 [[CMP]]
951947
;
952948
%gep1 = getelementptr i32, ptr %base, i64 4

0 commit comments

Comments
 (0)