@@ -945,19 +945,15 @@ define i64 @multiple_geps_two_chains_gep_base(ptr %base, i64 %base.idx, i64 %idx
945
945
946
946
define i64 @multiple_geps_two_chains_multi_use (ptr %base , i64 %idx1 , i64 %idx2 , i64 %idx3 , i64 %idx4 ) {
947
947
; CHECK-LABEL: @multiple_geps_two_chains_multi_use(
948
- ; CHECK-NEXT: [[P2_IDX:%.*]] = shl nsw i64 [[IDX2:%.*]], 2
949
- ; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i8, ptr [[P1:%.*]], i64 [[P2_IDX]]
950
- ; CHECK-NEXT: [[P4_IDX:%.*]] = shl nsw i64 [[IDX4:%.*]], 2
951
- ; CHECK-NEXT: [[P5:%.*]] = getelementptr inbounds i8, ptr [[P2]], i64 [[P4_IDX]]
952
- ; CHECK-NEXT: [[P3_IDX:%.*]] = shl nsw i64 [[IDX3:%.*]], 2
953
- ; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds i8, ptr [[P1]], i64 [[P3_IDX]]
954
- ; CHECK-NEXT: [[P4_IDX1:%.*]] = shl nsw i64 [[IDX5:%.*]], 2
955
- ; CHECK-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr [[P3]], i64 [[P4_IDX1]]
948
+ ; CHECK-NEXT: [[P1_IDX1:%.*]] = add i64 [[IDX1:%.*]], [[IDX2:%.*]]
949
+ ; CHECK-NEXT: [[P4_IDX:%.*]] = shl i64 [[P1_IDX1]], 2
950
+ ; CHECK-NEXT: [[P5:%.*]] = getelementptr inbounds i8, ptr [[P2:%.*]], i64 [[P4_IDX]]
951
+ ; CHECK-NEXT: [[P3_IDX2:%.*]] = add i64 [[IDX3:%.*]], [[IDX4:%.*]]
952
+ ; CHECK-NEXT: [[P4_IDX1:%.*]] = shl i64 [[P3_IDX2]], 2
953
+ ; CHECK-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr [[P2]], i64 [[P4_IDX1]]
956
954
; CHECK-NEXT: call void @use(ptr [[P5]])
957
955
; CHECK-NEXT: call void @use(ptr [[P4]])
958
- ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[P2_IDX]], [[P4_IDX]]
959
- ; CHECK-NEXT: [[TMP2:%.*]] = add nsw i64 [[P3_IDX]], [[P4_IDX1]]
960
- ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[TMP1]], [[TMP2]]
956
+ ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[P4_IDX]], [[P4_IDX1]]
961
957
; CHECK-NEXT: ret i64 [[GEPDIFF]]
962
958
;
963
959
%p1 = getelementptr inbounds i32 , ptr %base , i64 %idx1
@@ -974,23 +970,18 @@ define i64 @multiple_geps_two_chains_multi_use(ptr %base, i64 %idx1, i64 %idx2,
974
970
975
971
define i64 @multiple_geps_two_chains_partial_multi_use (ptr %base , i64 %idx1 , i64 %idx2 , i64 %idx3 , i64 %idx4 , i64 %idx5 , i64 %idx6 ) {
976
972
; CHECK-LABEL: @multiple_geps_two_chains_partial_multi_use(
977
- ; CHECK-NEXT: [[P2_IDX:%.*]] = shl nsw i64 [[IDX2:%.*]], 2
978
- ; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i8, ptr [[P1:%.*]], i64 [[P2_IDX]]
979
- ; CHECK-NEXT: [[P4_IDX:%.*]] = shl nsw i64 [[IDX4:%.*]], 2
980
- ; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds i8, ptr [[P2]], i64 [[P4_IDX]]
981
- ; CHECK-NEXT: [[P3_IDX:%.*]] = shl nsw i64 [[IDX3:%.*]], 2
982
- ; CHECK-NEXT: [[P4_IDX1:%.*]] = shl nsw i64 [[IDX7:%.*]], 2
983
- ; CHECK-NEXT: [[P5:%.*]] = getelementptr inbounds i8, ptr [[P1]], i64 [[P4_IDX1]]
984
- ; CHECK-NEXT: [[P5_IDX:%.*]] = shl nsw i64 [[IDX5:%.*]], 2
985
- ; CHECK-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr [[P5]], i64 [[P5_IDX]]
986
- ; CHECK-NEXT: [[P6_IDX:%.*]] = shl nsw i64 [[IDX6:%.*]], 2
973
+ ; CHECK-NEXT: [[P1_IDX1:%.*]] = add i64 [[IDX1:%.*]], [[IDX2:%.*]]
974
+ ; CHECK-NEXT: [[P4_IDX:%.*]] = shl i64 [[P1_IDX1]], 2
975
+ ; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds i8, ptr [[P2:%.*]], i64 [[P4_IDX]]
976
+ ; CHECK-NEXT: [[P4_IDX2:%.*]] = add i64 [[IDX4:%.*]], [[IDX5:%.*]]
977
+ ; CHECK-NEXT: [[P5_IDX:%.*]] = shl i64 [[P4_IDX2]], 2
978
+ ; CHECK-NEXT: [[P4:%.*]] = getelementptr inbounds i8, ptr [[P2]], i64 [[P5_IDX]]
987
979
; CHECK-NEXT: call void @use(ptr [[P3]])
988
980
; CHECK-NEXT: call void @use(ptr [[P4]])
989
- ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i64 [[P2_IDX]], [[P4_IDX]]
990
- ; CHECK-NEXT: [[TMP2:%.*]] = add nsw i64 [[TMP1]], [[P3_IDX]]
991
- ; CHECK-NEXT: [[TMP3:%.*]] = add nsw i64 [[P4_IDX1]], [[P5_IDX]]
992
- ; CHECK-NEXT: [[TMP4:%.*]] = add nsw i64 [[TMP3]], [[P6_IDX]]
993
- ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[TMP2]], [[TMP4]]
981
+ ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[P1_IDX1]], [[IDX3:%.*]]
982
+ ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[P4_IDX2]], [[IDX6:%.*]]
983
+ ; CHECK-NEXT: [[TMP5:%.*]] = sub i64 [[TMP3]], [[TMP4]]
984
+ ; CHECK-NEXT: [[GEPDIFF:%.*]] = shl i64 [[TMP5]], 2
994
985
; CHECK-NEXT: ret i64 [[GEPDIFF]]
995
986
;
996
987
%p1 = getelementptr inbounds i32 , ptr %base , i64 %idx1
@@ -1007,6 +998,29 @@ define i64 @multiple_geps_two_chains_partial_multi_use(ptr %base, i64 %idx1, i64
1007
998
ret i64 %d
1008
999
}
1009
1000
1001
+ define i64 @multiple_geps_two_chains_partial_multi_use_insert_point (ptr %p , i64 %idx1 , i64 %idx2 , i64 %idx3 ) {
1002
+ ; CHECK-LABEL: @multiple_geps_two_chains_partial_multi_use_insert_point(
1003
+ ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 8
1004
+ ; CHECK-NEXT: call void @use(ptr [[GEP2]])
1005
+ ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[IDX2:%.*]], [[IDX3:%.*]]
1006
+ ; CHECK-NEXT: [[GEP4:%.*]] = getelementptr i8, ptr [[GEP2]], i64 [[TMP1]]
1007
+ ; CHECK-NEXT: call void @use(ptr [[GEP4]])
1008
+ ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP1]], 8
1009
+ ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub i64 [[IDX1:%.*]], [[TMP2]]
1010
+ ; CHECK-NEXT: ret i64 [[GEPDIFF]]
1011
+ ;
1012
+ %gep1 = getelementptr i8 , ptr %p , i64 %idx1
1013
+ %gep2 = getelementptr i8 , ptr %p , i64 8
1014
+ call void @use (ptr %gep2 )
1015
+ %gep3 = getelementptr i8 , ptr %gep2 , i64 %idx2
1016
+ %gep4 = getelementptr i8 , ptr %gep3 , i64 %idx3
1017
+ call void @use (ptr %gep4 )
1018
+ %gep1.int = ptrtoint ptr %gep1 to i64
1019
+ %gep4.int = ptrtoint ptr %gep4 to i64
1020
+ %sub = sub i64 %gep1.int , %gep4.int
1021
+ ret i64 %sub
1022
+ }
1023
+
1010
1024
define i64 @multiple_geps_inbounds (ptr %base , i64 %idx , i64 %idx2 ) {
1011
1025
; CHECK-LABEL: @multiple_geps_inbounds(
1012
1026
; CHECK-NEXT: [[D:%.*]] = add nsw i64 [[IDX:%.*]], [[IDX2:%.*]]
0 commit comments