@@ -852,56 +852,109 @@ define i1 @gep_mugtiple_ugt_inbounds_nusw(ptr %base, i64 %idx, i64 %idx2) {
852852
853853define 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
892935define 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
911964define 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
0 commit comments