[llvm] 87087a0 - [InstCombine] Add tests for gep of null (NFC)
    Nikita Popov via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Dec 23 12:42:06 PST 2020
    
    
  
Author: Nikita Popov
Date: 2020-12-23T21:41:53+01:00
New Revision: 87087a02ae49a907e0ec9e6dfe62c9b9ca232936
URL: https://github.com/llvm/llvm-project/commit/87087a02ae49a907e0ec9e6dfe62c9b9ca232936
DIFF: https://github.com/llvm/llvm-project/commit/87087a02ae49a907e0ec9e6dfe62c9b9ca232936.diff
LOG: [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.
Added: 
    
Modified: 
    llvm/test/Transforms/InstCombine/getelementptr.ll
Removed: 
    
################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/getelementptr.ll b/llvm/test/Transforms/InstCombine/getelementptr.ll
index 85ef011b3212..b4124c5edf5e 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}
        
    
    
More information about the llvm-commits
mailing list