[llvm] 7a77b76 - [InstCombine] Add additional multi-use test for sub of gep (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 22:25:44 PDT 2024


Author: Nikita Popov
Date: 2024-04-25T14:24:55+09:00
New Revision: 7a77b763af3b6ac3218b9cf574d7d65f3196a4ec

URL: https://github.com/llvm/llvm-project/commit/7a77b763af3b6ac3218b9cf574d7d65f3196a4ec
DIFF: https://github.com/llvm/llvm-project/commit/7a77b763af3b6ac3218b9cf574d7d65f3196a4ec.diff

LOG: [InstCombine] Add additional multi-use test for sub of gep (NFC)

A case where still performing the fold is clearly profitable.

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/sub.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll
index a84e389f13c3b8..56dd9c6a879981 100644
--- a/llvm/test/Transforms/InstCombine/sub.ll
+++ b/llvm/test/Transforms/InstCombine/sub.ll
@@ -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


        


More information about the llvm-commits mailing list