@@ -389,9 +389,8 @@ define ptr @test15(i64 %X) {
389389 ret ptr %A
390390}
391391
392-
393- define ptr @test16 (ptr %X , i32 %Idx ) {
394- ; CHECK-LABEL: @test16(
392+ define ptr @test_index_canon (ptr %X , i32 %Idx ) {
393+ ; CHECK-LABEL: @test_index_canon(
395394; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[IDX:%.*]] to i64
396395; CHECK-NEXT: [[R:%.*]] = getelementptr i32, ptr [[X:%.*]], i64 [[TMP1]]
397396; CHECK-NEXT: ret ptr [[R]]
@@ -400,6 +399,39 @@ define ptr @test16(ptr %X, i32 %Idx) {
400399 ret ptr %R
401400}
402401
402+ define ptr @test_index_canon_inbounds (ptr %X , i32 %Idx ) {
403+ ; CHECK-LABEL: @test_index_canon_inbounds(
404+ ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[IDX:%.*]] to i64
405+ ; CHECK-NEXT: [[R:%.*]] = getelementptr inbounds i32, ptr [[X:%.*]], i64 [[TMP1]]
406+ ; CHECK-NEXT: ret ptr [[R]]
407+ ;
408+ %R = getelementptr inbounds i32 , ptr %X , i32 %Idx
409+ ret ptr %R
410+ }
411+
412+ define ptr @test_index_canon_nusw_nuw (ptr %X , i32 %Idx ) {
413+ ; CHECK-LABEL: @test_index_canon_nusw_nuw(
414+ ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[IDX:%.*]] to i64
415+ ; CHECK-NEXT: [[R:%.*]] = getelementptr nusw nuw i32, ptr [[X:%.*]], i64 [[TMP1]]
416+ ; CHECK-NEXT: ret ptr [[R]]
417+ ;
418+ %R = getelementptr nusw nuw i32 , ptr %X , i32 %Idx
419+ ret ptr %R
420+ }
421+
422+ define ptr @test_index_canon_const_expr_inbounds (ptr %X , i32 %Idx ) {
423+ ; CHECK-LABEL: @test_index_canon_const_expr_inbounds(
424+ ; CHECK-NEXT: ret ptr getelementptr inbounds (i8, ptr @Global, i64 123)
425+ ;
426+ ret ptr getelementptr inbounds (i8 , ptr @Global , i32 123 )
427+ }
428+
429+ define ptr @test_index_canon_const_expr_nuw_nusw (ptr %X , i32 %Idx ) {
430+ ; CHECK-LABEL: @test_index_canon_const_expr_nuw_nusw(
431+ ; CHECK-NEXT: ret ptr getelementptr (i8, ptr @Global, i64 123)
432+ ;
433+ ret ptr getelementptr nusw nuw (i8 , ptr @Global , i32 123 )
434+ }
403435
404436define i1 @test17 (ptr %P , i32 %I , i32 %J ) {
405437; CHECK-LABEL: @test17(
0 commit comments