Skip to content

Commit

Permalink
[InstCombine] Add additional multi-use test for sub of gep (NFC)
Browse files Browse the repository at this point in the history
A case where still performing the fold is clearly profitable.
  • Loading branch information
nikic committed Apr 25, 2024
1 parent 873889b commit 7a77b76
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions llvm/test/Transforms/InstCombine/sub.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,27 @@ define i64 @test61(ptr %foo, i64 %i, i64 %j) {
ret i64 %sub
}

declare void @use.ptr(ptr)

define i64 @test_sub_ptradd_multiuse(ptr %p, i64 %idx1, i64 %idx2) {
; CHECK-LABEL: @test_sub_ptradd_multiuse(
; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[IDX1:%.*]]
; CHECK-NEXT: call void @use.ptr(ptr [[P1]])
; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[IDX2:%.*]]
; CHECK-NEXT: [[P1_INT:%.*]] = ptrtoint ptr [[P1]] to i64
; CHECK-NEXT: [[P2_INT:%.*]] = ptrtoint ptr [[P2]] to i64
; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[P1_INT]], [[P2_INT]]
; CHECK-NEXT: ret i64 [[SUB]]
;
%p1 = getelementptr inbounds i8, ptr %p, i64 %idx1
call void @use.ptr(ptr %p1)
%p2 = getelementptr inbounds i8, ptr %p, i64 %idx2
%p1.int = ptrtoint ptr %p1 to i64
%p2.int = ptrtoint ptr %p2 to i64
%sub = sub i64 %p1.int, %p2.int
ret i64 %sub
}

define i32 @test62(i32 %A) {
; CHECK-LABEL: @test62(
; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[A:%.*]], 1
Expand Down

0 comments on commit 7a77b76

Please sign in to comment.