[llvm] 3eab6c5 - [InstCombine] Add test for GEP difference with bitcasts (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 07:12:08 PDT 2022


Author: Nikita Popov
Date: 2022-05-24T16:12:01+02:00
New Revision: 3eab6c5911415ce1f9b72738025f8f5051b55c34

URL: https://github.com/llvm/llvm-project/commit/3eab6c5911415ce1f9b72738025f8f5051b55c34
DIFF: https://github.com/llvm/llvm-project/commit/3eab6c5911415ce1f9b72738025f8f5051b55c34.diff

LOG: [InstCombine] Add test for GEP difference with bitcasts (NFC)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/sub-gep.ll b/llvm/test/Transforms/InstCombine/sub-gep.ll
index 4450459329dc..b198e1423ccd 100644
--- a/llvm/test/Transforms/InstCombine/sub-gep.ll
+++ b/llvm/test/Transforms/InstCombine/sub-gep.ll
@@ -369,3 +369,22 @@ define i64 @gep_
diff _second_inbounds(i8* %foo, i64 %i, i64 %j) {
   %sub = sub i64 %cast1, %cast2
   ret i64 %sub
 }
+
+define i64 @gep_
diff _with_bitcast(i64* %p, i64 %idx) {
+; CHECK-LABEL: @gep_
diff _with_bitcast(
+; CHECK-NEXT:    [[I0:%.*]] = bitcast i64* [[P:%.*]] to [4 x i64]*
+; CHECK-NEXT:    [[I1:%.*]] = getelementptr inbounds [4 x i64], [4 x i64]* [[I0]], i64 [[IDX:%.*]]
+; CHECK-NEXT:    [[I3:%.*]] = ptrtoint [4 x i64]* [[I1]] to i64
+; CHECK-NEXT:    [[I4:%.*]] = ptrtoint i64* [[P]] to i64
+; CHECK-NEXT:    [[I5:%.*]] = sub nuw i64 [[I3]], [[I4]]
+; CHECK-NEXT:    [[I6:%.*]] = lshr i64 [[I5]], 5
+; CHECK-NEXT:    ret i64 [[I6]]
+;
+  %i0 = bitcast i64* %p to [4 x i64]*
+  %i1 = getelementptr inbounds [4 x i64], [4 x i64]* %i0, i64 %idx
+  %i3 = ptrtoint [4 x i64]* %i1 to i64
+  %i4 = ptrtoint i64* %p to i64
+  %i5 = sub nuw i64 %i3, %i4
+  %i6 = lshr i64 %i5, 5
+  ret i64 %i6
+}


        


More information about the llvm-commits mailing list