Skip to content

Commit 7a77b76

Browse files
committed
[InstCombine] Add additional multi-use test for sub of gep (NFC)
A case where still performing the fold is clearly profitable.
1 parent 873889b commit 7a77b76

File tree

1 file changed

+21
-0
lines changed
  • llvm/test/Transforms/InstCombine

1 file changed

+21
-0
lines changed

llvm/test/Transforms/InstCombine/sub.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,27 @@ define i64 @test61(ptr %foo, i64 %i, i64 %j) {
11801180
ret i64 %sub
11811181
}
11821182

1183+
declare void @use.ptr(ptr)
1184+
1185+
define i64 @test_sub_ptradd_multiuse(ptr %p, i64 %idx1, i64 %idx2) {
1186+
; CHECK-LABEL: @test_sub_ptradd_multiuse(
1187+
; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[IDX1:%.*]]
1188+
; CHECK-NEXT: call void @use.ptr(ptr [[P1]])
1189+
; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[IDX2:%.*]]
1190+
; CHECK-NEXT: [[P1_INT:%.*]] = ptrtoint ptr [[P1]] to i64
1191+
; CHECK-NEXT: [[P2_INT:%.*]] = ptrtoint ptr [[P2]] to i64
1192+
; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[P1_INT]], [[P2_INT]]
1193+
; CHECK-NEXT: ret i64 [[SUB]]
1194+
;
1195+
%p1 = getelementptr inbounds i8, ptr %p, i64 %idx1
1196+
call void @use.ptr(ptr %p1)
1197+
%p2 = getelementptr inbounds i8, ptr %p, i64 %idx2
1198+
%p1.int = ptrtoint ptr %p1 to i64
1199+
%p2.int = ptrtoint ptr %p2 to i64
1200+
%sub = sub i64 %p1.int, %p2.int
1201+
ret i64 %sub
1202+
}
1203+
11831204
define i32 @test62(i32 %A) {
11841205
; CHECK-LABEL: @test62(
11851206
; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A:%.*]], 1

0 commit comments

Comments
 (0)