[InstCombine] Add test for GEP difference with bitcasts (NFC)
authorNikita Popov <npopov@redhat.com>
Tue, 24 May 2022 14:09:26 +0000 (16:09 +0200)
committerNikita Popov <npopov@redhat.com>
Tue, 24 May 2022 14:12:01 +0000 (16:12 +0200)
llvm/test/Transforms/InstCombine/sub-gep.ll

index 4450459..b198e14 100644 (file)
@@ -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
+}