Skip to content

Commit b8ca1c6

Browse files
committed
Adjust tests for new behavior
1 parent f2da011 commit b8ca1c6

File tree

2 files changed

+107
-35
lines changed

2 files changed

+107
-35
lines changed

llvm/test/Transforms/InstCombine/icmp-gep.ll

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -852,56 +852,109 @@ define i1 @gep_mugtiple_ugt_inbounds_nusw(ptr %base, i64 %idx, i64 %idx2) {
852852

853853
define i1 @gep_multiple_multi_use_below_limit(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3) {
854854
; CHECK-LABEL: @gep_multiple_multi_use_below_limit(
855-
; CHECK-NEXT: [[GEP1_IDX1:%.*]] = add i64 [[IDX1:%.*]], [[IDX2:%.*]]
856-
; CHECK-NEXT: [[IDX3:%.*]] = add i64 [[GEP1_IDX1]], [[IDX4:%.*]]
857-
; CHECK-NEXT: [[GEP3_IDX:%.*]] = shl i64 [[IDX3]], 2
855+
; CHECK-NEXT: [[GEP3_IDX:%.*]] = shl i64 [[IDX3:%.*]], 2
858856
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2:%.*]], i64 [[GEP3_IDX]]
859857
; CHECK-NEXT: call void @use(ptr [[GEP3]])
860-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[GEP3_IDX]], 0
858+
; CHECK-NEXT: [[GEP2_IDX:%.*]] = shl i64 [[IDX2:%.*]], 2
859+
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[GEP3]], i64 [[GEP2_IDX]]
860+
; CHECK-NEXT: call void @use(ptr [[GEP4]])
861+
; CHECK-NEXT: [[GEP3_IDX1:%.*]] = shl i64 [[IDX4:%.*]], 2
862+
; CHECK-NEXT: [[GEP5:%.*]] = getelementptr i8, ptr [[GEP4]], i64 [[GEP3_IDX1]]
863+
; CHECK-NEXT: call void @use(ptr [[GEP5]])
864+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GEP3_IDX]], [[GEP2_IDX]]
865+
; CHECK-NEXT: [[TMP2:%.*]] = sub i64 0, [[GEP3_IDX1]]
866+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP1]], [[TMP2]]
861867
; CHECK-NEXT: ret i1 [[CMP]]
862868
;
863869
%gep1 = getelementptr i32, ptr %base, i64 %idx1
870+
call void @use(ptr %gep1)
864871
%gep2 = getelementptr i32, ptr %gep1, i64 %idx2
872+
call void @use(ptr %gep2)
865873
%gep3 = getelementptr i32, ptr %gep2, i64 %idx3
866874
call void @use(ptr %gep3)
867875
%cmp = icmp eq ptr %gep3, %base
868876
ret i1 %cmp
869877
}
870878

871-
define i1 @gep_multiple_multi_use_below_limit_extra_one_use_gep(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3, i64 %idx4) {
872-
; CHECK-LABEL: @gep_multiple_multi_use_below_limit_extra_one_use_gep(
873-
; CHECK-NEXT: [[GEP1_IDX1:%.*]] = add i64 [[IDX1:%.*]], [[IDX2:%.*]]
874-
; CHECK-NEXT: [[IDX3:%.*]] = add i64 [[GEP1_IDX1]], [[IDX5:%.*]]
875-
; CHECK-NEXT: [[GEP3_IDX:%.*]] = shl i64 [[IDX3]], 2
876-
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2:%.*]], i64 [[GEP3_IDX]]
879+
define i1 @gep_multiple_multi_use_below_limit_extra_one_use_gep1(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3, i64 %idx4) {
880+
; CHECK-LABEL: @gep_multiple_multi_use_below_limit_extra_one_use_gep1(
881+
; CHECK-NEXT: [[GEP1_IDX:%.*]] = shl i64 [[IDX1:%.*]], 2
882+
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[GEP1_IDX]]
883+
; CHECK-NEXT: call void @use(ptr [[GEP1]])
884+
; CHECK-NEXT: [[GEP2_IDX:%.*]] = shl i64 [[IDX2:%.*]], 2
885+
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[GEP1]], i64 [[GEP2_IDX]]
886+
; CHECK-NEXT: call void @use(ptr [[GEP2]])
887+
; CHECK-NEXT: [[GEP3_IDX:%.*]] = shl i64 [[IDX3:%.*]], 2
888+
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 [[GEP3_IDX]]
877889
; CHECK-NEXT: call void @use(ptr [[GEP3]])
878-
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[IDX3]], [[IDX4:%.*]]
879-
; CHECK-NEXT: [[DOTMASK:%.*]] = and i64 [[TMP3]], 4611686018427387903
880-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[DOTMASK]], 0
890+
; CHECK-NEXT: [[GEP4_IDX_NEG:%.*]] = mul i64 [[IDX4:%.*]], -4
891+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GEP1_IDX]], [[GEP2_IDX]]
892+
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], [[GEP3_IDX]]
893+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP2]], [[GEP4_IDX_NEG]]
881894
; CHECK-NEXT: ret i1 [[CMP]]
882895
;
883896
%gep1 = getelementptr i32, ptr %base, i64 %idx1
897+
call void @use(ptr %gep1)
884898
%gep2 = getelementptr i32, ptr %gep1, i64 %idx2
899+
call void @use(ptr %gep2)
885900
%gep3 = getelementptr i32, ptr %gep2, i64 %idx3
901+
call void @use(ptr %gep3)
886902
%gep4 = getelementptr i32, ptr %gep3, i64 %idx4
903+
%cmp = icmp eq ptr %gep4, %base
904+
ret i1 %cmp
905+
}
906+
907+
define i1 @gep_multiple_multi_use_below_limit_extra_one_use_gep2(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3, i64 %idx4) {
908+
; CHECK-LABEL: @gep_multiple_multi_use_below_limit_extra_one_use_gep2(
909+
; CHECK-NEXT: [[GEP1_IDX1:%.*]] = add i64 [[IDX1:%.*]], [[IDX2:%.*]]
910+
; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[GEP1_IDX1]], 2
911+
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[TMP1]]
912+
; CHECK-NEXT: call void @use(ptr [[GEP2]])
913+
; CHECK-NEXT: [[GEP3_IDX:%.*]] = shl i64 [[IDX3:%.*]], 2
914+
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP2]], i64 [[GEP3_IDX]]
915+
; CHECK-NEXT: call void @use(ptr [[GEP3]])
916+
; CHECK-NEXT: [[GEP4_IDX:%.*]] = shl i64 [[IDX4:%.*]], 2
917+
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[GEP3]], i64 [[GEP4_IDX]]
918+
; CHECK-NEXT: call void @use(ptr [[GEP4]])
919+
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], [[GEP3_IDX]]
920+
; CHECK-NEXT: [[GEP4_IDX_NEG:%.*]] = sub i64 0, [[GEP4_IDX]]
921+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP2]], [[GEP4_IDX_NEG]]
922+
; CHECK-NEXT: ret i1 [[CMP]]
923+
;
924+
%gep1 = getelementptr i32, ptr %base, i64 %idx1
925+
%gep2 = getelementptr i32, ptr %gep1, i64 %idx2
926+
call void @use(ptr %gep2)
927+
%gep3 = getelementptr i32, ptr %gep2, i64 %idx3
887928
call void @use(ptr %gep3)
929+
%gep4 = getelementptr i32, ptr %gep3, i64 %idx4
930+
call void @use(ptr %gep4)
888931
%cmp = icmp eq ptr %gep4, %base
889932
ret i1 %cmp
890933
}
891934

892935
define i1 @gep_multiple_multi_use_below_limit_consts(ptr %base, i64 %idx1, i64 %idx2) {
893936
; CHECK-LABEL: @gep_multiple_multi_use_below_limit_consts(
894-
; CHECK-NEXT: [[IDX2:%.*]] = add i64 [[IDX1:%.*]], [[IDX3:%.*]]
895-
; CHECK-NEXT: [[GEP4_IDX:%.*]] = shl i64 [[IDX2]], 2
896-
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[GEP4_IDX]], 32
897-
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[TMP3]]
937+
; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 16
938+
; CHECK-NEXT: call void @use(ptr [[GEP1]])
939+
; CHECK-NEXT: [[GEP4_IDX:%.*]] = shl i64 [[IDX2:%.*]], 2
940+
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[GEP1]], i64 [[GEP4_IDX]]
898941
; CHECK-NEXT: call void @use(ptr [[GEP4]])
899-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP3]], 0
942+
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i8, ptr [[GEP4]], i64 16
943+
; CHECK-NEXT: call void @use(ptr [[GEP3]])
944+
; CHECK-NEXT: [[GEP4_IDX1:%.*]] = shl i64 [[IDX3:%.*]], 2
945+
; CHECK-NEXT: [[GEP5:%.*]] = getelementptr i8, ptr [[GEP3]], i64 [[GEP4_IDX1]]
946+
; CHECK-NEXT: call void @use(ptr [[GEP5]])
947+
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GEP4_IDX]], 32
948+
; CHECK-NEXT: [[TMP2:%.*]] = sub i64 0, [[GEP4_IDX1]]
949+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP1]], [[TMP2]]
900950
; CHECK-NEXT: ret i1 [[CMP]]
901951
;
902952
%gep1 = getelementptr i32, ptr %base, i64 4
953+
call void @use(ptr %gep1)
903954
%gep2 = getelementptr i32, ptr %gep1, i64 %idx1
955+
call void @use(ptr %gep2)
904956
%gep3 = getelementptr i32, ptr %gep2, i64 4
957+
call void @use(ptr %gep3)
905958
%gep4 = getelementptr i32, ptr %gep3, i64 %idx2
906959
call void @use(ptr %gep4)
907960
%cmp = icmp eq ptr %gep4, %base
@@ -910,18 +963,23 @@ define i1 @gep_multiple_multi_use_below_limit_consts(ptr %base, i64 %idx1, i64 %
910963

911964
define i1 @gep_multiple_multi_use_above_limit(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3, i64 %idx4) {
912965
; CHECK-LABEL: @gep_multiple_multi_use_above_limit(
913-
; CHECK-NEXT: [[GEP1_IDX1:%.*]] = add i64 [[IDX1:%.*]], [[IDX2:%.*]]
914-
; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[GEP1_IDX1]], [[IDX3:%.*]]
915-
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], [[IDX4:%.*]]
916-
; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 2
917-
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 [[TMP3]]
966+
; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i32, ptr [[BASE:%.*]], i64 [[IDX1:%.*]]
918967
; CHECK-NEXT: call void @use(ptr [[GEP4]])
919-
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[TMP3]], 0
968+
; CHECK-NEXT: [[GEP3:%.*]] = getelementptr i32, ptr [[GEP4]], i64 [[IDX2:%.*]]
969+
; CHECK-NEXT: call void @use(ptr [[GEP3]])
970+
; CHECK-NEXT: [[GEP5:%.*]] = getelementptr i32, ptr [[GEP3]], i64 [[IDX3:%.*]]
971+
; CHECK-NEXT: call void @use(ptr [[GEP5]])
972+
; CHECK-NEXT: [[GEP6:%.*]] = getelementptr i32, ptr [[GEP5]], i64 [[IDX4:%.*]]
973+
; CHECK-NEXT: call void @use(ptr [[GEP6]])
974+
; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP6]], [[BASE]]
920975
; CHECK-NEXT: ret i1 [[CMP]]
921976
;
922977
%gep1 = getelementptr i32, ptr %base, i64 %idx1
978+
call void @use(ptr %gep1)
923979
%gep2 = getelementptr i32, ptr %gep1, i64 %idx2
980+
call void @use(ptr %gep2)
924981
%gep3 = getelementptr i32, ptr %gep2, i64 %idx3
982+
call void @use(ptr %gep3)
925983
%gep4 = getelementptr i32, ptr %gep3, i64 %idx4
926984
call void @use(ptr %gep4)
927985
%cmp = icmp eq ptr %gep4, %base

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

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,19 +1175,25 @@ define i64 @nuw_ptrdiff_mul_nsw_nneg_scale_multiuse(ptr %base, i64 %idx) {
11751175

11761176
define i64 @multiple_geps_multi_use_below_limit(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3, i64 %idx4) {
11771177
; CHECK-LABEL: @multiple_geps_multi_use_below_limit(
1178-
; CHECK-NEXT: [[IDX2:%.*]] = add nuw nsw i64 [[IDX1:%.*]], [[IDX5:%.*]]
1179-
; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds nuw i8, ptr [[P1:%.*]], i64 [[IDX2]]
1178+
; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds nuw i8, ptr [[P1:%.*]], i64 [[IDX2:%.*]]
11801179
; CHECK-NEXT: call void @use(ptr [[P2]])
1181-
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[IDX3:%.*]], [[IDX4:%.*]]
1182-
; CHECK-NEXT: [[P4:%.*]] = getelementptr inbounds nuw i8, ptr [[P1]], i64 [[TMP2]]
1180+
; CHECK-NEXT: [[P4:%.*]] = getelementptr inbounds nuw i8, ptr [[P2]], i64 [[IDX5:%.*]]
11831181
; CHECK-NEXT: call void @use(ptr [[P4]])
1184-
; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[IDX2]], [[TMP2]]
1182+
; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds nuw i8, ptr [[P1]], i64 [[IDX3:%.*]]
1183+
; CHECK-NEXT: call void @use(ptr [[P3]])
1184+
; CHECK-NEXT: [[P5:%.*]] = getelementptr inbounds nuw i8, ptr [[P3]], i64 [[IDX4:%.*]]
1185+
; CHECK-NEXT: call void @use(ptr [[P5]])
1186+
; CHECK-NEXT: [[TMP1:%.*]] = add nuw nsw i64 [[IDX2]], [[IDX5]]
1187+
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[IDX3]], [[IDX4]]
1188+
; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[TMP1]], [[TMP2]]
11851189
; CHECK-NEXT: ret i64 [[GEPDIFF]]
11861190
;
11871191
%p1 = getelementptr inbounds nuw i8, ptr %base, i64 %idx1
1192+
call void @use(ptr %p1)
11881193
%p2 = getelementptr inbounds nuw i8, ptr %p1, i64 %idx2
11891194
call void @use(ptr %p2)
11901195
%p3 = getelementptr inbounds nuw i8, ptr %base, i64 %idx3
1196+
call void @use(ptr %p3)
11911197
%p4 = getelementptr inbounds nuw i8, ptr %p3, i64 %idx4
11921198
call void @use(ptr %p4)
11931199
%i1 = ptrtoint ptr %p4 to i64
@@ -1198,21 +1204,29 @@ define i64 @multiple_geps_multi_use_below_limit(ptr %base, i64 %idx1, i64 %idx2,
11981204

11991205
define i64 @multiple_geps_multi_use_above_limit(ptr %base, i64 %idx1, i64 %idx2, i64 %idx3, i64 %idx4, i64 %idx5) {
12001206
; CHECK-LABEL: @multiple_geps_multi_use_above_limit(
1201-
; CHECK-NEXT: [[IDX2:%.*]] = add nuw nsw i64 [[IDX1:%.*]], [[IDX6:%.*]]
1202-
; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds nuw i8, ptr [[P1:%.*]], i64 [[IDX2]]
1207+
; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds nuw i8, ptr [[P1:%.*]], i64 [[IDX2:%.*]]
12031208
; CHECK-NEXT: call void @use(ptr [[P2]])
1204-
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[IDX3:%.*]], [[IDX4:%.*]]
1205-
; CHECK-NEXT: [[TMP3:%.*]] = add nuw nsw i64 [[TMP2]], [[IDX5:%.*]]
1206-
; CHECK-NEXT: [[P5:%.*]] = getelementptr inbounds nuw i8, ptr [[P1]], i64 [[TMP3]]
1209+
; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds nuw i8, ptr [[P2]], i64 [[IDX6:%.*]]
1210+
; CHECK-NEXT: call void @use(ptr [[P3]])
1211+
; CHECK-NEXT: [[P5:%.*]] = getelementptr inbounds nuw i8, ptr [[P1]], i64 [[TMP3:%.*]]
12071212
; CHECK-NEXT: call void @use(ptr [[P5]])
1208-
; CHECK-NEXT: [[D:%.*]] = sub nsw i64 [[IDX2]], [[TMP3]]
1213+
; CHECK-NEXT: [[P6:%.*]] = getelementptr inbounds nuw i8, ptr [[P5]], i64 [[IDX7:%.*]]
1214+
; CHECK-NEXT: call void @use(ptr [[P6]])
1215+
; CHECK-NEXT: [[P7:%.*]] = getelementptr inbounds nuw i8, ptr [[P6]], i64 [[IDX5:%.*]]
1216+
; CHECK-NEXT: call void @use(ptr [[P7]])
1217+
; CHECK-NEXT: [[I1:%.*]] = ptrtoint ptr [[P7]] to i64
1218+
; CHECK-NEXT: [[I2:%.*]] = ptrtoint ptr [[P3]] to i64
1219+
; CHECK-NEXT: [[D:%.*]] = sub i64 [[I2]], [[I1]]
12091220
; CHECK-NEXT: ret i64 [[D]]
12101221
;
12111222
%p1 = getelementptr inbounds nuw i8, ptr %base, i64 %idx1
1223+
call void @use(ptr %p1)
12121224
%p2 = getelementptr inbounds nuw i8, ptr %p1, i64 %idx2
12131225
call void @use(ptr %p2)
12141226
%p3 = getelementptr inbounds nuw i8, ptr %base, i64 %idx3
1227+
call void @use(ptr %p3)
12151228
%p4 = getelementptr inbounds nuw i8, ptr %p3, i64 %idx4
1229+
call void @use(ptr %p4)
12161230
%p5 = getelementptr inbounds nuw i8, ptr %p4, i64 %idx5
12171231
call void @use(ptr %p5)
12181232
%i1 = ptrtoint ptr %p5 to i64

0 commit comments

Comments
 (0)