@@ -1123,7 +1123,8 @@ define i64 @test58(ptr %foo, i64 %i, i64 %j) {
11231123
11241124define i64 @test59 (ptr %foo , i64 %i ) {
11251125; CHECK-LABEL: @test59(
1126- ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO:%.*]], i64 0, i64 42, i64 [[I:%.*]]
1126+ ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[FOO:%.*]], i64 [[I:%.*]]
1127+ ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[TMP1]], i64 4200
11271128; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[FOO]], i64 4200
11281129; CHECK-NEXT: store ptr [[GEP1]], ptr @dummy_global1, align 8
11291130; CHECK-NEXT: store ptr [[GEP2]], ptr @dummy_global2, align 8
@@ -1142,13 +1143,12 @@ define i64 @test59(ptr %foo, i64 %i) {
11421143
11431144define i64 @test60 (ptr %foo , i64 %i , i64 %j ) {
11441145; CHECK-LABEL: @test60(
1145- ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO:%.*]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]]
1146- ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[FOO]], i64 4200
1147- ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint ptr [[GEP1]] to i64
1148- ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint ptr [[GEP2]] to i64
1149- ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]]
1146+ ; CHECK-NEXT: [[GEP1_IDX:%.*]] = mul nsw i64 [[J:%.*]], 100
1147+ ; CHECK-NEXT: [[GEP1_OFFS:%.*]] = add nsw i64 [[GEP1_IDX]], [[I:%.*]]
1148+ ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[FOO:%.*]], i64 [[GEP1_OFFS]]
1149+ ; CHECK-NEXT: [[GEPDIFF:%.*]] = add nsw i64 [[GEP1_OFFS]], -4200
11501150; CHECK-NEXT: store ptr [[GEP1]], ptr @dummy_global1, align 8
1151- ; CHECK-NEXT: ret i64 [[SUB ]]
1151+ ; CHECK-NEXT: ret i64 [[GEPDIFF ]]
11521152;
11531153; gep1 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
11541154 %gep1 = getelementptr inbounds [100 x [100 x i8 ]], ptr %foo , i64 0 , i64 %j , i64 %i
@@ -1162,13 +1162,12 @@ define i64 @test60(ptr %foo, i64 %i, i64 %j) {
11621162
11631163define i64 @test61 (ptr %foo , i64 %i , i64 %j ) {
11641164; CHECK-LABEL: @test61(
1165- ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[FOO:%.*]], i64 4200
1166- ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds [100 x [100 x i8]], ptr [[FOO]], i64 0, i64 [[J:%.*]], i64 [[I:%.*]]
1167- ; CHECK-NEXT: [[CAST1:%.*]] = ptrtoint ptr [[GEP1]] to i64
1168- ; CHECK-NEXT: [[CAST2:%.*]] = ptrtoint ptr [[GEP2]] to i64
1169- ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[CAST1]], [[CAST2]]
1165+ ; CHECK-NEXT: [[GEP2_IDX:%.*]] = mul nsw i64 [[J:%.*]], 100
1166+ ; CHECK-NEXT: [[GEP2_OFFS:%.*]] = add nsw i64 [[GEP2_IDX]], [[I:%.*]]
1167+ ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[FOO:%.*]], i64 [[GEP2_OFFS]]
1168+ ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 4200, [[GEP2_OFFS]]
11701169; CHECK-NEXT: store ptr [[GEP2]], ptr @dummy_global2, align 8
1171- ; CHECK-NEXT: ret i64 [[SUB ]]
1170+ ; CHECK-NEXT: ret i64 [[GEPDIFF ]]
11721171;
11731172; gep2 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
11741173 %gep1 = getelementptr inbounds [100 x [100 x i8 ]], ptr %foo , i64 0 , i64 42 , i64 0
@@ -1186,11 +1185,8 @@ define i64 @test_sub_ptradd_multiuse(ptr %p, i64 %idx1, i64 %idx2) {
11861185; CHECK-LABEL: @test_sub_ptradd_multiuse(
11871186; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[IDX1:%.*]]
11881187; CHECK-NEXT: call void @use.ptr(ptr [[P1]])
1189- ; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[IDX2:%.*]]
1190- ; CHECK-NEXT: [[P1_INT:%.*]] = ptrtoint ptr [[P1]] to i64
1191- ; CHECK-NEXT: [[P2_INT:%.*]] = ptrtoint ptr [[P2]] to i64
1192- ; CHECK-NEXT: [[SUB:%.*]] = sub i64 [[P1_INT]], [[P2_INT]]
1193- ; CHECK-NEXT: ret i64 [[SUB]]
1188+ ; CHECK-NEXT: [[GEPDIFF:%.*]] = sub nsw i64 [[IDX1]], [[IDX2:%.*]]
1189+ ; CHECK-NEXT: ret i64 [[GEPDIFF]]
11941190;
11951191 %p1 = getelementptr inbounds i8 , ptr %p , i64 %idx1
11961192 call void @use.ptr (ptr %p1 )
0 commit comments