From 87087a02ae49a907e0ec9e6dfe62c9b9ca232936 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 23 Dec 2020 21:22:36 +0100 Subject: [PATCH] [InstCombine] Add tests for gep of null (NFC) We were only considering the gep of null pattern in conjunction with a load/store. Also test it independently. --- llvm/test/Transforms/InstCombine/getelementptr.ll | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/getelementptr.ll b/llvm/test/Transforms/InstCombine/getelementptr.ll index 85ef011..b4124c5 100644 --- a/llvm/test/Transforms/InstCombine/getelementptr.ll +++ b/llvm/test/Transforms/InstCombine/getelementptr.ll @@ -1237,4 +1237,31 @@ define i32* @PR45084_extra_use(i1 %cond, %struct.f** %p) { ret i32* %gep } +define i8* @gep_null_inbounds(i64 %idx) { +; CHECK-LABEL: @gep_null_inbounds( +; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* null, i64 [[IDX:%.*]] +; CHECK-NEXT: ret i8* [[GEP]] +; + %gep = getelementptr inbounds i8, i8* null, i64 %idx + ret i8* %gep +} + +define i8* @gep_null_not_inbounds(i64 %idx) { +; CHECK-LABEL: @gep_null_not_inbounds( +; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, i8* null, i64 [[IDX:%.*]] +; CHECK-NEXT: ret i8* [[GEP]] +; + %gep = getelementptr i8, i8* null, i64 %idx + ret i8* %gep +} + +define i8* @gep_null_defined(i64 %idx) null_pointer_is_valid { +; CHECK-LABEL: @gep_null_defined( +; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i8, i8* null, i64 [[IDX:%.*]] +; CHECK-NEXT: ret i8* [[GEP]] +; + %gep = getelementptr inbounds i8, i8* null, i64 %idx + ret i8* %gep +} + !0 = !{!"branch_weights", i32 2, i32 10} -- 2.7.4