@@ -1123,7 +1123,8 @@ define i64 @test58(ptr %foo, i64 %i, i64 %j) {
1123
1123
1124
1124
define i64 @test59 (ptr %foo , i64 %i ) {
1125
1125
; 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
1127
1128
; CHECK-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[FOO]], i64 4200
1128
1129
; CHECK-NEXT: store ptr [[GEP1]], ptr @dummy_global1, align 8
1129
1130
; CHECK-NEXT: store ptr [[GEP2]], ptr @dummy_global2, align 8
@@ -1142,13 +1143,12 @@ define i64 @test59(ptr %foo, i64 %i) {
1142
1143
1143
1144
define i64 @test60 (ptr %foo , i64 %i , i64 %j ) {
1144
1145
; 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
1150
1150
; CHECK-NEXT: store ptr [[GEP1]], ptr @dummy_global1, align 8
1151
- ; CHECK-NEXT: ret i64 [[SUB ]]
1151
+ ; CHECK-NEXT: ret i64 [[GEPDIFF ]]
1152
1152
;
1153
1153
; gep1 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
1154
1154
%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) {
1162
1162
1163
1163
define i64 @test61 (ptr %foo , i64 %i , i64 %j ) {
1164
1164
; 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]]
1170
1169
; CHECK-NEXT: store ptr [[GEP2]], ptr @dummy_global2, align 8
1171
- ; CHECK-NEXT: ret i64 [[SUB ]]
1170
+ ; CHECK-NEXT: ret i64 [[GEPDIFF ]]
1172
1171
;
1173
1172
; gep2 has a non-constant index and more than one uses. Shouldn't duplicate the arithmetic.
1174
1173
%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) {
1186
1185
; CHECK-LABEL: @test_sub_ptradd_multiuse(
1187
1186
; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 [[IDX1:%.*]]
1188
1187
; 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]]
1194
1190
;
1195
1191
%p1 = getelementptr inbounds i8 , ptr %p , i64 %idx1
1196
1192
call void @use.ptr (ptr %p1 )
0 commit comments