Skip to content

Commit c93e3b7

Browse files
committed
[InstCombine] Add pre-commit tests. NFC.
1 parent 0ba5958 commit c93e3b7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

llvm/test/Transforms/InstCombine/sub-gep.ll

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,3 +1089,55 @@ define <2 x i64> @splat_geps_multiple(ptr %base, i64 %idx0, <2 x i64> %idx1, <2
10891089
%d = sub <2 x i64> %gep2.int, %gep1.int
10901090
ret <2 x i64> %d
10911091
}
1092+
1093+
define i64 @nuw_ptrdiff_shl_nsw(ptr %base, i64 %idx) {
1094+
; CHECK-LABEL: @nuw_ptrdiff_shl_nsw(
1095+
; CHECK-NEXT: [[OFFSET:%.*]] = shl nsw i64 [[IDX:%.*]], 3
1096+
; CHECK-NEXT: ret i64 [[OFFSET]]
1097+
;
1098+
%offset = shl nsw i64 %idx, 3
1099+
%gep = getelementptr inbounds i8, ptr %base, i64 %offset
1100+
%lhs = ptrtoint ptr %gep to i64
1101+
%rhs = ptrtoint ptr %base to i64
1102+
%diff = sub nuw i64 %lhs, %rhs
1103+
ret i64 %diff
1104+
}
1105+
1106+
define i64 @nuw_ptrdiff_shl_nonsw(ptr %base, i64 %idx) {
1107+
; CHECK-LABEL: @nuw_ptrdiff_shl_nonsw(
1108+
; CHECK-NEXT: [[OFFSET:%.*]] = shl i64 [[IDX:%.*]], 3
1109+
; CHECK-NEXT: ret i64 [[OFFSET]]
1110+
;
1111+
%offset = shl i64 %idx, 3
1112+
%gep = getelementptr inbounds i8, ptr %base, i64 %offset
1113+
%lhs = ptrtoint ptr %gep to i64
1114+
%rhs = ptrtoint ptr %base to i64
1115+
%diff = sub nuw i64 %lhs, %rhs
1116+
ret i64 %diff
1117+
}
1118+
1119+
define i64 @nuw_ptrdiff_mul_nsw_nneg_scale(ptr %base, i64 %idx) {
1120+
; CHECK-LABEL: @nuw_ptrdiff_mul_nsw_nneg_scale(
1121+
; CHECK-NEXT: [[OFFSET:%.*]] = mul nuw nsw i64 [[IDX:%.*]], 3
1122+
; CHECK-NEXT: ret i64 [[OFFSET]]
1123+
;
1124+
%offset = mul nsw i64 %idx, 3
1125+
%gep = getelementptr inbounds i8, ptr %base, i64 %offset
1126+
%lhs = ptrtoint ptr %gep to i64
1127+
%rhs = ptrtoint ptr %base to i64
1128+
%diff = sub nuw i64 %lhs, %rhs
1129+
ret i64 %diff
1130+
}
1131+
1132+
define i64 @nuw_ptrdiff_mul_nsw_unknown_scale(ptr %base, i64 %idx, i64 %scale) {
1133+
; CHECK-LABEL: @nuw_ptrdiff_mul_nsw_unknown_scale(
1134+
; CHECK-NEXT: [[OFFSET:%.*]] = mul nuw nsw i64 [[IDX:%.*]], [[SCALE:%.*]]
1135+
; CHECK-NEXT: ret i64 [[OFFSET]]
1136+
;
1137+
%offset = mul nsw i64 %idx, %scale
1138+
%gep = getelementptr inbounds i8, ptr %base, i64 %offset
1139+
%lhs = ptrtoint ptr %gep to i64
1140+
%rhs = ptrtoint ptr %base to i64
1141+
%diff = sub nuw i64 %lhs, %rhs
1142+
ret i64 %diff
1143+
}

0 commit comments

Comments
 (0)