Skip to content

Commit 989938f

Browse files
committed
[InstCombine] Add pre-commit tests. NFC.
1 parent 029e102 commit 989938f

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,6 +2910,11 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
29102910
SQ.getWithInstruction(&GEP)))
29112911
return replaceInstUsesWith(GEP, V);
29122912

2913+
// // getelementptr inbounds null, idx -> null
2914+
// if (auto *BaseC = dyn_cast<Constant>(PtrOp))
2915+
// if (GEP.isInBounds() && BaseC->isNullValue() && !NullPointerIsDefined(GEP.getFunction(), GEPType->getPointerAddressSpace()))
2916+
// return replaceInstUsesWith(GEP, PtrOp);
2917+
29132918
// For vector geps, use the generic demanded vector support.
29142919
// Skip if GEP return type is scalable. The number of elements is unknown at
29152920
// compile-time.

llvm/test/Transforms/InstCombine/getelementptr.ll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,5 +2019,40 @@ define ptr @gep_merge_nusw_const(ptr %p, i64 %idx, i64 %idx2) {
20192019
ret ptr %gep
20202020
}
20212021

2022+
define <2 x ptr> @gep_inbounds_null_vec(i64 %idx) {
2023+
; CHECK-LABEL: @gep_inbounds_null_vec(
2024+
; CHECK-NEXT: [[P:%.*]] = getelementptr inbounds i8, <2 x ptr> zeroinitializer, i64 [[IDX:%.*]]
2025+
; CHECK-NEXT: ret <2 x ptr> [[P]]
2026+
;
2027+
%p = getelementptr inbounds i8, <2 x ptr> zeroinitializer, i64 %idx
2028+
ret <2 x ptr> %p
2029+
}
2030+
2031+
define <2 x ptr> @gep_inbounds_null_vec_broadcast(<2 x i64> %idx) {
2032+
; CHECK-LABEL: @gep_inbounds_null_vec_broadcast(
2033+
; CHECK-NEXT: [[P:%.*]] = getelementptr inbounds i8, ptr null, <2 x i64> [[IDX:%.*]]
2034+
; CHECK-NEXT: ret <2 x ptr> [[P]]
2035+
;
2036+
%p = getelementptr inbounds i8, ptr null, <2 x i64> %idx
2037+
ret <2 x ptr> %p
2038+
}
2039+
2040+
define ptr @gep_noinbounds_null(i64 %idx) {
2041+
; CHECK-LABEL: @gep_noinbounds_null(
2042+
; CHECK-NEXT: [[P:%.*]] = getelementptr i8, ptr null, i64 [[IDX:%.*]]
2043+
; CHECK-NEXT: ret ptr [[P]]
2044+
;
2045+
%p = getelementptr i8, ptr null, i64 %idx
2046+
ret ptr %p
2047+
}
2048+
2049+
define ptr @gep_inbounds_null_null_is_valid(i64 %idx) null_pointer_is_valid {
2050+
; CHECK-LABEL: @gep_inbounds_null_null_is_valid(
2051+
; CHECK-NEXT: [[P:%.*]] = getelementptr inbounds i8, ptr null, i64 [[IDX:%.*]]
2052+
; CHECK-NEXT: ret ptr [[P]]
2053+
;
2054+
%p = getelementptr inbounds i8, ptr null, i64 %idx
2055+
ret ptr %p
2056+
}
20222057

20232058
!0 = !{!"branch_weights", i32 2, i32 10}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ define i64 @nullptrtoint_scalable_c() {
741741
; CHECK-NEXT: ret i64 [[PTR_IDX]]
742742
;
743743
entry:
744-
%ptr = getelementptr inbounds <vscale x 4 x i32>, ptr null, i64 8
744+
%ptr = getelementptr nusw <vscale x 4 x i32>, ptr null, i64 8
745745
%ret = ptrtoint ptr %ptr to i64
746746
ret i64 %ret
747747
}
@@ -755,7 +755,7 @@ define i64 @nullptrtoint_scalable_x(i64 %x) {
755755
; CHECK-NEXT: ret i64 [[PTR_IDX]]
756756
;
757757
entry:
758-
%ptr = getelementptr inbounds <vscale x 4 x i32>, ptr null, i64 %x
758+
%ptr = getelementptr nusw <vscale x 4 x i32>, ptr null, i64 %x
759759
%ret = ptrtoint ptr %ptr to i64
760760
ret i64 %ret
761761
}

0 commit comments

Comments
 (0)